Chromium Code Reviews| 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "bin/eventhandler.h" | 8 #include "bin/eventhandler.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| 11 #include <pthread.h> // NOLINT | 11 #include <pthread.h> // NOLINT |
| 12 #include <stdio.h> // NOLINT | 12 #include <stdio.h> // NOLINT |
| 13 #include <string.h> // NOLINT | 13 #include <string.h> // NOLINT |
| 14 #include <sys/epoll.h> // NOLINT | 14 #include <sys/epoll.h> // NOLINT |
| 15 #include <sys/stat.h> // NOLINT | 15 #include <sys/stat.h> // NOLINT |
| 16 #include <unistd.h> // NOLINT | 16 #include <unistd.h> // NOLINT |
| 17 #include <fcntl.h> // NOLINT | |
| 17 | 18 |
| 18 #include "bin/dartutils.h" | 19 #include "bin/dartutils.h" |
| 19 #include "bin/fdutils.h" | 20 #include "bin/fdutils.h" |
| 20 #include "bin/log.h" | 21 #include "bin/log.h" |
| 21 #include "bin/utils.h" | 22 #include "bin/utils.h" |
| 22 #include "platform/hashmap.h" | 23 #include "platform/hashmap.h" |
| 23 #include "platform/thread.h" | 24 #include "platform/thread.h" |
| 24 #include "platform/utils.h" | 25 #include "platform/utils.h" |
| 25 | 26 |
| 26 | 27 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 ASSERT(msg.data == (1 << kShutdownWriteCommand)); | 209 ASSERT(msg.data == (1 << kShutdownWriteCommand)); |
| 209 // Close the socket for writing. | 210 // Close the socket for writing. |
| 210 sd->ShutdownWrite(); | 211 sd->ShutdownWrite(); |
| 211 UpdateEpollInstance(epoll_fd_, sd); | 212 UpdateEpollInstance(epoll_fd_, sd); |
| 212 } else if ((msg.data & (1 << kCloseCommand)) != 0) { | 213 } else if ((msg.data & (1 << kCloseCommand)) != 0) { |
| 213 ASSERT(msg.data == (1 << kCloseCommand)); | 214 ASSERT(msg.data == (1 << kCloseCommand)); |
| 214 // Close the socket and free system resources and move on to | 215 // Close the socket and free system resources and move on to |
| 215 // next message. | 216 // next message. |
| 216 RemoveFromEpollInstance(epoll_fd_, sd); | 217 RemoveFromEpollInstance(epoll_fd_, sd); |
| 217 intptr_t fd = sd->fd(); | 218 intptr_t fd = sd->fd(); |
| 218 sd->Close(); | 219 if (fd == STDOUT_FILENO) { |
| 220 // If stdout, redirect fd to /dev/null. | |
| 221 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); | |
| 222 ASSERT(null_fd >= 0); | |
| 223 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); | |
|
Bill Hesse
2013/06/27 16:42:36
OK, so stdout is still open at this point, so we k
| |
| 224 VOID_TEMP_FAILURE_RETRY(close(null_fd)); | |
| 225 } else { | |
| 226 sd->Close(); | |
| 227 } | |
| 219 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 228 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 220 delete sd; | 229 delete sd; |
| 221 } else { | 230 } else { |
| 222 // Setup events to wait for. | 231 // Setup events to wait for. |
| 223 sd->SetPortAndMask(msg.dart_port, msg.data); | 232 sd->SetPortAndMask(msg.dart_port, msg.data); |
| 224 UpdateEpollInstance(epoll_fd_, sd); | 233 UpdateEpollInstance(epoll_fd_, sd); |
| 225 } | 234 } |
| 226 } | 235 } |
| 227 } | 236 } |
| 228 } | 237 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 | 436 |
| 428 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 437 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 429 // The hashmap does not support keys with value 0. | 438 // The hashmap does not support keys with value 0. |
| 430 return dart::Utils::WordHash(fd + 1); | 439 return dart::Utils::WordHash(fd + 1); |
| 431 } | 440 } |
| 432 | 441 |
| 433 } // namespace bin | 442 } // namespace bin |
| 434 } // namespace dart | 443 } // namespace dart |
| 435 | 444 |
| 436 #endif // defined(TARGET_OS_ANDROID) | 445 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |