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

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

Issue 12328052: Handle single EPOLLHUP epoll events on Linux. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | no next file » | 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 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/eventhandler.h" 8 #include "bin/eventhandler.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // For listening sockets the EPOLLIN event indicate that there are 258 // For listening sockets the EPOLLIN event indicate that there are
259 // connections ready for accept unless accompanied with one of the 259 // connections ready for accept unless accompanied with one of the
260 // other flags. 260 // other flags.
261 if ((events & EPOLLIN) != 0) { 261 if ((events & EPOLLIN) != 0) {
262 if ((events & EPOLLHUP) != 0) event_mask |= (1 << kCloseEvent); 262 if ((events & EPOLLHUP) != 0) event_mask |= (1 << kCloseEvent);
263 if ((events & EPOLLERR) != 0) event_mask |= (1 << kErrorEvent); 263 if ((events & EPOLLERR) != 0) event_mask |= (1 << kErrorEvent);
264 if (event_mask == 0) event_mask |= (1 << kInEvent); 264 if (event_mask == 0) event_mask |= (1 << kInEvent);
265 } 265 }
266 } else { 266 } else {
267 // Prioritize data events over close and error events. 267 // Prioritize data events over close and error events.
268 if ((events & EPOLLIN) != 0) { 268 if ((events & (EPOLLIN | EPOLLHUP | EPOLLERR)) != 0) {
269 if (FDUtils::AvailableBytes(sd->fd()) != 0) { 269 // If we have EPOLLIN and we have available writes, report that.
Søren Gjesse 2013/02/22 11:41:20 writes -> bytes
Anders Johnsen 2013/02/22 11:42:19 Done.
270 if ((events & EPOLLIN) && FDUtils::AvailableBytes(sd->fd()) != 0) {
270 event_mask = (1 << kInEvent); 271 event_mask = (1 << kInEvent);
271 } else if ((events & EPOLLHUP) != 0) { 272 } else if ((events & EPOLLHUP) != 0) {
272 // If both EPOLLHUP and EPOLLERR are reported treat it as an 273 // If both EPOLLHUP and EPOLLERR are reported treat it as an
273 // error. 274 // error.
274 if ((events & EPOLLERR) != 0) { 275 if ((events & EPOLLERR) != 0) {
275 event_mask = (1 << kErrorEvent); 276 event_mask = (1 << kErrorEvent);
276 } else { 277 } else {
277 event_mask = (1 << kCloseEvent); 278 event_mask = (1 << kCloseEvent);
278 } 279 }
279 sd->MarkClosedRead(); 280 sd->MarkClosedRead();
(...skipping 19 matching lines...) Expand all
299 if (bytesPeeked == 0) { 300 if (bytesPeeked == 0) {
300 event_mask = (1 << kCloseEvent); 301 event_mask = (1 << kCloseEvent);
301 sd->MarkClosedRead(); 302 sd->MarkClosedRead();
302 } else if (errno != EWOULDBLOCK) { 303 } else if (errno != EWOULDBLOCK) {
303 Log::PrintErr("Error recv: %s\n", strerror(errno)); 304 Log::PrintErr("Error recv: %s\n", strerror(errno));
304 } 305 }
305 } 306 }
306 } 307 }
307 } 308 }
308 309
309 // On pipes EPOLLHUP is reported without EPOLLIN when there is no
310 // more data to read.
311 if (sd->IsPipe()) {
312 if (((events & EPOLLIN) == 0) &&
313 ((events & EPOLLHUP) != 0)) {
314 event_mask = (1 << kCloseEvent);
315 sd->MarkClosedRead();
316 }
317 } else {
318 // Assert we never get an EPOLLHUP on a non-pipe file-descriptor.
319 ASSERT(events != EPOLLHUP);
320 }
321
322 if ((events & EPOLLOUT) != 0) { 310 if ((events & EPOLLOUT) != 0) {
323 if ((events & EPOLLERR) != 0) { 311 if ((events & EPOLLERR) != 0) {
324 event_mask = (1 << kErrorEvent); 312 event_mask = (1 << kErrorEvent);
325 sd->MarkClosedWrite(); 313 sd->MarkClosedWrite();
326 } else { 314 } else {
327 event_mask |= (1 << kOutEvent); 315 event_mask |= (1 << kOutEvent);
328 } 316 }
329 } 317 }
330
331 if (events == (EPOLLHUP | EPOLLERR)) {
332 event_mask = (1 << kErrorEvent);
333 sd->MarkClosedWrite();
334 sd->MarkClosedRead();
335 }
336 } 318 }
337 319
338 return event_mask; 320 return event_mask;
339 } 321 }
340 322
341 323
342 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, 324 void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
343 int size) { 325 int size) {
344 for (int i = 0; i < size; i++) { 326 for (int i = 0; i < size; i++) {
345 if (events[i].data.ptr != NULL) { 327 if (events[i].data.ptr != NULL) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 return reinterpret_cast<void*>(fd + 1); 416 return reinterpret_cast<void*>(fd + 1);
435 } 417 }
436 418
437 419
438 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 420 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
439 // The hashmap does not support keys with value 0. 421 // The hashmap does not support keys with value 0.
440 return dart::Utils::WordHash(fd + 1); 422 return dart::Utils::WordHash(fd + 1);
441 } 423 }
442 424
443 #endif // defined(TARGET_OS_LINUX) 425 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698