| Index: runtime/bin/eventhandler_linux.h
|
| diff --git a/runtime/bin/eventhandler_linux.h b/runtime/bin/eventhandler_linux.h
|
| index f5386c34fbca8a1808a12ae8e5ace1899759f223..9341cd11f3ec30d9c7c5b13b1b4b60c33d764499 100644
|
| --- a/runtime/bin/eventhandler_linux.h
|
| +++ b/runtime/bin/eventhandler_linux.h
|
| @@ -14,32 +14,93 @@
|
| #include <sys/socket.h>
|
|
|
| #include "platform/hashmap.h"
|
| -#include "platform/thread.h"
|
|
|
|
|
| namespace dart {
|
| namespace bin {
|
|
|
| +class InterruptMessage {
|
| + public:
|
| + intptr_t id;
|
| + Dart_Port dart_port;
|
| + int64_t data;
|
| +};
|
| +
|
| +
|
| +class SocketData {
|
| + public:
|
| + explicit SocketData(intptr_t fd) : fd_(fd), port_(0), mask_(0), tokens_(8) {
|
| + ASSERT(fd_ != -1);
|
| + }
|
| +
|
| + intptr_t GetPollEvents();
|
| +
|
| + void Close() {
|
| + port_ = 0;
|
| + mask_ = 0;
|
| + close(fd_);
|
| + fd_ = -1;
|
| + }
|
| +
|
| + void SetPortAndMask(Dart_Port port, intptr_t mask) {
|
| + ASSERT(fd_ != -1);
|
| + port_ = port;
|
| + mask_ = mask;
|
| + }
|
| +
|
| + intptr_t fd() { return fd_; }
|
| + Dart_Port port() { return port_; }
|
| +
|
| + // Returns true if the last token was taken.
|
| + bool TakeToken() {
|
| + ASSERT(tokens_ > 0);
|
| + tokens_--;
|
| + return tokens_ == 0;
|
| + }
|
| +
|
| + // Returns true if the tokens was 0 before adding.
|
| + bool ReturnToken() {
|
| + ASSERT(tokens_ >= 0);
|
| + tokens_++;
|
| + return tokens_ == 1;
|
| + }
|
| +
|
| + private:
|
| + intptr_t fd_;
|
| + Dart_Port port_;
|
| + intptr_t mask_;
|
| + int tokens_;
|
| +};
|
| +
|
| +
|
| class EventHandlerImplementation {
|
| public:
|
| EventHandlerImplementation();
|
| ~EventHandlerImplementation();
|
|
|
| - void Notify(intptr_t id, Dart_Port dart_port, int64_t data);
|
| + // Gets the socket data structure for a given file
|
| + // descriptor. Creates a new one if one is not found.
|
| + SocketData* GetSocketData(intptr_t fd);
|
| + 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 SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
|
| - intptr_t GetPollEvents(intptr_t events);
|
| + intptr_t GetPollEvents(intptr_t events, SocketData* sd);
|
| + static void* GetHashmapKeyFromFd(intptr_t fd);
|
| + static uint32_t GetHashmapHashFromFd(intptr_t fd);
|
|
|
| + HashMap socket_map_;
|
| TimeoutQueue timeout_queue_;
|
| bool shutdown_;
|
| + int interrupt_fds_[2];
|
| int epoll_fd_;
|
| int timer_fd_;
|
| - Mutex timer_mutex_;
|
| };
|
|
|
| } // namespace bin
|
|
|