Index: runtime/bin/eventhandler_linux.cc |
diff --git a/runtime/bin/eventhandler_linux.cc b/runtime/bin/eventhandler_linux.cc |
index a72f42a36ed6794f39ba5208ff642246e2e72e5a..0f60633aea5805c940af41b66b053e11022ed579 100644 |
--- a/runtime/bin/eventhandler_linux.cc |
+++ b/runtime/bin/eventhandler_linux.cc |
@@ -96,6 +96,11 @@ Dart_Port EventHandlerImplementation::PortFor(intptr_t fd) { |
} |
+bool EventHandlerImplementation::IsListeningSocket(intptr_t fd) { |
+ return (port_map_[fd].mask & (1 << kListeningSocket)) != 0; |
+} |
+ |
+ |
void EventHandlerImplementation::RegisterFdWakeup(intptr_t id, |
Dart_Port dart_port, |
intptr_t data) { |
@@ -136,17 +141,15 @@ void EventHandlerImplementation::WakeupHandler(intptr_t id, |
void EventHandlerImplementation::SetPollEvents(struct pollfd* pollfds, |
intptr_t mask) { |
- /* |
- * We do not set POLLERR and POLLHUP explicitly since they are triggered |
- * anyway. |
- */ |
- pollfds->events |= POLLRDHUP; |
+ // Do not ask for POLLERR and POLLHUP explicitly as they are |
+ // triggered anyway. |
if ((mask & (1 << kInEvent)) != 0) { |
pollfds->events |= POLLIN; |
} |
if ((mask & (1 << kOutEvent)) != 0) { |
pollfds->events |= POLLOUT; |
} |
+ pollfds->events |= POLLRDHUP; |
} |
@@ -213,27 +216,29 @@ void EventHandlerImplementation::HandleInterruptFd() { |
intptr_t EventHandlerImplementation::GetPollEvents(struct pollfd* pollfd) { |
intptr_t event_mask = 0; |
- /* |
- * We prioritize the events in the following order. |
- */ |
- if ((pollfd->revents & POLLIN) != 0) { |
- if (FDUtils::AvailableBytes(pollfd->fd) != 0) { |
- event_mask = (1 << kInEvent); |
- } else if (((pollfd->revents & POLLHUP) != 0) || |
- ((pollfd->revents & POLLRDHUP) != 0)) { |
- event_mask = (1 << kCloseEvent); |
- } else if ((pollfd->revents & POLLERR) != 0) { |
- event_mask = (1 << kErrorEvent); |
- } else { |
- /* |
- * Accept event. |
- */ |
- event_mask = (1 << kInEvent); |
+ if (IsListeningSocket(pollfd->fd)) { |
+ // For listening sockets the POLLIN event indicate that there are |
+ // connections ready for accept unless accompanied with one of the |
+ // other flags. |
+ if ((pollfd->revents & POLLIN) != 0) { |
+ if ((pollfd->revents & POLLHUP) != 0) event_mask |= (1 << kCloseEvent); |
+ if ((pollfd->revents & POLLERR) != 0) event_mask |= (1 << kErrorEvent); |
+ if (event_mask == 0) event_mask |= (1 << kInEvent); |
+ } |
+ } else { |
+ // Prioritize data events over close and error events. |
+ if ((pollfd->revents & POLLIN) != 0) { |
+ if (FDUtils::AvailableBytes(pollfd->fd) != 0) { |
+ event_mask = (1 << kInEvent); |
+ } else if (((pollfd->revents & POLLHUP) != 0) || |
+ ((pollfd->revents & POLLRDHUP) != 0)) { |
+ event_mask = (1 << kCloseEvent); |
+ } else if ((pollfd->revents & POLLERR) != 0) { |
+ event_mask = (1 << kErrorEvent); |
+ } |
} |
- } |
- if ((pollfd->revents & POLLOUT) != 0) { |
- event_mask |= (1 << kOutEvent); |
+ if ((pollfd->revents & POLLOUT) != 0) event_mask |= (1 << kOutEvent); |
} |
return event_mask; |