| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 if (result != kInterruptMessageSize) { | 177 if (result != kInterruptMessageSize) { |
| 178 if (result == -1) { | 178 if (result == -1) { |
| 179 perror("Interrupt message failure:"); | 179 perror("Interrupt message failure:"); |
| 180 } | 180 } |
| 181 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result); | 181 FATAL1("Interrupt message failure. Wrote %" Pd " bytes.", result); |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | 184 |
| 185 | 185 |
| 186 void EventHandlerImplementation::HandleInterruptFd() { | 186 void EventHandlerImplementation::HandleInterruptFd() { |
| 187 InterruptMessage msg; | 187 const intptr_t BUFFER_SIZE = 8 * kInterruptMessageSize; |
| 188 intptr_t available = FDUtils::AvailableBytes(interrupt_fds_[0]); | 188 char buffer[BUFFER_SIZE]; |
| 189 for (int i = 0; | 189 ssize_t bytes = TEMP_FAILURE_RETRY(read(interrupt_fds_[0], |
| 190 i + kInterruptMessageSize <= available; | 190 buffer, |
| 191 i += kInterruptMessageSize) { | 191 BUFFER_SIZE)); |
| 192 VOID_TEMP_FAILURE_RETRY(read(interrupt_fds_[0], | 192 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { |
| 193 reinterpret_cast<char*>(&msg), | 193 InterruptMessage* msg = reinterpret_cast<InterruptMessage*>( |
| 194 kInterruptMessageSize)); | 194 buffer + i * kInterruptMessageSize); |
| 195 if (msg.id == kTimerId) { | 195 if (msg->id == kTimerId) { |
| 196 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data); | 196 timeout_queue_.UpdateTimeout(msg->dart_port, msg->data); |
| 197 } else if (msg.id == kShutdownId) { | 197 } else if (msg->id == kShutdownId) { |
| 198 shutdown_ = true; | 198 shutdown_ = true; |
| 199 } else { | 199 } else { |
| 200 SocketData* sd = GetSocketData(msg.id); | 200 SocketData* sd = GetSocketData(msg->id); |
| 201 if ((msg.data & (1 << kShutdownReadCommand)) != 0) { | 201 if ((msg->data & (1 << kShutdownReadCommand)) != 0) { |
| 202 ASSERT(msg.data == (1 << kShutdownReadCommand)); | 202 ASSERT(msg->data == (1 << kShutdownReadCommand)); |
| 203 // Close the socket for reading. | 203 // Close the socket for reading. |
| 204 sd->ShutdownRead(); | 204 sd->ShutdownRead(); |
| 205 UpdateEpollInstance(epoll_fd_, sd); | 205 UpdateEpollInstance(epoll_fd_, sd); |
| 206 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) { | 206 } else if ((msg->data & (1 << kShutdownWriteCommand)) != 0) { |
| 207 ASSERT(msg.data == (1 << kShutdownWriteCommand)); | 207 ASSERT(msg->data == (1 << kShutdownWriteCommand)); |
| 208 // Close the socket for writing. | 208 // Close the socket for writing. |
| 209 sd->ShutdownWrite(); | 209 sd->ShutdownWrite(); |
| 210 UpdateEpollInstance(epoll_fd_, sd); | 210 UpdateEpollInstance(epoll_fd_, sd); |
| 211 } else if ((msg.data & (1 << kCloseCommand)) != 0) { | 211 } else if ((msg->data & (1 << kCloseCommand)) != 0) { |
| 212 ASSERT(msg.data == (1 << kCloseCommand)); | 212 ASSERT(msg->data == (1 << kCloseCommand)); |
| 213 // Close the socket and free system resources and move on to | 213 // Close the socket and free system resources and move on to |
| 214 // next message. | 214 // next message. |
| 215 RemoveFromEpollInstance(epoll_fd_, sd); | 215 RemoveFromEpollInstance(epoll_fd_, sd); |
| 216 intptr_t fd = sd->fd(); | 216 intptr_t fd = sd->fd(); |
| 217 if (fd == STDOUT_FILENO) { | 217 if (fd == STDOUT_FILENO) { |
| 218 // If stdout, redirect fd to /dev/null. | 218 // If stdout, redirect fd to /dev/null. |
| 219 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); | 219 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
| 220 ASSERT(null_fd >= 0); | 220 ASSERT(null_fd >= 0); |
| 221 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); | 221 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); |
| 222 VOID_TEMP_FAILURE_RETRY(close(null_fd)); | 222 VOID_TEMP_FAILURE_RETRY(close(null_fd)); |
| 223 } else { | 223 } else { |
| 224 sd->Close(); | 224 sd->Close(); |
| 225 } | 225 } |
| 226 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 226 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 227 delete sd; | 227 delete sd; |
| 228 DartUtils::PostInt32(msg.dart_port, 1 << kDestroyedEvent); | 228 DartUtils::PostInt32(msg->dart_port, 1 << kDestroyedEvent); |
| 229 } else { | 229 } else { |
| 230 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { | 230 if ((msg->data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { |
| 231 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); | 231 DartUtils::PostInt32(msg->dart_port, 1 << kCloseEvent); |
| 232 } else { | 232 } else { |
| 233 // Setup events to wait for. | 233 // Setup events to wait for. |
| 234 sd->SetPortAndMask(msg.dart_port, msg.data); | 234 sd->SetPortAndMask(msg->dart_port, msg->data); |
| 235 UpdateEpollInstance(epoll_fd_, sd); | 235 UpdateEpollInstance(epoll_fd_, sd); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 #ifdef DEBUG_POLL | 242 #ifdef DEBUG_POLL |
| 243 static void PrintEventMask(intptr_t fd, intptr_t events) { | 243 static void PrintEventMask(intptr_t fd, intptr_t events) { |
| 244 Log::Print("%d ", fd); | 244 Log::Print("%d ", fd); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 440 |
| 441 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 441 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 442 // The hashmap does not support keys with value 0. | 442 // The hashmap does not support keys with value 0. |
| 443 return dart::Utils::WordHash(fd + 1); | 443 return dart::Utils::WordHash(fd + 1); |
| 444 } | 444 } |
| 445 | 445 |
| 446 } // namespace bin | 446 } // namespace bin |
| 447 } // namespace dart | 447 } // namespace dart |
| 448 | 448 |
| 449 #endif // defined(TARGET_OS_LINUX) | 449 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |