Chromium Code Reviews| Index: dart/runtime/bin/eventhandler_android.cc |
| diff --git a/dart/runtime/bin/eventhandler_android.cc b/dart/runtime/bin/eventhandler_android.cc |
| index 680bcae7b99bf6cf8125ca688efb1f63b772c78c..a9ca040a63b2ce1a495f4a83856a7cf1bb8d3c78 100644 |
| --- a/dart/runtime/bin/eventhandler_android.cc |
| +++ b/dart/runtime/bin/eventhandler_android.cc |
| @@ -6,6 +6,7 @@ |
| #if defined(TARGET_OS_ANDROID) |
| #include "bin/eventhandler.h" |
| +#include "bin/eventhandler_android.h" |
| #include <errno.h> // NOLINT |
| #include <pthread.h> // NOLINT |
| @@ -100,7 +101,7 @@ EventHandlerImplementation::EventHandlerImplementation() |
| static const int kEpollInitialSize = 64; |
| epoll_fd_ = NO_RETRY_EXPECTED(epoll_create(kEpollInitialSize)); |
| if (epoll_fd_ == -1) { |
| - FATAL("Failed creating epoll file descriptor"); |
| + FATAL1("Failed creating epoll file descriptor: %i", errno); |
| } |
| FDUtils::SetCloseOnExec(epoll_fd_); |
| // Register the interrupt_fd with the epoll instance. |
| @@ -108,9 +109,9 @@ EventHandlerImplementation::EventHandlerImplementation() |
| event.events = EPOLLIN; |
| event.data.ptr = NULL; |
| int status = NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_, |
| - EPOLL_CTL_ADD, |
| - interrupt_fds_[0], |
| - &event)); |
| + EPOLL_CTL_ADD, |
| + interrupt_fds_[0], |
| + &event)); |
| if (status == -1) { |
| FATAL("Failed adding interrupt fd to epoll instance"); |
| } |
| @@ -118,6 +119,7 @@ EventHandlerImplementation::EventHandlerImplementation() |
| EventHandlerImplementation::~EventHandlerImplementation() { |
| + VOID_TEMP_FAILURE_RETRY(close(epoll_fd_)); |
| VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[0])); |
| VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[1])); |
| } |
| @@ -157,7 +159,7 @@ void EventHandlerImplementation::WakeupHandler(intptr_t id, |
| if (result == -1) { |
| perror("Interrupt message failure:"); |
| } |
| - FATAL1("Interrupt message failure. Wrote %d bytes.", result); |
| + FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result); |
| } |
| } |
| @@ -177,10 +179,10 @@ void EventHandlerImplementation::HandleInterruptFd() { |
| if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { |
| // Close the socket for reading. |
| - shutdown(sd->fd(), SHUT_RD); |
| + VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_RD)); |
| } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { |
| // Close the socket for writing. |
| - shutdown(sd->fd(), SHUT_WR); |
| + VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_WR)); |
| } else if (IS_COMMAND(msg[i].data, kCloseCommand)) { |
| // Close the socket and free system resources and move on to |
| // next message. |
| @@ -299,15 +301,15 @@ void EventHandlerImplementation::Poll(uword args) { |
| ThreadSignalBlocker signal_blocker(SIGPROF); |
| static const intptr_t kMaxEvents = 16; |
| struct epoll_event events[kMaxEvents]; |
| - EventHandlerImplementation* handler = |
| - reinterpret_cast<EventHandlerImplementation*>(args); |
|
kustermann
2015/01/29 11:22:33
This was a pretty risky cast. It just happens by a
|
| - ASSERT(handler != NULL); |
| - while (!handler->shutdown_) { |
| + EventHandler* handler = reinterpret_cast<EventHandler*>(args); |
| + EventHandlerImplementation* handler_impl = &handler->delegate_; |
| + ASSERT(handler_impl != NULL); |
| + while (!handler_impl->shutdown_) { |
| int64_t millis = handler->GetTimeout(); |
| ASSERT(millis == kInfinityTimeout || millis >= 0); |
| if (millis > kMaxInt32) millis = kMaxInt32; |
| intptr_t result = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER( |
| - epoll_wait(handler->epoll_fd_, events, kMaxEvents, millis)); |
| + epoll_wait(handler_impl->epoll_fd_, events, kMaxEvents, millis)); |
| ASSERT(EAGAIN == EWOULDBLOCK); |
| if (result == -1) { |
| if (errno != EWOULDBLOCK) { |
| @@ -318,6 +320,7 @@ void EventHandlerImplementation::Poll(uword args) { |
| handler->HandleEvents(events, result); |
| } |
| } |
| + delete handler; |
| } |
| @@ -337,7 +340,7 @@ void EventHandlerImplementation::Shutdown() { |
| void EventHandlerImplementation::SendData(intptr_t id, |
| Dart_Port dart_port, |
| - intptr_t data) { |
| + int64_t data) { |
| WakeupHandler(id, dart_port, data); |
| } |