| 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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 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/event.h> // NOLINT | 14 #include <sys/event.h> // NOLINT |
| 15 #include <unistd.h> // NOLINT | 15 #include <unistd.h> // NOLINT |
| 16 #include <fcntl.h> // NOLINT |
| 16 | 17 |
| 17 #include "bin/dartutils.h" | 18 #include "bin/dartutils.h" |
| 18 #include "bin/fdutils.h" | 19 #include "bin/fdutils.h" |
| 19 #include "bin/log.h" | 20 #include "bin/log.h" |
| 20 #include "bin/utils.h" | 21 #include "bin/utils.h" |
| 21 #include "platform/hashmap.h" | 22 #include "platform/hashmap.h" |
| 22 #include "platform/thread.h" | 23 #include "platform/thread.h" |
| 23 #include "platform/utils.h" | 24 #include "platform/utils.h" |
| 24 | 25 |
| 25 | 26 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) { | 229 } else if ((msg.data & (1 << kShutdownWriteCommand)) != 0) { |
| 229 ASSERT(msg.data == (1 << kShutdownWriteCommand)); | 230 ASSERT(msg.data == (1 << kShutdownWriteCommand)); |
| 230 // Close the socket for writing. | 231 // Close the socket for writing. |
| 231 sd->ShutdownWrite(); | 232 sd->ShutdownWrite(); |
| 232 UpdateKqueue(kqueue_fd_, sd); | 233 UpdateKqueue(kqueue_fd_, sd); |
| 233 } else if ((msg.data & (1 << kCloseCommand)) != 0) { | 234 } else if ((msg.data & (1 << kCloseCommand)) != 0) { |
| 234 ASSERT(msg.data == (1 << kCloseCommand)); | 235 ASSERT(msg.data == (1 << kCloseCommand)); |
| 235 // Close the socket and free system resources. | 236 // Close the socket and free system resources. |
| 236 RemoveFromKqueue(kqueue_fd_, sd); | 237 RemoveFromKqueue(kqueue_fd_, sd); |
| 237 intptr_t fd = sd->fd(); | 238 intptr_t fd = sd->fd(); |
| 238 sd->Close(); | 239 if (fd == STDOUT_FILENO) { |
| 240 // If stdout, redirect fd to /dev/null. |
| 241 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
| 242 ASSERT(null_fd >= 0); |
| 243 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); |
| 244 VOID_TEMP_FAILURE_RETRY(close(null_fd)); |
| 245 } else { |
| 246 sd->Close(); |
| 247 } |
| 239 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 248 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 240 delete sd; | 249 delete sd; |
| 241 } else { | 250 } else { |
| 242 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { | 251 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { |
| 243 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); | 252 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); |
| 244 } else { | 253 } else { |
| 245 // Setup events to wait for. | 254 // Setup events to wait for. |
| 246 sd->SetPortAndMask(msg.dart_port, msg.data); | 255 sd->SetPortAndMask(msg.dart_port, msg.data); |
| 247 UpdateKqueue(kqueue_fd_, sd); | 256 UpdateKqueue(kqueue_fd_, sd); |
| 248 } | 257 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 446 |
| 438 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 447 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 439 // The hashmap does not support keys with value 0. | 448 // The hashmap does not support keys with value 0. |
| 440 return dart::Utils::WordHash(fd + 1); | 449 return dart::Utils::WordHash(fd + 1); |
| 441 } | 450 } |
| 442 | 451 |
| 443 } // namespace bin | 452 } // namespace bin |
| 444 } // namespace dart | 453 } // namespace dart |
| 445 | 454 |
| 446 #endif // defined(TARGET_OS_MACOS) | 455 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |