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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 ASSERT(msg[i].data == (1 << kShutdownWriteCommand)); | 228 ASSERT(msg[i].data == (1 << kShutdownWriteCommand)); |
229 // Close the socket for writing. | 229 // Close the socket for writing. |
230 sd->ShutdownWrite(); | 230 sd->ShutdownWrite(); |
231 UpdateEpollInstance(epoll_fd_, sd); | 231 UpdateEpollInstance(epoll_fd_, sd); |
232 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { | 232 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { |
233 ASSERT(msg[i].data == (1 << kCloseCommand)); | 233 ASSERT(msg[i].data == (1 << kCloseCommand)); |
234 // Close the socket and free system resources and move on to | 234 // Close the socket and free system resources and move on to |
235 // next message. | 235 // next message. |
236 RemoveFromEpollInstance(epoll_fd_, sd); | 236 RemoveFromEpollInstance(epoll_fd_, sd); |
237 intptr_t fd = sd->fd(); | 237 intptr_t fd = sd->fd(); |
238 if (fd == STDOUT_FILENO) { | 238 sd->Close(); |
239 // If stdout, redirect fd to /dev/null. | |
240 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); | |
241 ASSERT(null_fd >= 0); | |
242 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); | |
243 VOID_TEMP_FAILURE_RETRY(close(null_fd)); | |
244 } else { | |
245 sd->Close(); | |
246 } | |
247 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 239 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
248 delete sd; | 240 delete sd; |
249 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); | 241 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); |
250 } else { | 242 } else { |
251 if ((msg[i].data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { | 243 if ((msg[i].data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { |
252 DartUtils::PostInt32(msg[i].dart_port, 1 << kCloseEvent); | 244 DartUtils::PostInt32(msg[i].dart_port, 1 << kCloseEvent); |
253 } else { | 245 } else { |
254 // Setup events to wait for. | 246 // Setup events to wait for. |
255 sd->SetPortAndMask(msg[i].dart_port, msg[i].data); | 247 sd->SetPortAndMask(msg[i].dart_port, msg[i].data); |
256 UpdateEpollInstance(epoll_fd_, sd); | 248 UpdateEpollInstance(epoll_fd_, sd); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 435 |
444 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 436 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
445 // The hashmap does not support keys with value 0. | 437 // The hashmap does not support keys with value 0. |
446 return dart::Utils::WordHash(fd + 1); | 438 return dart::Utils::WordHash(fd + 1); |
447 } | 439 } |
448 | 440 |
449 } // namespace bin | 441 } // namespace bin |
450 } // namespace dart | 442 } // namespace dart |
451 | 443 |
452 #endif // defined(TARGET_OS_LINUX) | 444 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |