| 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_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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 // Update the kqueue registration for SocketData structure to reflect | 59 // Update the kqueue registration for SocketData structure to reflect |
| 60 // the events currently of interest. | 60 // the events currently of interest. |
| 61 static void AddToKqueue(intptr_t kqueue_fd_, SocketData* sd) { | 61 static void AddToKqueue(intptr_t kqueue_fd_, SocketData* sd) { |
| 62 ASSERT(!sd->tracked_by_kqueue()); | 62 ASSERT(!sd->tracked_by_kqueue()); |
| 63 static const intptr_t kMaxChanges = 2; | 63 static const intptr_t kMaxChanges = 2; |
| 64 intptr_t changes = 0; | 64 intptr_t changes = 0; |
| 65 struct kevent events[kMaxChanges]; | 65 struct kevent events[kMaxChanges]; |
| 66 int flags = EV_ADD; |
| 67 if (!sd->IsListeningSocket()) { |
| 68 flags |= EV_CLEAR; |
| 69 } |
| 66 // Register or unregister READ filter if needed. | 70 // Register or unregister READ filter if needed. |
| 67 if (sd->HasReadEvent()) { | 71 if (sd->HasReadEvent()) { |
| 68 EV_SET(events + changes, | 72 EV_SET(events + changes, |
| 69 sd->fd(), | 73 sd->fd(), |
| 70 EVFILT_READ, | 74 EVFILT_READ, |
| 71 EV_ADD | EV_CLEAR, | 75 flags, |
| 72 0, | 76 0, |
| 73 0, | 77 0, |
| 74 sd); | 78 sd); |
| 75 ++changes; | 79 ++changes; |
| 76 } | 80 } |
| 77 // Register or unregister WRITE filter if needed. | 81 // Register or unregister WRITE filter if needed. |
| 78 if (sd->HasWriteEvent()) { | 82 if (sd->HasWriteEvent()) { |
| 79 EV_SET(events + changes, | 83 EV_SET(events + changes, |
| 80 sd->fd(), | 84 sd->fd(), |
| 81 EVFILT_WRITE, | 85 EVFILT_WRITE, |
| 82 EV_ADD | EV_CLEAR, | 86 flags, |
| 83 0, | 87 0, |
| 84 0, | 88 0, |
| 85 sd); | 89 sd); |
| 86 ++changes; | 90 ++changes; |
| 87 } | 91 } |
| 88 ASSERT(changes > 0); | 92 ASSERT(changes > 0); |
| 89 ASSERT(changes <= kMaxChanges); | 93 ASSERT(changes <= kMaxChanges); |
| 90 int status = | 94 int status = |
| 91 NO_RETRY_EXPECTED(kevent(kqueue_fd_, events, changes, NULL, 0, NULL)); | 95 NO_RETRY_EXPECTED(kevent(kqueue_fd_, events, changes, NULL, 0, NULL)); |
| 92 if (status == -1) { | 96 if (status == -1) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 char error_message[kBufferSize]; | 307 char error_message[kBufferSize]; |
| 304 strerror_r(events[i].data, error_message, kBufferSize); | 308 strerror_r(events[i].data, error_message, kBufferSize); |
| 305 FATAL1("kevent failed %s\n", error_message); | 309 FATAL1("kevent failed %s\n", error_message); |
| 306 } | 310 } |
| 307 if (events[i].udata == NULL) { | 311 if (events[i].udata == NULL) { |
| 308 interrupt_seen = true; | 312 interrupt_seen = true; |
| 309 } else { | 313 } else { |
| 310 SocketData* sd = reinterpret_cast<SocketData*>(events[i].udata); | 314 SocketData* sd = reinterpret_cast<SocketData*>(events[i].udata); |
| 311 intptr_t event_mask = GetEvents(events + i, sd); | 315 intptr_t event_mask = GetEvents(events + i, sd); |
| 312 if (event_mask != 0) { | 316 if (event_mask != 0) { |
| 313 if (!sd->IsListeningSocket() && sd->TakeToken()) { | 317 if (sd->TakeToken()) { |
| 314 // Took last token, remove from epoll. | 318 // Took last token, remove from epoll. |
| 315 RemoveFromKqueue(kqueue_fd_, sd); | 319 RemoveFromKqueue(kqueue_fd_, sd); |
| 316 } | 320 } |
| 317 Dart_Port port = sd->port(); | 321 Dart_Port port = sd->port(); |
| 318 ASSERT(port != 0); | 322 ASSERT(port != 0); |
| 319 DartUtils::PostInt32(port, event_mask); | 323 DartUtils::PostInt32(port, event_mask); |
| 320 } | 324 } |
| 321 } | 325 } |
| 322 } | 326 } |
| 323 if (interrupt_seen) { | 327 if (interrupt_seen) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 423 |
| 420 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 424 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 421 // The hashmap does not support keys with value 0. | 425 // The hashmap does not support keys with value 0. |
| 422 return dart::Utils::WordHash(fd + 1); | 426 return dart::Utils::WordHash(fd + 1); |
| 423 } | 427 } |
| 424 | 428 |
| 425 } // namespace bin | 429 } // namespace bin |
| 426 } // namespace dart | 430 } // namespace dart |
| 427 | 431 |
| 428 #endif // defined(TARGET_OS_MACOS) | 432 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |