Chromium Code Reviews| Index: runtime/bin/eventhandler_linux.cc |
| diff --git a/runtime/bin/eventhandler_linux.cc b/runtime/bin/eventhandler_linux.cc |
| index a72f42a36ed6794f39ba5208ff642246e2e72e5a..c80c620d0af83624b2c02473f6502893a6cf70a8 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 << kListenSocket)) != 0; |
|
Mads Ager (google)
2011/10/28 08:33:23
kListeningSocket?
Søren Gjesse
2011/10/28 09:24:19
Done.
|
| +} |
| + |
| + |
| 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,26 @@ 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. |
| + 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
|
| + if ((pollfd->revents & POLLHUP) != 0) event_mask |= (1 << kCloseEvent); |
| + if ((pollfd->revents & POLLERR) != 0) event_mask |= (1 << kErrorEvent); |
| + } 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; |