| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 sd->Close(); | 249 sd->Close(); |
| 250 } | 250 } |
| 251 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 251 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 252 delete sd; | 252 delete sd; |
| 253 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); | 253 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); |
| 254 } else { | 254 } else { |
| 255 if ((msg[i].data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { | 255 if ((msg[i].data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { |
| 256 DartUtils::PostInt32(msg[i].dart_port, 1 << kCloseEvent); | 256 DartUtils::PostInt32(msg[i].dart_port, 1 << kCloseEvent); |
| 257 } else { | 257 } else { |
| 258 // Setup events to wait for. | 258 // Setup events to wait for. |
| 259 sd->SetPortAndMask(msg[i].dart_port, msg[i].data); | 259 ASSERT((msg[i].data > 0) && (msg[i].data < kIntptrMax)); |
| 260 sd->SetPortAndMask(msg[i].dart_port, |
| 261 static_cast<intptr_t>(msg[i].data)); |
| 260 UpdateKqueue(kqueue_fd_, sd); | 262 UpdateKqueue(kqueue_fd_, sd); |
| 261 } | 263 } |
| 262 } | 264 } |
| 263 } | 265 } |
| 264 } | 266 } |
| 265 } | 267 } |
| 266 | 268 |
| 267 #ifdef DEBUG_KQUEUE | 269 #ifdef DEBUG_KQUEUE |
| 268 static void PrintEventMask(intptr_t fd, struct kevent* event) { | 270 static void PrintEventMask(intptr_t fd, struct kevent* event) { |
| 269 Log::Print("%d ", static_cast<int>(fd)); | 271 Log::Print("%d ", static_cast<int>(fd)); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 ASSERT(handler_impl != NULL); | 406 ASSERT(handler_impl != NULL); |
| 405 while (!handler_impl->shutdown_) { | 407 while (!handler_impl->shutdown_) { |
| 406 int64_t millis = handler_impl->GetTimeout(); | 408 int64_t millis = handler_impl->GetTimeout(); |
| 407 ASSERT(millis == kInfinityTimeout || millis >= 0); | 409 ASSERT(millis == kInfinityTimeout || millis >= 0); |
| 408 if (millis > kMaxInt32) millis = kMaxInt32; | 410 if (millis > kMaxInt32) millis = kMaxInt32; |
| 409 // NULL pointer timespec for infinite timeout. | 411 // NULL pointer timespec for infinite timeout. |
| 410 ASSERT(kInfinityTimeout < 0); | 412 ASSERT(kInfinityTimeout < 0); |
| 411 struct timespec* timeout = NULL; | 413 struct timespec* timeout = NULL; |
| 412 struct timespec ts; | 414 struct timespec ts; |
| 413 if (millis >= 0) { | 415 if (millis >= 0) { |
| 414 ts.tv_sec = millis / 1000; | 416 int32_t millis32 = static_cast<int32_t>(millis); |
| 415 ts.tv_nsec = (millis - (ts.tv_sec * 1000)) * 1000000; | 417 int32_t secs = millis32 / 1000; |
| 418 ts.tv_sec = secs; |
| 419 ts.tv_nsec = (millis32 - (secs * 1000)) * 1000000; |
| 416 timeout = &ts; | 420 timeout = &ts; |
| 417 } | 421 } |
| 418 intptr_t result = TEMP_FAILURE_RETRY(kevent(handler_impl->kqueue_fd_, | 422 intptr_t result = TEMP_FAILURE_RETRY(kevent(handler_impl->kqueue_fd_, |
| 419 NULL, | 423 NULL, |
| 420 0, | 424 0, |
| 421 events, | 425 events, |
| 422 kMaxEvents, | 426 kMaxEvents, |
| 423 timeout)); | 427 timeout)); |
| 424 if (result == -1) { | 428 if (result == -1) { |
| 425 const int kBufferSize = 1024; | 429 const int kBufferSize = 1024; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 469 |
| 466 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 470 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 467 // The hashmap does not support keys with value 0. | 471 // The hashmap does not support keys with value 0. |
| 468 return dart::Utils::WordHash(fd + 1); | 472 return dart::Utils::WordHash(fd + 1); |
| 469 } | 473 } |
| 470 | 474 |
| 471 } // namespace bin | 475 } // namespace bin |
| 472 } // namespace dart | 476 } // namespace dart |
| 473 | 477 |
| 474 #endif // defined(TARGET_OS_MACOS) | 478 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |