mirror of
https://github.com/dart-lang/sdk
synced 2024-10-15 00:49:52 +00:00
ec599a5977
This covers Linux, Mac, Android, and Fuchsia. Bug: https://github.com/dart-lang/sdk/issues/35954 Fixes: https://github.com/dart-lang/sdk/issues/35954 Change-Id: I8142332c530be8ad3ce46312a4a5ac750953c288 Reviewed-on: https://dart-review.googlesource.com/c/93320 Commit-Queue: Liam Appelbe <liama@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
100 lines
2.7 KiB
C++
100 lines
2.7 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef RUNTIME_BIN_EVENTHANDLER_LINUX_H_
|
|
#define RUNTIME_BIN_EVENTHANDLER_LINUX_H_
|
|
|
|
#if !defined(RUNTIME_BIN_EVENTHANDLER_H_)
|
|
#error Do not include eventhandler_linux.h directly; use eventhandler.h instead.
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
#include <sys/epoll.h>
|
|
#include <sys/socket.h>
|
|
#include <unistd.h>
|
|
|
|
#include "platform/hashmap.h"
|
|
#include "platform/signal_blocker.h"
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
class DescriptorInfo : public DescriptorInfoBase {
|
|
public:
|
|
explicit DescriptorInfo(intptr_t fd) : DescriptorInfoBase(fd) {}
|
|
|
|
virtual ~DescriptorInfo() {}
|
|
|
|
intptr_t GetPollEvents();
|
|
|
|
virtual void Close() {
|
|
close(fd_);
|
|
fd_ = -1;
|
|
}
|
|
|
|
private:
|
|
DISALLOW_COPY_AND_ASSIGN(DescriptorInfo);
|
|
};
|
|
|
|
class DescriptorInfoSingle : public DescriptorInfoSingleMixin<DescriptorInfo> {
|
|
public:
|
|
explicit DescriptorInfoSingle(intptr_t fd)
|
|
: DescriptorInfoSingleMixin(fd, false) {}
|
|
virtual ~DescriptorInfoSingle() {}
|
|
|
|
private:
|
|
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle);
|
|
};
|
|
|
|
class DescriptorInfoMultiple
|
|
: public DescriptorInfoMultipleMixin<DescriptorInfo> {
|
|
public:
|
|
explicit DescriptorInfoMultiple(intptr_t fd)
|
|
: DescriptorInfoMultipleMixin(fd, false) {}
|
|
virtual ~DescriptorInfoMultiple() {}
|
|
|
|
private:
|
|
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple);
|
|
};
|
|
|
|
class EventHandlerImplementation {
|
|
public:
|
|
EventHandlerImplementation();
|
|
~EventHandlerImplementation();
|
|
|
|
void UpdateEpollInstance(intptr_t old_mask, DescriptorInfo* di);
|
|
|
|
// Gets the socket data structure for a given file
|
|
// descriptor. Creates a new one if one is not found.
|
|
DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening);
|
|
void SendData(intptr_t id, Dart_Port dart_port, int64_t data);
|
|
void Start(EventHandler* handler);
|
|
void Shutdown();
|
|
|
|
private:
|
|
void HandleEvents(struct epoll_event* events, int size);
|
|
static void Poll(uword args);
|
|
void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
|
|
void HandleInterruptFd();
|
|
void UpdateTimerFd();
|
|
void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
|
|
intptr_t GetPollEvents(intptr_t events, DescriptorInfo* di);
|
|
static void* GetHashmapKeyFromFd(intptr_t fd);
|
|
static uint32_t GetHashmapHashFromFd(intptr_t fd);
|
|
|
|
SimpleHashMap socket_map_;
|
|
TimeoutQueue timeout_queue_;
|
|
bool shutdown_;
|
|
int interrupt_fds_[2];
|
|
int epoll_fd_;
|
|
int timer_fd_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation);
|
|
};
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_BIN_EVENTHANDLER_LINUX_H_
|