| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } else if ((msg.data & (1 << kCloseCommand)) != 0) { | 209 } else if ((msg.data & (1 << kCloseCommand)) != 0) { |
| 210 ASSERT(msg.data == (1 << kCloseCommand)); | 210 ASSERT(msg.data == (1 << kCloseCommand)); |
| 211 // Close the socket and free system resources and move on to | 211 // Close the socket and free system resources and move on to |
| 212 // next message. | 212 // next message. |
| 213 RemoveFromEpollInstance(epoll_fd_, sd); | 213 RemoveFromEpollInstance(epoll_fd_, sd); |
| 214 intptr_t fd = sd->fd(); | 214 intptr_t fd = sd->fd(); |
| 215 sd->Close(); | 215 sd->Close(); |
| 216 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 216 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 217 delete sd; | 217 delete sd; |
| 218 } else { | 218 } else { |
| 219 // Setup events to wait for. | 219 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { |
| 220 sd->SetPortAndMask(msg.dart_port, msg.data); | 220 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); |
| 221 UpdateEpollInstance(epoll_fd_, sd); | 221 } else { |
| 222 // Setup events to wait for. |
| 223 sd->SetPortAndMask(msg.dart_port, msg.data); |
| 224 UpdateEpollInstance(epoll_fd_, sd); |
| 225 } |
| 222 } | 226 } |
| 223 } | 227 } |
| 224 } | 228 } |
| 225 } | 229 } |
| 226 | 230 |
| 227 #ifdef DEBUG_POLL | 231 #ifdef DEBUG_POLL |
| 228 static void PrintEventMask(intptr_t fd, intptr_t events) { | 232 static void PrintEventMask(intptr_t fd, intptr_t events) { |
| 229 Log::Print("%d ", fd); | 233 Log::Print("%d ", fd); |
| 230 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); | 234 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); |
| 231 if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI "); | 235 if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI "); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // Unregister events for the file descriptor. Events will be | 340 // Unregister events for the file descriptor. Events will be |
| 337 // registered again when the current event has been handled in | 341 // registered again when the current event has been handled in |
| 338 // Dart code. | 342 // Dart code. |
| 339 RemoveFromEpollInstance(epoll_fd_, sd); | 343 RemoveFromEpollInstance(epoll_fd_, sd); |
| 340 Dart_Port port = sd->port(); | 344 Dart_Port port = sd->port(); |
| 341 ASSERT(port != 0); | 345 ASSERT(port != 0); |
| 342 DartUtils::PostInt32(port, event_mask); | 346 DartUtils::PostInt32(port, event_mask); |
| 343 } | 347 } |
| 344 } | 348 } |
| 345 } | 349 } |
| 350 // Handle after socket events, so we avoid closing a socket before we handle |
| 351 // the current events. |
| 346 HandleInterruptFd(); | 352 HandleInterruptFd(); |
| 347 } | 353 } |
| 348 | 354 |
| 349 | 355 |
| 350 intptr_t EventHandlerImplementation::GetTimeout() { | 356 intptr_t EventHandlerImplementation::GetTimeout() { |
| 351 if (timeout_ == kInfinityTimeout) { | 357 if (timeout_ == kInfinityTimeout) { |
| 352 return kInfinityTimeout; | 358 return kInfinityTimeout; |
| 353 } | 359 } |
| 354 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); | 360 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
| 355 return (millis < 0) ? 0 : millis; | 361 return (millis < 0) ? 0 : millis; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 return reinterpret_cast<void*>(fd + 1); | 425 return reinterpret_cast<void*>(fd + 1); |
| 420 } | 426 } |
| 421 | 427 |
| 422 | 428 |
| 423 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 429 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 424 // The hashmap does not support keys with value 0. | 430 // The hashmap does not support keys with value 0. |
| 425 return dart::Utils::WordHash(fd + 1); | 431 return dart::Utils::WordHash(fd + 1); |
| 426 } | 432 } |
| 427 | 433 |
| 428 #endif // defined(TARGET_OS_LINUX) | 434 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |