Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Side by Side Diff: runtime/bin/eventhandler_android.h

Issue 172133004: Also make eventhandler on Android edge-triggered. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_ANDROID_H_ 5 #ifndef BIN_EVENTHANDLER_ANDROID_H_
6 #define BIN_EVENTHANDLER_ANDROID_H_ 6 #define BIN_EVENTHANDLER_ANDROID_H_
7 7
8 #if !defined(BIN_EVENTHANDLER_H_) 8 #if !defined(BIN_EVENTHANDLER_H_)
9 #error Do not include eventhandler_android.h directly; 9 #error Do not include eventhandler_android.h directly;
10 #error use eventhandler.h instead. 10 #error use eventhandler.h instead.
(...skipping 10 matching lines...) Expand all
21 namespace bin { 21 namespace bin {
22 22
23 class InterruptMessage { 23 class InterruptMessage {
24 public: 24 public:
25 intptr_t id; 25 intptr_t id;
26 Dart_Port dart_port; 26 Dart_Port dart_port;
27 int64_t data; 27 int64_t data;
28 }; 28 };
29 29
30 30
31 enum PortDataFlags {
32 kClosedRead = 0,
33 kClosedWrite = 1,
34 };
35
36
37 class SocketData { 31 class SocketData {
38 public: 32 public:
39 explicit SocketData(intptr_t fd) 33 explicit SocketData(intptr_t fd)
40 : tracked_by_epoll_(false), fd_(fd), port_(0), mask_(0), flags_(0) { 34 : tracked_by_epoll_(false), fd_(fd), port_(0), mask_(0) {
41 ASSERT(fd_ != -1); 35 ASSERT(fd_ != -1);
42 } 36 }
43 37
44 intptr_t GetPollEvents();
45
46 void ShutdownRead() { 38 void ShutdownRead() {
47 shutdown(fd_, SHUT_RD); 39 shutdown(fd_, SHUT_RD);
48 MarkClosedRead();
49 } 40 }
50 41
51 void ShutdownWrite() { 42 void ShutdownWrite() {
52 shutdown(fd_, SHUT_WR); 43 shutdown(fd_, SHUT_WR);
53 MarkClosedWrite();
54 } 44 }
55 45
56 void Close() { 46 void Close() {
57 port_ = 0; 47 port_ = 0;
58 mask_ = 0; 48 mask_ = 0;
59 flags_ = 0;
60 close(fd_); 49 close(fd_);
61 fd_ = -1; 50 fd_ = -1;
62 } 51 }
63 52
64 bool IsListeningSocket() { return (mask_ & (1 << kListeningSocket)) != 0; } 53 bool IsListeningSocket() { return (mask_ & (1 << kListeningSocket)) != 0; }
65 bool IsPipe() { return (mask_ & (1 << kPipe)) != 0; } 54 bool IsPipe() { return (mask_ & (1 << kPipe)) != 0; }
66 bool IsClosedRead() { return (flags_ & (1 << kClosedRead)) != 0; }
67 bool IsClosedWrite() { return (flags_ & (1 << kClosedWrite)) != 0; }
68
69 void MarkClosedRead() { flags_ |= (1 << kClosedRead); }
70 void MarkClosedWrite() { flags_ |= (1 << kClosedWrite); }
71 55
72 void SetPortAndMask(Dart_Port port, intptr_t mask) { 56 void SetPortAndMask(Dart_Port port, intptr_t mask) {
73 ASSERT(fd_ != -1); 57 ASSERT(fd_ != -1);
74 port_ = port; 58 port_ = port;
75 mask_ = mask; 59 mask_ = mask;
76 } 60 }
77 61
78 intptr_t fd() { return fd_; } 62 intptr_t fd() { return fd_; }
79 Dart_Port port() { return port_; } 63 Dart_Port port() { return port_; }
80 intptr_t mask() { return mask_; } 64 intptr_t mask() { return mask_; }
81 bool tracked_by_epoll() { return tracked_by_epoll_; } 65 bool tracked_by_epoll() { return tracked_by_epoll_; }
82 void set_tracked_by_epoll(bool value) { tracked_by_epoll_ = value; } 66 void set_tracked_by_epoll(bool value) { tracked_by_epoll_ = value; }
83 67
84 private: 68 private:
85 bool tracked_by_epoll_; 69 bool tracked_by_epoll_;
86 intptr_t fd_; 70 intptr_t fd_;
87 Dart_Port port_; 71 Dart_Port port_;
88 intptr_t mask_; 72 intptr_t mask_;
89 intptr_t flags_;
90 }; 73 };
91 74
92 75
93 class EventHandlerImplementation { 76 class EventHandlerImplementation {
94 public: 77 public:
95 EventHandlerImplementation(); 78 EventHandlerImplementation();
96 ~EventHandlerImplementation(); 79 ~EventHandlerImplementation();
97 80
98 // Gets the socket data structure for a given file 81 // Gets the socket data structure for a given file
99 // descriptor. Creates a new one if one is not found. 82 // descriptor. Creates a new one if one is not found.
100 SocketData* GetSocketData(intptr_t fd); 83 SocketData* GetSocketData(intptr_t fd, bool* is_new);
101 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data); 84 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data);
102 void Start(EventHandler* handler); 85 void Start(EventHandler* handler);
103 void Shutdown(); 86 void Shutdown();
104 87
105 private: 88 private:
106 int64_t GetTimeout(); 89 int64_t GetTimeout();
107 void HandleEvents(struct epoll_event* events, int size); 90 void HandleEvents(struct epoll_event* events, int size);
108 void HandleTimeout(); 91 void HandleTimeout();
109 static void Poll(uword args); 92 static void Poll(uword args);
110 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); 93 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
111 void HandleInterruptFd(); 94 void HandleInterruptFd();
112 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); 95 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
113 intptr_t GetPollEvents(intptr_t events, SocketData* sd); 96 intptr_t GetPollEvents(intptr_t events, SocketData* sd);
114 static void* GetHashmapKeyFromFd(intptr_t fd); 97 static void* GetHashmapKeyFromFd(intptr_t fd);
115 static uint32_t GetHashmapHashFromFd(intptr_t fd); 98 static uint32_t GetHashmapHashFromFd(intptr_t fd);
116 99
117 HashMap socket_map_; 100 HashMap socket_map_;
118 TimeoutQueue timeout_queue_; 101 TimeoutQueue timeout_queue_;
119 bool shutdown_; 102 bool shutdown_;
120 int interrupt_fds_[2]; 103 int interrupt_fds_[2];
121 int epoll_fd_; 104 int epoll_fd_;
122 }; 105 };
123 106
124 } // namespace bin 107 } // namespace bin
125 } // namespace dart 108 } // namespace dart
126 109
127 #endif // BIN_EVENTHANDLER_ANDROID_H_ 110 #endif // BIN_EVENTHANDLER_ANDROID_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698