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

Side by Side Diff: runtime/bin/eventhandler_linux.cc

Issue 8399039: Explicitly handle listen sockets and connection sockets differently in Linux and Mac OS eventhandler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Mac OS build Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #include <errno.h> 5 #include <errno.h>
6 #include <poll.h> 6 #include <poll.h>
7 #include <pthread.h> 7 #include <pthread.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/time.h> 10 #include <sys/time.h>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 port_map_[fd].dart_port = dart_port; 89 port_map_[fd].dart_port = dart_port;
90 port_map_[fd].mask = mask; 90 port_map_[fd].mask = mask;
91 } 91 }
92 92
93 93
94 Dart_Port EventHandlerImplementation::PortFor(intptr_t fd) { 94 Dart_Port EventHandlerImplementation::PortFor(intptr_t fd) {
95 return port_map_[fd].dart_port; 95 return port_map_[fd].dart_port;
96 } 96 }
97 97
98 98
99 bool EventHandlerImplementation::IsListeningSocket(intptr_t fd) {
100 return (port_map_[fd].mask & (1 << kListenSocket)) != 0;
Mads Ager (google) 2011/10/28 08:33:23 kListeningSocket?
Søren Gjesse 2011/10/28 09:24:19 Done.
101 }
102
103
99 void EventHandlerImplementation::RegisterFdWakeup(intptr_t id, 104 void EventHandlerImplementation::RegisterFdWakeup(intptr_t id,
100 Dart_Port dart_port, 105 Dart_Port dart_port,
101 intptr_t data) { 106 intptr_t data) {
102 WakeupHandler(id, dart_port, data); 107 WakeupHandler(id, dart_port, data);
103 } 108 }
104 109
105 110
106 void EventHandlerImplementation::CloseFd(intptr_t id) { 111 void EventHandlerImplementation::CloseFd(intptr_t id) {
107 SetPort(id, 0, 0); 112 SetPort(id, 0, 0);
108 close(id); 113 close(id);
(...skipping 20 matching lines...) Expand all
129 intptr_t result = 134 intptr_t result =
130 write(interrupt_fds_[1], &msg, kInterruptMessageSize); 135 write(interrupt_fds_[1], &msg, kInterruptMessageSize);
131 if (result != kInterruptMessageSize) { 136 if (result != kInterruptMessageSize) {
132 perror("Interrupt message failure"); 137 perror("Interrupt message failure");
133 } 138 }
134 } 139 }
135 140
136 141
137 void EventHandlerImplementation::SetPollEvents(struct pollfd* pollfds, 142 void EventHandlerImplementation::SetPollEvents(struct pollfd* pollfds,
138 intptr_t mask) { 143 intptr_t mask) {
139 /* 144 // Do not ask for POLLERR and POLLHUP explicitly as they are
140 * We do not set POLLERR and POLLHUP explicitly since they are triggered 145 // triggered anyway.
141 * anyway.
142 */
143 pollfds->events |= POLLRDHUP;
144 if ((mask & (1 << kInEvent)) != 0) { 146 if ((mask & (1 << kInEvent)) != 0) {
145 pollfds->events |= POLLIN; 147 pollfds->events |= POLLIN;
146 } 148 }
147 if ((mask & (1 << kOutEvent)) != 0) { 149 if ((mask & (1 << kOutEvent)) != 0) {
148 pollfds->events |= POLLOUT; 150 pollfds->events |= POLLOUT;
149 } 151 }
152 pollfds->events |= POLLRDHUP;
150 } 153 }
151 154
152 155
153 struct pollfd* EventHandlerImplementation::GetPollFds(intptr_t* pollfds_size) { 156 struct pollfd* EventHandlerImplementation::GetPollFds(intptr_t* pollfds_size) {
154 struct pollfd* pollfds; 157 struct pollfd* pollfds;
155 158
156 intptr_t numPollfds = 1 + port_map_entries_; 159 intptr_t numPollfds = 1 + port_map_entries_;
157 pollfds = reinterpret_cast<struct pollfd*>(calloc(sizeof(struct pollfd), 160 pollfds = reinterpret_cast<struct pollfd*>(calloc(sizeof(struct pollfd),
158 numPollfds)); 161 numPollfds));
159 pollfds[0].fd = interrupt_fds_[0]; 162 pollfds[0].fd = interrupt_fds_[0];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 CloseFd(msg.id); 209 CloseFd(msg.id);
207 } else { 210 } else {
208 SetPort(msg.id, msg.dart_port, msg.data); 211 SetPort(msg.id, msg.dart_port, msg.data);
209 } 212 }
210 } 213 }
211 } 214 }
212 215
213 216
214 intptr_t EventHandlerImplementation::GetPollEvents(struct pollfd* pollfd) { 217 intptr_t EventHandlerImplementation::GetPollEvents(struct pollfd* pollfd) {
215 intptr_t event_mask = 0; 218 intptr_t event_mask = 0;
216 /* 219 if (IsListeningSocket(pollfd->fd)) {
217 * We prioritize the events in the following order. 220 // For listening sockets the POLLIN event indicate that there are
218 */ 221 // connections ready for accept.
219 if ((pollfd->revents & POLLIN) != 0) { 222 if ((pollfd->revents & POLLIN) != 0) event_mask |= (1 << kInEvent);
Mads Ager (google) 2011/10/28 08:33:23 Should we assert that there is no overlap in these
Søren Gjesse 2011/10/28 09:24:19 I would be reluctant to try to assert anything her
220 if (FDUtils::AvailableBytes(pollfd->fd) != 0) { 223 if ((pollfd->revents & POLLHUP) != 0) event_mask |= (1 << kCloseEvent);
221 event_mask = (1 << kInEvent); 224 if ((pollfd->revents & POLLERR) != 0) event_mask |= (1 << kErrorEvent);
222 } else if (((pollfd->revents & POLLHUP) != 0) || 225 } else {
223 ((pollfd->revents & POLLRDHUP) != 0)) { 226 // Prioritize data events over close and error events.
224 event_mask = (1 << kCloseEvent); 227 if ((pollfd->revents & POLLIN) != 0) {
225 } else if ((pollfd->revents & POLLERR) != 0) { 228 if (FDUtils::AvailableBytes(pollfd->fd) != 0) {
226 event_mask = (1 << kErrorEvent); 229 event_mask = (1 << kInEvent);
227 } else { 230 } else if (((pollfd->revents & POLLHUP) != 0) ||
228 /* 231 ((pollfd->revents & POLLRDHUP) != 0)) {
229 * Accept event. 232 event_mask = (1 << kCloseEvent);
230 */ 233 } else if ((pollfd->revents & POLLERR) != 0) {
231 event_mask = (1 << kInEvent); 234 event_mask = (1 << kErrorEvent);
235 }
232 } 236 }
233 }
234 237
235 if ((pollfd->revents & POLLOUT) != 0) { 238 if ((pollfd->revents & POLLOUT) != 0) event_mask |= (1 << kOutEvent);
236 event_mask |= (1 << kOutEvent);
237 } 239 }
238 240
239 return event_mask; 241 return event_mask;
240 } 242 }
241 243
242 244
243 void EventHandlerImplementation::HandleEvents(struct pollfd* pollfds, 245 void EventHandlerImplementation::HandleEvents(struct pollfd* pollfds,
244 int pollfds_size, 246 int pollfds_size,
245 int result_size) { 247 int result_size) {
246 if ((pollfds[0].revents & POLLIN) != 0) { 248 if ((pollfds[0].revents & POLLIN) != 0) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 FATAL("Create start event handler thread"); 320 FATAL("Create start event handler thread");
319 } 321 }
320 } 322 }
321 323
322 324
323 void EventHandlerImplementation::SendData(intptr_t id, 325 void EventHandlerImplementation::SendData(intptr_t id,
324 Dart_Port dart_port, 326 Dart_Port dart_port,
325 intptr_t data) { 327 intptr_t data) {
326 RegisterFdWakeup(id, dart_port, data); 328 RegisterFdWakeup(id, dart_port, data);
327 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698