| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BIN_EVENTHANDLER_LINUX_H_ | 5 #ifndef BIN_EVENTHANDLER_LINUX_H_ |
| 6 #define BIN_EVENTHANDLER_LINUX_H_ | 6 #define BIN_EVENTHANDLER_LINUX_H_ |
| 7 | 7 |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 | 10 |
| 11 #include "bin/thread_pool.h" | 11 #include "bin/hashmap.h" |
| 12 | 12 |
| 13 class InterruptMessage { | 13 class InterruptMessage { |
| 14 public: | 14 public: |
| 15 intptr_t id; | 15 intptr_t id; |
| 16 Dart_Port dart_port; | 16 Dart_Port dart_port; |
| 17 int64_t data; | 17 int64_t data; |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 | 20 |
| 21 enum PortDataFlags { | 21 enum PortDataFlags { |
| 22 kClosedRead = 0, | 22 kClosedRead = 0, |
| 23 kClosedWrite = 1, | 23 kClosedWrite = 1, |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 | 26 |
| 27 class SocketData { | 27 class SocketData { |
| 28 public: | 28 public: |
| 29 SocketData(intptr_t fd) : fd_(fd), port_(0), mask_(0), flags_(0) { |
| 30 ASSERT(fd_ != -1); |
| 31 } |
| 32 |
| 29 intptr_t GetPollEvents(); | 33 intptr_t GetPollEvents(); |
| 30 | 34 |
| 31 void Unregister() { | 35 void Unregister() { |
| 32 port_ = 0; | 36 port_ = 0; |
| 33 mask_ = 0; | 37 mask_ = 0; |
| 34 } | 38 } |
| 35 | 39 |
| 36 void ShutdownRead() { | 40 void ShutdownRead() { |
| 37 shutdown(fd_, SHUT_RD); | 41 shutdown(fd_, SHUT_RD); |
| 38 MarkClosedRead(); | 42 MarkClosedRead(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 60 | 64 |
| 61 bool HasPollEvents() { return mask_ != 0; } | 65 bool HasPollEvents() { return mask_ != 0; } |
| 62 | 66 |
| 63 void SetPortAndMask(Dart_Port port, intptr_t mask) { | 67 void SetPortAndMask(Dart_Port port, intptr_t mask) { |
| 64 ASSERT(fd_ != -1); | 68 ASSERT(fd_ != -1); |
| 65 port_ = port; | 69 port_ = port; |
| 66 mask_ = mask; | 70 mask_ = mask; |
| 67 } | 71 } |
| 68 | 72 |
| 69 intptr_t fd() { return fd_; } | 73 intptr_t fd() { return fd_; } |
| 70 void set_fd(intptr_t fd) { fd_ = fd; } | |
| 71 Dart_Port port() { return port_; } | 74 Dart_Port port() { return port_; } |
| 72 intptr_t mask() { return mask_; } | 75 intptr_t mask() { return mask_; } |
| 73 | 76 |
| 74 private: | 77 private: |
| 75 intptr_t fd_; | 78 intptr_t fd_; |
| 76 Dart_Port port_; | 79 Dart_Port port_; |
| 77 intptr_t mask_; | 80 intptr_t mask_; |
| 78 intptr_t flags_; | 81 intptr_t flags_; |
| 79 }; | 82 }; |
| 80 | 83 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 intptr_t GetTimeout(); | 95 intptr_t GetTimeout(); |
| 93 bool GetInterruptMessage(InterruptMessage* msg); | 96 bool GetInterruptMessage(InterruptMessage* msg); |
| 94 struct pollfd* GetPollFds(intptr_t* size); | 97 struct pollfd* GetPollFds(intptr_t* size); |
| 95 void HandleEvents(struct pollfd* pollfds, int pollfds_size, int result_size); | 98 void HandleEvents(struct pollfd* pollfds, int pollfds_size, int result_size); |
| 96 void HandleTimeout(); | 99 void HandleTimeout(); |
| 97 static void* Poll(void* args); | 100 static void* Poll(void* args); |
| 98 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); | 101 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); |
| 99 void HandleInterruptFd(); | 102 void HandleInterruptFd(); |
| 100 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); | 103 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); |
| 101 intptr_t GetPollEvents(struct pollfd* pollfd); | 104 intptr_t GetPollEvents(struct pollfd* pollfd); |
| 105 static void* GetHashmapKeyFromFd(intptr_t fd); |
| 106 static uint32_t GetHashmapHashFromFd(intptr_t fd); |
| 102 | 107 |
| 103 SocketData* socket_map_; | 108 HashMap socket_map_; |
| 104 intptr_t socket_map_size_; | |
| 105 int64_t timeout_; // Time for next timeout. | 109 int64_t timeout_; // Time for next timeout. |
| 106 Dart_Port timeout_port_; | 110 Dart_Port timeout_port_; |
| 107 int interrupt_fds_[2]; | 111 int interrupt_fds_[2]; |
| 108 }; | 112 }; |
| 109 | 113 |
| 110 | 114 |
| 111 #endif // BIN_EVENTHANDLER_LINUX_H_ | 115 #endif // BIN_EVENTHANDLER_LINUX_H_ |
| OLD | NEW |