| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <poll.h> | 6 #include <poll.h> |
| 7 #include <pthread.h> | 7 #include <pthread.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/time.h> | 10 #include <sys/time.h> |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 void* EventHandlerImplementation::Poll(void* args) { | 342 void* EventHandlerImplementation::Poll(void* args) { |
| 343 intptr_t pollfds_size; | 343 intptr_t pollfds_size; |
| 344 struct pollfd* pollfds; | 344 struct pollfd* pollfds; |
| 345 EventHandlerImplementation* handler = | 345 EventHandlerImplementation* handler = |
| 346 reinterpret_cast<EventHandlerImplementation*>(args); | 346 reinterpret_cast<EventHandlerImplementation*>(args); |
| 347 while (1) { | 347 while (1) { |
| 348 pollfds = handler->GetPollFds(&pollfds_size); | 348 pollfds = handler->GetPollFds(&pollfds_size); |
| 349 intptr_t millis = handler->GetTimeout(); | 349 intptr_t millis = handler->GetTimeout(); |
| 350 intptr_t result = poll(pollfds, pollfds_size, millis); | 350 intptr_t result = poll(pollfds, pollfds_size, millis); |
| 351 if (result == -1) { | 351 if (result == -1) { |
| 352 perror("Poll failed"); | 352 if (errno != EAGAIN && errno != EINTR) { |
| 353 perror("Poll failed"); |
| 354 } |
| 353 } else { | 355 } else { |
| 354 handler->HandleTimeout(); | 356 handler->HandleTimeout(); |
| 355 handler->HandleEvents(pollfds, pollfds_size, result); | 357 handler->HandleEvents(pollfds, pollfds_size, result); |
| 356 } | 358 } |
| 357 free(pollfds); | 359 free(pollfds); |
| 358 } | 360 } |
| 359 return NULL; | 361 return NULL; |
| 360 } | 362 } |
| 361 | 363 |
| 362 | 364 |
| 363 void EventHandlerImplementation::StartEventHandler() { | 365 void EventHandlerImplementation::StartEventHandler() { |
| 364 pthread_t handler_thread; | 366 pthread_t handler_thread; |
| 365 int result = pthread_create(&handler_thread, | 367 int result = pthread_create(&handler_thread, |
| 366 NULL, | 368 NULL, |
| 367 &EventHandlerImplementation::Poll, | 369 &EventHandlerImplementation::Poll, |
| 368 this); | 370 this); |
| 369 if (result != 0) { | 371 if (result != 0) { |
| 370 FATAL("Create start event handler thread"); | 372 FATAL("Create start event handler thread"); |
| 371 } | 373 } |
| 372 } | 374 } |
| 373 | 375 |
| 374 | 376 |
| 375 void EventHandlerImplementation::SendData(intptr_t id, | 377 void EventHandlerImplementation::SendData(intptr_t id, |
| 376 Dart_Port dart_port, | 378 Dart_Port dart_port, |
| 377 intptr_t data) { | 379 intptr_t data) { |
| 378 WakeupHandler(id, dart_port, data); | 380 WakeupHandler(id, dart_port, data); |
| 379 } | 381 } |
| OLD | NEW |