| 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 void* EventHandlerImplementation::Poll(void* args) { | 339 void* EventHandlerImplementation::Poll(void* args) { |
| 340 intptr_t pollfds_size; | 340 intptr_t pollfds_size; |
| 341 struct pollfd* pollfds; | 341 struct pollfd* pollfds; |
| 342 EventHandlerImplementation* handler = | 342 EventHandlerImplementation* handler = |
| 343 reinterpret_cast<EventHandlerImplementation*>(args); | 343 reinterpret_cast<EventHandlerImplementation*>(args); |
| 344 while (1) { | 344 while (1) { |
| 345 pollfds = handler->GetPollFds(&pollfds_size); | 345 pollfds = handler->GetPollFds(&pollfds_size); |
| 346 intptr_t millis = handler->GetTimeout(); | 346 intptr_t millis = handler->GetTimeout(); |
| 347 intptr_t result = poll(pollfds, pollfds_size, millis); | 347 intptr_t result = poll(pollfds, pollfds_size, millis); |
| 348 if (result == -1) { | 348 if (result == -1) { |
| 349 perror("Poll failed"); | 349 if (errno != EAGAIN && errno != EINTR) { |
| 350 perror("Poll failed"); |
| 351 } |
| 350 } else { | 352 } else { |
| 351 handler->HandleTimeout(); | 353 handler->HandleTimeout(); |
| 352 handler->HandleEvents(pollfds, pollfds_size, result); | 354 handler->HandleEvents(pollfds, pollfds_size, result); |
| 353 } | 355 } |
| 354 free(pollfds); | 356 free(pollfds); |
| 355 } | 357 } |
| 356 return NULL; | 358 return NULL; |
| 357 } | 359 } |
| 358 | 360 |
| 359 | 361 |
| 360 void EventHandlerImplementation::StartEventHandler() { | 362 void EventHandlerImplementation::StartEventHandler() { |
| 361 pthread_t handler_thread; | 363 pthread_t handler_thread; |
| 362 int result = pthread_create(&handler_thread, | 364 int result = pthread_create(&handler_thread, |
| 363 NULL, | 365 NULL, |
| 364 &EventHandlerImplementation::Poll, | 366 &EventHandlerImplementation::Poll, |
| 365 this); | 367 this); |
| 366 if (result != 0) { | 368 if (result != 0) { |
| 367 FATAL("Create start event handler thread"); | 369 FATAL("Create start event handler thread"); |
| 368 } | 370 } |
| 369 } | 371 } |
| 370 | 372 |
| 371 | 373 |
| 372 void EventHandlerImplementation::SendData(intptr_t id, | 374 void EventHandlerImplementation::SendData(intptr_t id, |
| 373 Dart_Port dart_port, | 375 Dart_Port dart_port, |
| 374 intptr_t data) { | 376 intptr_t data) { |
| 375 WakeupHandler(id, dart_port, data); | 377 WakeupHandler(id, dart_port, data); |
| 376 } | 378 } |
| OLD | NEW |