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_LINUX_H_ | 5 #ifndef RUNTIME_BIN_EVENTHANDLER_LINUX_H_ |
6 #define RUNTIME_BIN_EVENTHANDLER_LINUX_H_ | 6 #define RUNTIME_BIN_EVENTHANDLER_LINUX_H_ |
7 | 7 |
8 #if !defined(RUNTIME_BIN_EVENTHANDLER_H_) | 8 #if !defined(RUNTIME_BIN_EVENTHANDLER_H_) |
9 #error Do not include eventhandler_linux.h directly; use eventhandler.h instead. | 9 #error Do not include eventhandler_linux.h directly; use eventhandler.h instead. |
10 #endif | 10 #endif |
11 | 11 |
12 #include <errno.h> | 12 #include <errno.h> |
13 #include <sys/epoll.h> | 13 #include <sys/epoll.h> |
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) : DescriptorInfoBase(fd) { } | 26 explicit DescriptorInfo(intptr_t fd) : DescriptorInfoBase(fd) {} |
27 | 27 |
28 virtual ~DescriptorInfo() { } | 28 virtual ~DescriptorInfo() {} |
29 | 29 |
30 intptr_t GetPollEvents(); | 30 intptr_t GetPollEvents(); |
31 | 31 |
32 virtual void Close() { | 32 virtual void Close() { |
33 VOID_TEMP_FAILURE_RETRY(close(fd_)); | 33 VOID_TEMP_FAILURE_RETRY(close(fd_)); |
34 fd_ = -1; | 34 fd_ = -1; |
35 } | 35 } |
36 | 36 |
37 private: | 37 private: |
38 DISALLOW_COPY_AND_ASSIGN(DescriptorInfo); | 38 DISALLOW_COPY_AND_ASSIGN(DescriptorInfo); |
39 }; | 39 }; |
40 | 40 |
41 | 41 |
42 class DescriptorInfoSingle | 42 class DescriptorInfoSingle : public DescriptorInfoSingleMixin<DescriptorInfo> { |
43 : public DescriptorInfoSingleMixin<DescriptorInfo> { | |
44 public: | 43 public: |
45 explicit DescriptorInfoSingle(intptr_t fd) | 44 explicit DescriptorInfoSingle(intptr_t fd) |
46 : DescriptorInfoSingleMixin(fd, false) {} | 45 : DescriptorInfoSingleMixin(fd, false) {} |
47 virtual ~DescriptorInfoSingle() {} | 46 virtual ~DescriptorInfoSingle() {} |
48 | 47 |
49 private: | 48 private: |
50 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle); | 49 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle); |
51 }; | 50 }; |
52 | 51 |
53 | 52 |
54 class DescriptorInfoMultiple | 53 class DescriptorInfoMultiple |
55 : public DescriptorInfoMultipleMixin<DescriptorInfo> { | 54 : public DescriptorInfoMultipleMixin<DescriptorInfo> { |
56 public: | 55 public: |
57 explicit DescriptorInfoMultiple(intptr_t fd) | 56 explicit DescriptorInfoMultiple(intptr_t fd) |
58 : DescriptorInfoMultipleMixin(fd, false) {} | 57 : DescriptorInfoMultipleMixin(fd, false) {} |
59 virtual ~DescriptorInfoMultiple() {} | 58 virtual ~DescriptorInfoMultiple() {} |
60 | 59 |
61 private: | 60 private: |
62 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple); | 61 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple); |
63 }; | 62 }; |
64 | 63 |
65 | 64 |
66 class EventHandlerImplementation { | 65 class EventHandlerImplementation { |
67 public: | 66 public: |
68 EventHandlerImplementation(); | 67 EventHandlerImplementation(); |
69 ~EventHandlerImplementation(); | 68 ~EventHandlerImplementation(); |
70 | 69 |
71 void UpdateEpollInstance(intptr_t old_mask, DescriptorInfo *di); | 70 void UpdateEpollInstance(intptr_t old_mask, DescriptorInfo* di); |
72 | 71 |
73 // Gets the socket data structure for a given file | 72 // Gets the socket data structure for a given file |
74 // descriptor. Creates a new one if one is not found. | 73 // descriptor. Creates a new one if one is not found. |
75 DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening); | 74 DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening); |
76 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); | 75 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); |
77 void Start(EventHandler* handler); | 76 void Start(EventHandler* handler); |
78 void Shutdown(); | 77 void Shutdown(); |
79 | 78 |
80 private: | 79 private: |
81 void HandleEvents(struct epoll_event* events, int size); | 80 void HandleEvents(struct epoll_event* events, int size); |
(...skipping 12 matching lines...) Expand all Loading... |
94 int epoll_fd_; | 93 int epoll_fd_; |
95 int timer_fd_; | 94 int timer_fd_; |
96 | 95 |
97 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); | 96 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); |
98 }; | 97 }; |
99 | 98 |
100 } // namespace bin | 99 } // namespace bin |
101 } // namespace dart | 100 } // namespace dart |
102 | 101 |
103 #endif // RUNTIME_BIN_EVENTHANDLER_LINUX_H_ | 102 #endif // RUNTIME_BIN_EVENTHANDLER_LINUX_H_ |
OLD | NEW |