| 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 "bin/eventhandler.h" | 5 #include "bin/eventhandler.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 if (sd->write_tracked_by_kqueue()) { | 56 if (sd->write_tracked_by_kqueue()) { |
| 57 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, sd); | 57 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, sd); |
| 58 ++changes; | 58 ++changes; |
| 59 sd->set_write_tracked_by_kqueue(false); | 59 sd->set_write_tracked_by_kqueue(false); |
| 60 } | 60 } |
| 61 if (changes > 0) { | 61 if (changes > 0) { |
| 62 ASSERT(changes <= kMaxChanges); | 62 ASSERT(changes <= kMaxChanges); |
| 63 int status = | 63 int status = |
| 64 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, events, changes, NULL, 0, NULL)); | 64 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, events, changes, NULL, 0, NULL)); |
| 65 if (status == -1) { | 65 if (status == -1) { |
| 66 FATAL("Failed deleting events from kqueue"); | 66 FATAL1("Failed deleting events from kqueue: %s\n", strerror(errno)); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 // Update the kqueue registration for SocketData structure to reflect | 72 // Update the kqueue registration for SocketData structure to reflect |
| 73 // the events currently of interest. | 73 // the events currently of interest. |
| 74 static void UpdateKqueue(intptr_t kqueue_fd_, SocketData* sd) { | 74 static void UpdateKqueue(intptr_t kqueue_fd_, SocketData* sd) { |
| 75 static const intptr_t kMaxChanges = 2; | 75 static const intptr_t kMaxChanges = 2; |
| 76 intptr_t changes = 0; | 76 intptr_t changes = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 99 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); | 99 EV_SET(events + changes, sd->fd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); |
| 100 ++changes; | 100 ++changes; |
| 101 sd->set_write_tracked_by_kqueue(false); | 101 sd->set_write_tracked_by_kqueue(false); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 if (changes > 0) { | 104 if (changes > 0) { |
| 105 ASSERT(changes <= kMaxChanges); | 105 ASSERT(changes <= kMaxChanges); |
| 106 int status = | 106 int status = |
| 107 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, events, changes, NULL, 0, NULL)); | 107 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, events, changes, NULL, 0, NULL)); |
| 108 if (status == -1) { | 108 if (status == -1) { |
| 109 FATAL("Failed updating kqueue"); | 109 FATAL1("Failed updating kqueue: %s\n", strerror(errno)); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 EventHandlerImplementation::EventHandlerImplementation() | 115 EventHandlerImplementation::EventHandlerImplementation() |
| 116 : socket_map_(&HashMap::SamePointerValue, 16) { | 116 : socket_map_(&HashMap::SamePointerValue, 16) { |
| 117 intptr_t result; | 117 intptr_t result; |
| 118 result = TEMP_FAILURE_RETRY(pipe(interrupt_fds_)); | 118 result = TEMP_FAILURE_RETRY(pipe(interrupt_fds_)); |
| 119 if (result != 0) { | 119 if (result != 0) { |
| 120 FATAL("Pipe creation failed"); | 120 FATAL("Pipe creation failed"); |
| 121 } | 121 } |
| 122 FDUtils::SetNonBlocking(interrupt_fds_[0]); | 122 FDUtils::SetNonBlocking(interrupt_fds_[0]); |
| 123 timeout_ = kInfinityTimeout; | 123 timeout_ = kInfinityTimeout; |
| 124 timeout_port_ = 0; | 124 timeout_port_ = 0; |
| 125 | 125 |
| 126 kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue()); | 126 kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue()); |
| 127 if (kqueue_fd_ == -1) { | 127 if (kqueue_fd_ == -1) { |
| 128 FATAL("Failed creating kqueue"); | 128 FATAL("Failed creating kqueue"); |
| 129 } | 129 } |
| 130 // Register the interrupt_fd with the kqueue. | 130 // Register the interrupt_fd with the kqueue. |
| 131 struct kevent event; | 131 struct kevent event; |
| 132 EV_SET(&event, interrupt_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL); | 132 EV_SET(&event, interrupt_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL); |
| 133 int status = TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL)); | 133 int status = TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL)); |
| 134 if (status == -1) { | 134 if (status == -1) { |
| 135 FATAL("Failed adding interrupt fd to kqueue"); | 135 FATAL1("Failed adding interrupt fd to kqueue: %s\n", strerror(errno)); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 | 139 |
| 140 EventHandlerImplementation::~EventHandlerImplementation() { | 140 EventHandlerImplementation::~EventHandlerImplementation() { |
| 141 TEMP_FAILURE_RETRY(close(interrupt_fds_[0])); | 141 TEMP_FAILURE_RETRY(close(interrupt_fds_[0])); |
| 142 TEMP_FAILURE_RETRY(close(interrupt_fds_[1])); | 142 TEMP_FAILURE_RETRY(close(interrupt_fds_[1])); |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { | 390 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { |
| 391 // The hashmap does not support keys with value 0. | 391 // The hashmap does not support keys with value 0. |
| 392 return reinterpret_cast<void*>(fd + 1); | 392 return reinterpret_cast<void*>(fd + 1); |
| 393 } | 393 } |
| 394 | 394 |
| 395 | 395 |
| 396 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 396 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 397 // The hashmap does not support keys with value 0. | 397 // The hashmap does not support keys with value 0. |
| 398 return dart::Utils::WordHash(fd + 1); | 398 return dart::Utils::WordHash(fd + 1); |
| 399 } | 399 } |
| OLD | NEW |