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_MACOS_H_ | 5 #ifndef BIN_EVENTHANDLER_MACOS_H_ |
6 #define BIN_EVENTHANDLER_MACOS_H_ | 6 #define BIN_EVENTHANDLER_MACOS_H_ |
7 | 7 |
8 #if !defined(BIN_EVENTHANDLER_H_) | 8 #if !defined(BIN_EVENTHANDLER_H_) |
9 #error Do not include eventhandler_macos.h directly; use eventhandler.h instead. | 9 #error Do not include eventhandler_macos.h directly; use eventhandler.h instead. |
10 #endif | 10 #endif |
11 | 11 |
12 #include <errno.h> | 12 #include <errno.h> |
13 #include <sys/event.h> // NOLINT | 13 #include <sys/event.h> // NOLINT |
14 #include <sys/socket.h> | 14 #include <sys/socket.h> |
15 #include <unistd.h> | 15 #include <unistd.h> |
16 | 16 |
17 #include "platform/hashmap.h" | 17 #include "platform/hashmap.h" |
18 #include "platform/signal_blocker.h" | 18 #include "platform/signal_blocker.h" |
19 | 19 |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 namespace bin { | 22 namespace bin { |
23 | 23 |
24 class SocketData { | 24 class SocketData { |
25 public: | 25 public: |
26 explicit SocketData(intptr_t fd) | 26 explicit SocketData(intptr_t fd, bool is_listening) |
27 : fd_(fd), | 27 : fd_(fd), |
28 port_(0), | 28 port_(0), |
29 mask_(0), | 29 mask_(0), |
30 tracked_by_kqueue_(false), | 30 tracked_by_kqueue_(false), |
31 tokens_(16) { | 31 tokens_(16), |
| 32 is_listening_(is_listening) { |
32 ASSERT(fd_ != -1); | 33 ASSERT(fd_ != -1); |
33 } | 34 } |
34 | 35 |
35 bool HasReadEvent(); | 36 bool HasReadEvent(); |
36 bool HasWriteEvent(); | 37 bool HasWriteEvent(); |
37 | 38 |
38 bool IsListeningSocket() { return (mask_ & (1 << kListeningSocket)) != 0; } | 39 bool IsListeningSocket() { return is_listening_; } |
39 | 40 |
40 void SetPortAndMask(Dart_Port port, intptr_t mask) { | 41 void SetPortAndMask(Dart_Port port, intptr_t mask) { |
41 ASSERT(fd_ != -1); | 42 ASSERT(fd_ != -1); |
42 port_ = port; | 43 port_ = port; |
43 mask_ = mask; | 44 mask_ = mask; |
44 } | 45 } |
45 | 46 |
46 intptr_t fd() { return fd_; } | 47 intptr_t fd() { return fd_; } |
47 Dart_Port port() { return port_; } | 48 Dart_Port port() { return port_; } |
48 intptr_t mask() { return mask_; } | 49 intptr_t mask() { return mask_; } |
(...skipping 13 matching lines...) Expand all Loading... |
62 tokens_++; | 63 tokens_++; |
63 return tokens_ == 1; | 64 return tokens_ == 1; |
64 } | 65 } |
65 | 66 |
66 private: | 67 private: |
67 intptr_t fd_; | 68 intptr_t fd_; |
68 Dart_Port port_; | 69 Dart_Port port_; |
69 intptr_t mask_; | 70 intptr_t mask_; |
70 bool tracked_by_kqueue_; | 71 bool tracked_by_kqueue_; |
71 int tokens_; | 72 int tokens_; |
| 73 bool is_listening_; |
72 }; | 74 }; |
73 | 75 |
74 | 76 |
75 class EventHandlerImplementation { | 77 class EventHandlerImplementation { |
76 public: | 78 public: |
77 EventHandlerImplementation(); | 79 EventHandlerImplementation(); |
78 ~EventHandlerImplementation(); | 80 ~EventHandlerImplementation(); |
79 | 81 |
80 // Gets the socket data structure for a given file | 82 // Gets the socket data structure for a given file |
81 // descriptor. Creates a new one if one is not found. | 83 // descriptor. Creates a new one if one is not found. |
82 SocketData* GetSocketData(intptr_t fd); | 84 SocketData* GetSocketData(intptr_t fd, bool is_listening); |
83 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); | 85 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); |
84 void Start(EventHandler* handler); | 86 void Start(EventHandler* handler); |
85 void Shutdown(); | 87 void Shutdown(); |
86 | 88 |
87 private: | 89 private: |
88 int64_t GetTimeout(); | 90 int64_t GetTimeout(); |
89 void HandleEvents(struct kevent* events, int size); | 91 void HandleEvents(struct kevent* events, int size); |
90 void HandleTimeout(); | 92 void HandleTimeout(); |
91 static void EventHandlerEntry(uword args); | 93 static void EventHandlerEntry(uword args); |
92 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); | 94 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); |
93 void HandleInterruptFd(); | 95 void HandleInterruptFd(); |
94 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); | 96 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); |
95 intptr_t GetEvents(struct kevent* event, SocketData* sd); | 97 intptr_t GetEvents(struct kevent* event, SocketData* sd); |
96 static void* GetHashmapKeyFromFd(intptr_t fd); | 98 static void* GetHashmapKeyFromFd(intptr_t fd); |
97 static uint32_t GetHashmapHashFromFd(intptr_t fd); | 99 static uint32_t GetHashmapHashFromFd(intptr_t fd); |
98 | 100 |
99 HashMap socket_map_; | 101 HashMap socket_map_; |
100 TimeoutQueue timeout_queue_; | 102 TimeoutQueue timeout_queue_; |
101 bool shutdown_; | 103 bool shutdown_; |
102 int interrupt_fds_[2]; | 104 int interrupt_fds_[2]; |
103 int kqueue_fd_; | 105 int kqueue_fd_; |
104 }; | 106 }; |
105 | 107 |
106 } // namespace bin | 108 } // namespace bin |
107 } // namespace dart | 109 } // namespace dart |
108 | 110 |
109 #endif // BIN_EVENTHANDLER_MACOS_H_ | 111 #endif // BIN_EVENTHANDLER_MACOS_H_ |
OLD | NEW |