| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 intptr_t result; | 53 intptr_t result; |
| 54 socket_map_size_ = kInitialPortMapSize; | 54 socket_map_size_ = kInitialPortMapSize; |
| 55 socket_map_ = reinterpret_cast<SocketData*>(calloc(socket_map_size_, | 55 socket_map_ = reinterpret_cast<SocketData*>(calloc(socket_map_size_, |
| 56 sizeof(SocketData))); | 56 sizeof(SocketData))); |
| 57 ASSERT(socket_map_ != NULL); | 57 ASSERT(socket_map_ != NULL); |
| 58 result = pipe(interrupt_fds_); | 58 result = pipe(interrupt_fds_); |
| 59 if (result != 0) { | 59 if (result != 0) { |
| 60 FATAL("Pipe creation failed"); | 60 FATAL("Pipe creation failed"); |
| 61 } | 61 } |
| 62 FDUtils::SetNonBlocking(interrupt_fds_[0]); | 62 FDUtils::SetNonBlocking(interrupt_fds_[0]); |
| 63 FDUtils::SetNonBlocking(interrupt_fds_[1]); | |
| 64 timeout_ = kInfinityTimeout; | 63 timeout_ = kInfinityTimeout; |
| 65 timeout_port_ = 0; | 64 timeout_port_ = 0; |
| 66 } | 65 } |
| 67 | 66 |
| 68 | 67 |
| 69 EventHandlerImplementation::~EventHandlerImplementation() { | 68 EventHandlerImplementation::~EventHandlerImplementation() { |
| 70 free(socket_map_); | 69 free(socket_map_); |
| 71 close(interrupt_fds_[0]); | 70 close(interrupt_fds_[0]); |
| 72 close(interrupt_fds_[1]); | 71 close(interrupt_fds_[1]); |
| 73 } | 72 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 99 | 98 |
| 100 | 99 |
| 101 void EventHandlerImplementation::WakeupHandler(intptr_t id, | 100 void EventHandlerImplementation::WakeupHandler(intptr_t id, |
| 102 Dart_Port dart_port, | 101 Dart_Port dart_port, |
| 103 int64_t data) { | 102 int64_t data) { |
| 104 InterruptMessage msg; | 103 InterruptMessage msg; |
| 105 msg.id = id; | 104 msg.id = id; |
| 106 msg.dart_port = dart_port; | 105 msg.dart_port = dart_port; |
| 107 msg.data = data; | 106 msg.data = data; |
| 108 intptr_t result = | 107 intptr_t result = |
| 109 write(interrupt_fds_[1], &msg, kInterruptMessageSize); | 108 FDUtils::WriteToBlocking(interrupt_fds_[1], &msg, kInterruptMessageSize); |
| 110 if (result != kInterruptMessageSize) { | 109 if (result != kInterruptMessageSize) { |
| 111 perror("Interrupt message failure"); | 110 FATAL("Interrupt message failure"); |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 | 113 |
| 115 | 114 |
| 116 struct pollfd* EventHandlerImplementation::GetPollFds(intptr_t* pollfds_size) { | 115 struct pollfd* EventHandlerImplementation::GetPollFds(intptr_t* pollfds_size) { |
| 117 struct pollfd* pollfds; | 116 struct pollfd* pollfds; |
| 118 | 117 |
| 119 // Calculate the number of file descriptors to poll on. | 118 // Calculate the number of file descriptors to poll on. |
| 120 intptr_t numPollfds = 1; | 119 intptr_t numPollfds = 1; |
| 121 for (int i = 0; i < socket_map_size_; i++) { | 120 for (int i = 0; i < socket_map_size_; i++) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 FATAL("Create start event handler thread"); | 368 FATAL("Create start event handler thread"); |
| 370 } | 369 } |
| 371 } | 370 } |
| 372 | 371 |
| 373 | 372 |
| 374 void EventHandlerImplementation::SendData(intptr_t id, | 373 void EventHandlerImplementation::SendData(intptr_t id, |
| 375 Dart_Port dart_port, | 374 Dart_Port dart_port, |
| 376 intptr_t data) { | 375 intptr_t data) { |
| 377 WakeupHandler(id, dart_port, data); | 376 WakeupHandler(id, dart_port, data); |
| 378 } | 377 } |
| OLD | NEW |