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 <poll.h> | 8 #include <poll.h> |
9 #include <pthread.h> | 9 #include <pthread.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 #include <string.h> | 11 #include <string.h> |
12 #include <sys/time.h> | 12 #include <sys/time.h> |
13 #include <unistd.h> | 13 #include <unistd.h> |
14 | 14 |
| 15 #include "bin/dartutils.h" |
15 #include "bin/fdutils.h" | 16 #include "bin/fdutils.h" |
16 #include "bin/hashmap.h" | 17 #include "bin/hashmap.h" |
17 #include "platform/utils.h" | 18 #include "platform/utils.h" |
18 | 19 |
19 | 20 |
20 int64_t GetCurrentTimeMilliseconds() { | 21 int64_t GetCurrentTimeMilliseconds() { |
21 struct timeval tv; | 22 struct timeval tv; |
22 if (gettimeofday(&tv, NULL) < 0) { | 23 if (gettimeofday(&tv, NULL) < 0) { |
23 UNREACHABLE(); | 24 UNREACHABLE(); |
24 return 0; | 25 return 0; |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 * The fd is unregistered. It gets re-registered when the request | 305 * The fd is unregistered. It gets re-registered when the request |
305 * was handled by dart. | 306 * was handled by dart. |
306 */ | 307 */ |
307 intptr_t event_mask = GetPollEvents(&pollfds[i]); | 308 intptr_t event_mask = GetPollEvents(&pollfds[i]); |
308 if (event_mask != 0) { | 309 if (event_mask != 0) { |
309 intptr_t fd = pollfds[i].fd; | 310 intptr_t fd = pollfds[i].fd; |
310 SocketData* sd = GetSocketData(fd); | 311 SocketData* sd = GetSocketData(fd); |
311 Dart_Port port = sd->port(); | 312 Dart_Port port = sd->port(); |
312 ASSERT(port != 0); | 313 ASSERT(port != 0); |
313 sd->Unregister(); | 314 sd->Unregister(); |
314 Dart_PostIntArray(port, 1, &event_mask); | 315 DartUtils::PostInteger(port, event_mask); |
315 } | 316 } |
316 } | 317 } |
317 } | 318 } |
318 HandleInterruptFd(); | 319 HandleInterruptFd(); |
319 } | 320 } |
320 | 321 |
321 | 322 |
322 intptr_t EventHandlerImplementation::GetTimeout() { | 323 intptr_t EventHandlerImplementation::GetTimeout() { |
323 if (timeout_ == kInfinityTimeout) { | 324 if (timeout_ == kInfinityTimeout) { |
324 return kInfinityTimeout; | 325 return kInfinityTimeout; |
325 } | 326 } |
326 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); | 327 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); |
327 return (millis < 0) ? 0 : millis; | 328 return (millis < 0) ? 0 : millis; |
328 } | 329 } |
329 | 330 |
330 | 331 |
331 void EventHandlerImplementation::HandleTimeout() { | 332 void EventHandlerImplementation::HandleTimeout() { |
332 if (timeout_ != kInfinityTimeout) { | 333 if (timeout_ != kInfinityTimeout) { |
333 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); | 334 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); |
334 if (millis <= 0) { | 335 if (millis <= 0) { |
335 Dart_PostIntArray(timeout_port_, 0, NULL); | 336 DartUtils::PostNull(timeout_port_); |
336 timeout_ = kInfinityTimeout; | 337 timeout_ = kInfinityTimeout; |
337 timeout_port_ = 0; | 338 timeout_port_ = 0; |
338 } | 339 } |
339 } | 340 } |
340 } | 341 } |
341 | 342 |
342 | 343 |
343 void EventHandlerImplementation::Poll(uword args) { | 344 void EventHandlerImplementation::Poll(uword args) { |
344 intptr_t pollfds_size; | 345 intptr_t pollfds_size; |
345 struct pollfd* pollfds; | 346 struct pollfd* pollfds; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { | 384 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { |
384 // The hashmap does not support keys with value 0. | 385 // The hashmap does not support keys with value 0. |
385 return reinterpret_cast<void*>(fd + 1); | 386 return reinterpret_cast<void*>(fd + 1); |
386 } | 387 } |
387 | 388 |
388 | 389 |
389 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 390 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
390 // The hashmap does not support keys with value 0. | 391 // The hashmap does not support keys with value 0. |
391 return dart::Utils::WordHash(fd + 1); | 392 return dart::Utils::WordHash(fd + 1); |
392 } | 393 } |
OLD | NEW |