| OLD | NEW |
| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 // Register the file descriptor for a SocketData structure with epoll | 70 // Register the file descriptor for a SocketData structure with epoll |
| 71 // if events are requested. | 71 // if events are requested. |
| 72 static void UpdateEpollInstance(intptr_t epoll_fd_, SocketData* sd) { | 72 static void UpdateEpollInstance(intptr_t epoll_fd_, SocketData* sd) { |
| 73 struct epoll_event event; | 73 struct epoll_event event; |
| 74 event.events = sd->GetPollEvents(); | 74 event.events = sd->GetPollEvents(); |
| 75 event.data.ptr = sd; | 75 event.data.ptr = sd; |
| 76 if (sd->port() != 0 && event.events != 0) { | 76 if (sd->port() != 0 && event.events != 0) { |
| 77 // Only report events once and wait for them to be re-enabled after the |
| 78 // event has been handled by the Dart code. |
| 79 event.events |= EPOLLONESHOT; |
| 77 int status = 0; | 80 int status = 0; |
| 78 if (sd->tracked_by_epoll()) { | 81 if (sd->tracked_by_epoll()) { |
| 79 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, | 82 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, |
| 80 EPOLL_CTL_MOD, | 83 EPOLL_CTL_MOD, |
| 81 sd->fd(), | 84 sd->fd(), |
| 82 &event)); | 85 &event)); |
| 83 } else { | 86 } else { |
| 84 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, | 87 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, |
| 85 EPOLL_CTL_ADD, | 88 EPOLL_CTL_ADD, |
| 86 sd->fd(), | 89 sd->fd(), |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, | 338 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, |
| 336 int size) { | 339 int size) { |
| 337 bool interrupt_seen = false; | 340 bool interrupt_seen = false; |
| 338 for (int i = 0; i < size; i++) { | 341 for (int i = 0; i < size; i++) { |
| 339 if (events[i].data.ptr == NULL) { | 342 if (events[i].data.ptr == NULL) { |
| 340 interrupt_seen = true; | 343 interrupt_seen = true; |
| 341 } else { | 344 } else { |
| 342 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr); | 345 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr); |
| 343 intptr_t event_mask = GetPollEvents(events[i].events, sd); | 346 intptr_t event_mask = GetPollEvents(events[i].events, sd); |
| 344 if (event_mask != 0) { | 347 if (event_mask != 0) { |
| 345 // Unregister events for the file descriptor. Events will be | |
| 346 // registered again when the current event has been handled in | |
| 347 // Dart code. | |
| 348 RemoveFromEpollInstance(epoll_fd_, sd); | |
| 349 Dart_Port port = sd->port(); | 348 Dart_Port port = sd->port(); |
| 350 ASSERT(port != 0); | 349 ASSERT(port != 0); |
| 351 DartUtils::PostInt32(port, event_mask); | 350 DartUtils::PostInt32(port, event_mask); |
| 352 } | 351 } |
| 353 } | 352 } |
| 354 } | 353 } |
| 355 if (interrupt_seen) { | 354 if (interrupt_seen) { |
| 356 // Handle after socket events, so we avoid closing a socket before we handle | 355 // Handle after socket events, so we avoid closing a socket before we handle |
| 357 // the current events. | 356 // the current events. |
| 358 HandleInterruptFd(); | 357 HandleInterruptFd(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if (millis > kMaxInt32) millis = kMaxInt32; | 394 if (millis > kMaxInt32) millis = kMaxInt32; |
| 396 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler_impl->epoll_fd_, | 395 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler_impl->epoll_fd_, |
| 397 events, | 396 events, |
| 398 kMaxEvents, | 397 kMaxEvents, |
| 399 millis)); | 398 millis)); |
| 400 ASSERT(EAGAIN == EWOULDBLOCK); | 399 ASSERT(EAGAIN == EWOULDBLOCK); |
| 401 if (result == -1) { | 400 if (result == -1) { |
| 402 if (errno != EWOULDBLOCK) { | 401 if (errno != EWOULDBLOCK) { |
| 403 perror("Poll failed"); | 402 perror("Poll failed"); |
| 404 } | 403 } |
| 404 } else if (result == 0) { |
| 405 handler_impl->HandleTimeout(); |
| 405 } else { | 406 } else { |
| 406 handler_impl->HandleTimeout(); | |
| 407 handler_impl->HandleEvents(events, result); | 407 handler_impl->HandleEvents(events, result); |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 delete handler; | 410 delete handler; |
| 411 } | 411 } |
| 412 | 412 |
| 413 | 413 |
| 414 void EventHandlerImplementation::Start(EventHandler* handler) { | 414 void EventHandlerImplementation::Start(EventHandler* handler) { |
| 415 int result = dart::Thread::Start(&EventHandlerImplementation::Poll, | 415 int result = dart::Thread::Start(&EventHandlerImplementation::Poll, |
| 416 reinterpret_cast<uword>(handler)); | 416 reinterpret_cast<uword>(handler)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 440 | 440 |
| 441 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 441 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 442 // The hashmap does not support keys with value 0. | 442 // The hashmap does not support keys with value 0. |
| 443 return dart::Utils::WordHash(fd + 1); | 443 return dart::Utils::WordHash(fd + 1); |
| 444 } | 444 } |
| 445 | 445 |
| 446 } // namespace bin | 446 } // namespace bin |
| 447 } // namespace dart | 447 } // namespace dart |
| 448 | 448 |
| 449 #endif // defined(TARGET_OS_LINUX) | 449 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |