| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 DartUtils::PostInt32(port, event_mask); | 348 DartUtils::PostInt32(port, event_mask); |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 // Handle after socket events, so we avoid closing a socket before we handle | 352 // Handle after socket events, so we avoid closing a socket before we handle |
| 353 // the current events. | 353 // the current events. |
| 354 HandleInterruptFd(); | 354 HandleInterruptFd(); |
| 355 } | 355 } |
| 356 | 356 |
| 357 | 357 |
| 358 intptr_t EventHandlerImplementation::GetTimeout() { | 358 int64_t EventHandlerImplementation::GetTimeout() { |
| 359 if (timeout_ == kInfinityTimeout) { | 359 if (timeout_ == kInfinityTimeout) { |
| 360 return kInfinityTimeout; | 360 return kInfinityTimeout; |
| 361 } | 361 } |
| 362 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); | 362 int64_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
| 363 return (millis < 0) ? 0 : millis; | 363 return (millis < 0) ? 0 : millis; |
| 364 } | 364 } |
| 365 | 365 |
| 366 | 366 |
| 367 void EventHandlerImplementation::HandleTimeout() { | 367 void EventHandlerImplementation::HandleTimeout() { |
| 368 if (timeout_ != kInfinityTimeout) { | 368 if (timeout_ != kInfinityTimeout) { |
| 369 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); | 369 int64_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
| 370 if (millis <= 0) { | 370 if (millis <= 0) { |
| 371 DartUtils::PostNull(timeout_port_); | 371 DartUtils::PostNull(timeout_port_); |
| 372 timeout_ = kInfinityTimeout; | 372 timeout_ = kInfinityTimeout; |
| 373 timeout_port_ = 0; | 373 timeout_port_ = 0; |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 | 377 |
| 378 | 378 |
| 379 void EventHandlerImplementation::Poll(uword args) { | 379 void EventHandlerImplementation::Poll(uword args) { |
| 380 static const intptr_t kMaxEvents = 16; | 380 static const intptr_t kMaxEvents = 16; |
| 381 struct epoll_event events[kMaxEvents]; | 381 struct epoll_event events[kMaxEvents]; |
| 382 EventHandler* handler = reinterpret_cast<EventHandler*>(args); | 382 EventHandler* handler = reinterpret_cast<EventHandler*>(args); |
| 383 EventHandlerImplementation* handler_impl = &handler->delegate_; | 383 EventHandlerImplementation* handler_impl = &handler->delegate_; |
| 384 ASSERT(handler_impl != NULL); | 384 ASSERT(handler_impl != NULL); |
| 385 while (!handler_impl->shutdown_) { | 385 while (!handler_impl->shutdown_) { |
| 386 intptr_t millis = handler_impl->GetTimeout(); | 386 int64_t millis = handler_impl->GetTimeout(); |
| 387 ASSERT(millis == kInfinityTimeout || millis >= 0); |
| 388 if (millis > kMaxInt32) millis = kMaxInt32; |
| 387 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler_impl->epoll_fd_, | 389 intptr_t result = TEMP_FAILURE_RETRY(epoll_wait(handler_impl->epoll_fd_, |
| 388 events, | 390 events, |
| 389 kMaxEvents, | 391 kMaxEvents, |
| 390 millis)); | 392 millis)); |
| 391 ASSERT(EAGAIN == EWOULDBLOCK); | 393 ASSERT(EAGAIN == EWOULDBLOCK); |
| 392 if (result == -1) { | 394 if (result == -1) { |
| 393 if (errno != EWOULDBLOCK) { | 395 if (errno != EWOULDBLOCK) { |
| 394 perror("Poll failed"); | 396 perror("Poll failed"); |
| 395 } | 397 } |
| 396 } else { | 398 } else { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 433 |
| 432 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 434 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 433 // The hashmap does not support keys with value 0. | 435 // The hashmap does not support keys with value 0. |
| 434 return dart::Utils::WordHash(fd + 1); | 436 return dart::Utils::WordHash(fd + 1); |
| 435 } | 437 } |
| 436 | 438 |
| 437 } // namespace bin | 439 } // namespace bin |
| 438 } // namespace dart | 440 } // namespace dart |
| 439 | 441 |
| 440 #endif // defined(TARGET_OS_LINUX) | 442 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |