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

Side by Side Diff: runtime/bin/eventhandler_macos.cc

Issue 85373002: Use EV_ONESHOT in eventhandler on Mac OS. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: epoll->kqueue Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_MACOS) 6 #if defined(TARGET_OS_MACOS)
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 } 72 }
73 73
74 74
75 // Update the kqueue registration for SocketData structure to reflect 75 // Update the kqueue registration for SocketData structure to reflect
76 // the events currently of interest. 76 // the events currently of interest.
77 static void UpdateKqueue(intptr_t kqueue_fd_, SocketData* sd) { 77 static void UpdateKqueue(intptr_t kqueue_fd_, SocketData* sd) {
78 static const intptr_t kMaxChanges = 2; 78 static const intptr_t kMaxChanges = 2;
79 intptr_t changes = 0; 79 intptr_t changes = 0;
80 struct kevent events[kMaxChanges]; 80 struct kevent events[kMaxChanges];
81 // Only report events once and wait for them to be re-enabled after the
82 // event has been handled by the Dart code. This is done by using EV_ONESHOT.
81 if (sd->port() != 0) { 83 if (sd->port() != 0) {
82 // Register or unregister READ filter if needed. 84 // Register or unregister READ filter if needed.
83 if (sd->HasReadEvent()) { 85 if (sd->HasReadEvent()) {
84 if (!sd->read_tracked_by_kqueue()) { 86 if (!sd->read_tracked_by_kqueue()) {
85 EV_SET(events + changes, sd->fd(), EVFILT_READ, EV_ADD, 0, 0, sd); 87 EV_SET(events + changes,
88 sd->fd(),
89 EVFILT_READ,
90 EV_ADD | EV_ONESHOT,
91 0,
92 0,
93 sd);
86 ++changes; 94 ++changes;
87 sd->set_read_tracked_by_kqueue(true); 95 sd->set_read_tracked_by_kqueue(true);
88 } 96 }
89 } else if (sd->read_tracked_by_kqueue()) { 97 } else if (sd->read_tracked_by_kqueue()) {
90 EV_SET(events + changes, sd->fd(), EVFILT_READ, EV_DELETE, 0, 0, NULL); 98 EV_SET(events + changes, sd->fd(), EVFILT_READ, EV_DELETE, 0, 0, NULL);
91 ++changes; 99 ++changes;
92 sd->set_read_tracked_by_kqueue(false); 100 sd->set_read_tracked_by_kqueue(false);
93 } 101 }
94 // Register or unregister WRITE filter if needed. 102 // Register or unregister WRITE filter if needed.
95 if (sd->HasWriteEvent()) { 103 if (sd->HasWriteEvent()) {
96 if (!sd->write_tracked_by_kqueue()) { 104 if (!sd->write_tracked_by_kqueue()) {
97 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_ADD, 0, 0, sd); 105 EV_SET(events + changes,
106 sd->fd(),
107 EVFILT_WRITE,
108 EV_ADD | EV_ONESHOT,
109 0,
110 0,
111 sd);
98 ++changes; 112 ++changes;
99 sd->set_write_tracked_by_kqueue(true); 113 sd->set_write_tracked_by_kqueue(true);
100 } 114 }
101 } else if (sd->write_tracked_by_kqueue()) { 115 } else if (sd->write_tracked_by_kqueue()) {
102 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); 116 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
103 ++changes; 117 ++changes;
104 sd->set_write_tracked_by_kqueue(false); 118 sd->set_write_tracked_by_kqueue(false);
105 } 119 }
106 } 120 }
107 if (changes > 0) { 121 if (changes > 0) {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if ((events[i].flags & EV_ERROR) != 0) { 346 if ((events[i].flags & EV_ERROR) != 0) {
333 const int kBufferSize = 1024; 347 const int kBufferSize = 1024;
334 char error_message[kBufferSize]; 348 char error_message[kBufferSize];
335 strerror_r(events[i].data, error_message, kBufferSize); 349 strerror_r(events[i].data, error_message, kBufferSize);
336 FATAL1("kevent failed %s\n", error_message); 350 FATAL1("kevent failed %s\n", error_message);
337 } 351 }
338 if (events[i].udata == NULL) { 352 if (events[i].udata == NULL) {
339 interrupt_seen = true; 353 interrupt_seen = true;
340 } else { 354 } else {
341 SocketData* sd = reinterpret_cast<SocketData*>(events[i].udata); 355 SocketData* sd = reinterpret_cast<SocketData*>(events[i].udata);
356 sd->set_write_tracked_by_kqueue(false);
357 sd->set_read_tracked_by_kqueue(false);
342 intptr_t event_mask = GetEvents(events + i, sd); 358 intptr_t event_mask = GetEvents(events + i, sd);
343 if (event_mask != 0) { 359 if (event_mask == 0) {
344 // Unregister events for the file descriptor. Events will be 360 // Event not handled, re-add to kqueue.
345 // registered again when the current event has been handled in 361 UpdateKqueue(kqueue_fd_, sd);
346 // Dart code. 362 } else {
347 RemoveFromKqueue(kqueue_fd_, sd);
348 Dart_Port port = sd->port(); 363 Dart_Port port = sd->port();
349 ASSERT(port != 0); 364 ASSERT(port != 0);
350 DartUtils::PostInt32(port, event_mask); 365 DartUtils::PostInt32(port, event_mask);
351 } 366 }
352 } 367 }
353 } 368 }
354 if (interrupt_seen) { 369 if (interrupt_seen) {
355 // Handle after socket events, so we avoid closing a socket before we handle 370 // Handle after socket events, so we avoid closing a socket before we handle
356 // the current events. 371 // the current events.
357 HandleInterruptFd(); 372 HandleInterruptFd();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 465
451 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 466 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
452 // The hashmap does not support keys with value 0. 467 // The hashmap does not support keys with value 0.
453 return dart::Utils::WordHash(fd + 1); 468 return dart::Utils::WordHash(fd + 1);
454 } 469 }
455 470
456 } // namespace bin 471 } // namespace bin
457 } // namespace dart 472 } // namespace dart
458 473
459 #endif // defined(TARGET_OS_MACOS) 474 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698