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 RUNTIME_BIN_EVENTHANDLER_MACOS_H_ | 5 #ifndef RUNTIME_BIN_EVENTHANDLER_MACOS_H_ |
6 #define RUNTIME_BIN_EVENTHANDLER_MACOS_H_ | 6 #define RUNTIME_BIN_EVENTHANDLER_MACOS_H_ |
7 | 7 |
8 #if !defined(RUNTIME_BIN_EVENTHANDLER_H_) | 8 #if !defined(RUNTIME_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 DescriptorInfo : public DescriptorInfoBase { | 24 class DescriptorInfo : public DescriptorInfoBase { |
25 public: | 25 public: |
26 explicit DescriptorInfo(intptr_t fd) | 26 explicit DescriptorInfo(intptr_t fd) |
27 : DescriptorInfoBase(fd), tracked_by_kqueue_(false) { } | 27 : DescriptorInfoBase(fd), tracked_by_kqueue_(false) {} |
28 | 28 |
29 virtual ~DescriptorInfo() { } | 29 virtual ~DescriptorInfo() {} |
30 | 30 |
31 intptr_t GetPollEvents(); | 31 intptr_t GetPollEvents(); |
32 | 32 |
33 virtual void Close() { | 33 virtual void Close() { |
34 VOID_TEMP_FAILURE_RETRY(close(fd_)); | 34 VOID_TEMP_FAILURE_RETRY(close(fd_)); |
35 fd_ = -1; | 35 fd_ = -1; |
36 } | 36 } |
37 | 37 |
38 void set_tracked_by_kqueue(bool value) { | 38 void set_tracked_by_kqueue(bool value) { tracked_by_kqueue_ = value; } |
39 tracked_by_kqueue_ = value; | |
40 } | |
41 | 39 |
42 bool tracked_by_kqueue() { return tracked_by_kqueue_; } | 40 bool tracked_by_kqueue() { return tracked_by_kqueue_; } |
43 | 41 |
44 bool HasReadEvent(); | 42 bool HasReadEvent(); |
45 | 43 |
46 bool HasWriteEvent(); | 44 bool HasWriteEvent(); |
47 | 45 |
48 protected: | 46 protected: |
49 bool tracked_by_kqueue_; | 47 bool tracked_by_kqueue_; |
50 | 48 |
51 private: | 49 private: |
52 DISALLOW_COPY_AND_ASSIGN(DescriptorInfo); | 50 DISALLOW_COPY_AND_ASSIGN(DescriptorInfo); |
53 }; | 51 }; |
54 | 52 |
55 | 53 |
56 class DescriptorInfoSingle | 54 class DescriptorInfoSingle : public DescriptorInfoSingleMixin<DescriptorInfo> { |
57 : public DescriptorInfoSingleMixin<DescriptorInfo> { | |
58 public: | 55 public: |
59 explicit DescriptorInfoSingle(intptr_t fd) | 56 explicit DescriptorInfoSingle(intptr_t fd) |
60 : DescriptorInfoSingleMixin(fd, false) {} | 57 : DescriptorInfoSingleMixin(fd, false) {} |
61 virtual ~DescriptorInfoSingle() {} | 58 virtual ~DescriptorInfoSingle() {} |
62 | 59 |
63 private: | 60 private: |
64 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle); | 61 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle); |
65 }; | 62 }; |
66 | 63 |
67 | 64 |
68 class DescriptorInfoMultiple | 65 class DescriptorInfoMultiple |
69 : public DescriptorInfoMultipleMixin<DescriptorInfo> { | 66 : public DescriptorInfoMultipleMixin<DescriptorInfo> { |
70 public: | 67 public: |
71 explicit DescriptorInfoMultiple(intptr_t fd) | 68 explicit DescriptorInfoMultiple(intptr_t fd) |
72 : DescriptorInfoMultipleMixin(fd, false) {} | 69 : DescriptorInfoMultipleMixin(fd, false) {} |
73 virtual ~DescriptorInfoMultiple() {} | 70 virtual ~DescriptorInfoMultiple() {} |
74 | 71 |
75 private: | 72 private: |
76 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple); | 73 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple); |
77 }; | 74 }; |
78 | 75 |
79 | 76 |
80 class EventHandlerImplementation { | 77 class EventHandlerImplementation { |
81 public: | 78 public: |
82 EventHandlerImplementation(); | 79 EventHandlerImplementation(); |
83 ~EventHandlerImplementation(); | 80 ~EventHandlerImplementation(); |
84 | 81 |
85 void UpdateKQueueInstance(intptr_t old_mask, DescriptorInfo *di); | 82 void UpdateKQueueInstance(intptr_t old_mask, DescriptorInfo* di); |
86 | 83 |
87 // Gets the socket data structure for a given file | 84 // Gets the socket data structure for a given file |
88 // descriptor. Creates a new one if one is not found. | 85 // descriptor. Creates a new one if one is not found. |
89 DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening); | 86 DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening); |
90 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); | 87 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); |
91 void Start(EventHandler* handler); | 88 void Start(EventHandler* handler); |
92 void Shutdown(); | 89 void Shutdown(); |
93 | 90 |
94 private: | 91 private: |
95 int64_t GetTimeout(); | 92 int64_t GetTimeout(); |
(...skipping 13 matching lines...) Expand all Loading... |
109 int interrupt_fds_[2]; | 106 int interrupt_fds_[2]; |
110 int kqueue_fd_; | 107 int kqueue_fd_; |
111 | 108 |
112 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); | 109 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); |
113 }; | 110 }; |
114 | 111 |
115 } // namespace bin | 112 } // namespace bin |
116 } // namespace dart | 113 } // namespace dart |
117 | 114 |
118 #endif // RUNTIME_BIN_EVENTHANDLER_MACOS_H_ | 115 #endif // RUNTIME_BIN_EVENTHANDLER_MACOS_H_ |
OLD | NEW |