| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { | 199 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { |
| 200 ASSERT(msg[i].data == (1 << kCloseCommand)); | 200 ASSERT(msg[i].data == (1 << kCloseCommand)); |
| 201 // Close the socket and free system resources. | 201 // Close the socket and free system resources. |
| 202 RemoveFromKqueue(kqueue_fd_, sd); | 202 RemoveFromKqueue(kqueue_fd_, sd); |
| 203 intptr_t fd = sd->fd(); | 203 intptr_t fd = sd->fd(); |
| 204 sd->Close(); | 204 sd->Close(); |
| 205 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 205 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 206 delete sd; | 206 delete sd; |
| 207 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); | 207 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); |
| 208 } else if ((msg[i].data & (1 << kReturnTokenCommand)) != 0) { | 208 } else if ((msg[i].data & (1 << kReturnTokenCommand)) != 0) { |
| 209 if (sd->ReturnToken()) { | 209 int count = msg[i].data & ((1 << kReturnTokenCommand) - 1); |
| 210 AddToKqueue(kqueue_fd_, sd); | 210 for (int i = 0; i < count; i++) { |
| 211 if (sd->ReturnToken()) { |
| 212 AddToKqueue(kqueue_fd_, sd); |
| 213 } |
| 211 } | 214 } |
| 212 } else { | 215 } else { |
| 213 // Setup events to wait for. | 216 // Setup events to wait for. |
| 214 ASSERT((msg[i].data > 0) && (msg[i].data < kIntptrMax)); | 217 ASSERT((msg[i].data > 0) && (msg[i].data < kIntptrMax)); |
| 215 ASSERT(sd->port() == 0); | 218 ASSERT(sd->port() == 0); |
| 216 sd->SetPortAndMask(msg[i].dart_port, | 219 sd->SetPortAndMask(msg[i].dart_port, |
| 217 static_cast<intptr_t>(msg[i].data)); | 220 static_cast<intptr_t>(msg[i].data)); |
| 218 AddToKqueue(kqueue_fd_, sd); | 221 AddToKqueue(kqueue_fd_, sd); |
| 219 } | 222 } |
| 220 } | 223 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 const int kBufferSize = 1024; | 302 const int kBufferSize = 1024; |
| 300 char error_message[kBufferSize]; | 303 char error_message[kBufferSize]; |
| 301 strerror_r(events[i].data, error_message, kBufferSize); | 304 strerror_r(events[i].data, error_message, kBufferSize); |
| 302 FATAL1("kevent failed %s\n", error_message); | 305 FATAL1("kevent failed %s\n", error_message); |
| 303 } | 306 } |
| 304 if (events[i].udata == NULL) { | 307 if (events[i].udata == NULL) { |
| 305 interrupt_seen = true; | 308 interrupt_seen = true; |
| 306 } else { | 309 } else { |
| 307 SocketData* sd = reinterpret_cast<SocketData*>(events[i].udata); | 310 SocketData* sd = reinterpret_cast<SocketData*>(events[i].udata); |
| 308 intptr_t event_mask = GetEvents(events + i, sd); | 311 intptr_t event_mask = GetEvents(events + i, sd); |
| 309 if (event_mask != 0) { | 312 if (!sd->IsListeningSocket() && event_mask != 0) { |
| 310 if (sd->TakeToken()) { | 313 if (sd->TakeToken()) { |
| 311 // Took last token, remove from epoll. | 314 // Took last token, remove from epoll. |
| 312 RemoveFromKqueue(kqueue_fd_, sd); | 315 RemoveFromKqueue(kqueue_fd_, sd); |
| 313 } | 316 } |
| 314 Dart_Port port = sd->port(); | 317 Dart_Port port = sd->port(); |
| 315 ASSERT(port != 0); | 318 ASSERT(port != 0); |
| 316 DartUtils::PostInt32(port, event_mask); | 319 DartUtils::PostInt32(port, event_mask); |
| 317 } | 320 } |
| 318 } | 321 } |
| 319 } | 322 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 418 |
| 416 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 419 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 417 // The hashmap does not support keys with value 0. | 420 // The hashmap does not support keys with value 0. |
| 418 return dart::Utils::WordHash(fd + 1); | 421 return dart::Utils::WordHash(fd + 1); |
| 419 } | 422 } |
| 420 | 423 |
| 421 } // namespace bin | 424 } // namespace bin |
| 422 } // namespace dart | 425 } // namespace dart |
| 423 | 426 |
| 424 #endif // defined(TARGET_OS_MACOS) | 427 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |