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

Unified Diff: runtime/bin/eventhandler_linux.cc

Issue 77983002: Only read from interrupt_fd when data is available. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/eventhandler_linux.cc
diff --git a/runtime/bin/eventhandler_linux.cc b/runtime/bin/eventhandler_linux.cc
index a14f12574d05e5221d04f250532d0c269e61388b..11e11d3d6f28d74511a65ccb5ad5b1b3bec11a42 100644
--- a/runtime/bin/eventhandler_linux.cc
+++ b/runtime/bin/eventhandler_linux.cc
@@ -180,30 +180,15 @@ void EventHandlerImplementation::WakeupHandler(intptr_t id,
}
-bool EventHandlerImplementation::GetInterruptMessage(InterruptMessage* msg) {
- char* dst = reinterpret_cast<char*>(msg);
- int total_read = 0;
- int bytes_read =
- TEMP_FAILURE_RETRY(read(interrupt_fds_[0], dst, kInterruptMessageSize));
- if (bytes_read < 0) {
- return false;
- }
- total_read = bytes_read;
- while (total_read < kInterruptMessageSize) {
- bytes_read = TEMP_FAILURE_RETRY(read(interrupt_fds_[0],
- dst + total_read,
- kInterruptMessageSize - total_read));
- if (bytes_read > 0) {
- total_read = total_read + bytes_read;
- }
- }
- return (total_read == kInterruptMessageSize) ? true : false;
-}
-
-
void EventHandlerImplementation::HandleInterruptFd() {
InterruptMessage msg;
- while (GetInterruptMessage(&msg)) {
+ intptr_t available = FDUtils::AvailableBytes(interrupt_fds_[0]);
+ for (int i = 0;
+ i + kInterruptMessageSize <= available;
+ i += kInterruptMessageSize) {
+ VOID_TEMP_FAILURE_RETRY(read(interrupt_fds_[0],
+ reinterpret_cast<char*>(&msg),
+ kInterruptMessageSize));
if (msg.id == kTimerId) {
timeout_queue_.UpdateTimeout(msg.dart_port, msg.data);
} else if (msg.id == kShutdownId) {
@@ -349,8 +334,11 @@ intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events,
void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
int size) {
+ bool interrupt_seen = false;
for (int i = 0; i < size; i++) {
- if (events[i].data.ptr != NULL) {
+ if (events[i].data.ptr == NULL) {
+ interrupt_seen = true;
+ } else {
SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr);
intptr_t event_mask = GetPollEvents(events[i].events, sd);
if (event_mask != 0) {
@@ -364,9 +352,11 @@ void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
}
}
}
- // Handle after socket events, so we avoid closing a socket before we handle
- // the current events.
- HandleInterruptFd();
+ if (interrupt_seen) {
+ // Handle after socket events, so we avoid closing a socket before we handle
+ // the current events.
+ HandleInterruptFd();
+ }
}

Powered by Google App Engine
This is Rietveld 408576698