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 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) { | 232 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) { |
233 ASSERT(msg[i].data == (1 << kShutdownWriteCommand)); | 233 ASSERT(msg[i].data == (1 << kShutdownWriteCommand)); |
234 // Close the socket for writing. | 234 // Close the socket for writing. |
235 sd->ShutdownWrite(); | 235 sd->ShutdownWrite(); |
236 UpdateKqueue(kqueue_fd_, sd); | 236 UpdateKqueue(kqueue_fd_, sd); |
237 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { | 237 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { |
238 ASSERT(msg[i].data == (1 << kCloseCommand)); | 238 ASSERT(msg[i].data == (1 << kCloseCommand)); |
239 // Close the socket and free system resources. | 239 // Close the socket and free system resources. |
240 RemoveFromKqueue(kqueue_fd_, sd); | 240 RemoveFromKqueue(kqueue_fd_, sd); |
241 intptr_t fd = sd->fd(); | 241 intptr_t fd = sd->fd(); |
242 if (fd == STDOUT_FILENO) { | 242 sd->Close(); |
243 // If stdout, redirect fd to /dev/null. | |
244 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); | |
245 ASSERT(null_fd >= 0); | |
246 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); | |
247 VOID_TEMP_FAILURE_RETRY(close(null_fd)); | |
248 } else { | |
249 sd->Close(); | |
250 } | |
251 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 243 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
252 delete sd; | 244 delete sd; |
253 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); | 245 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); |
254 } else { | 246 } else { |
255 if ((msg[i].data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { | 247 if ((msg[i].data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { |
256 DartUtils::PostInt32(msg[i].dart_port, 1 << kCloseEvent); | 248 DartUtils::PostInt32(msg[i].dart_port, 1 << kCloseEvent); |
257 } else { | 249 } else { |
258 // Setup events to wait for. | 250 // Setup events to wait for. |
259 ASSERT((msg[i].data > 0) && (msg[i].data < kIntptrMax)); | 251 ASSERT((msg[i].data > 0) && (msg[i].data < kIntptrMax)); |
260 sd->SetPortAndMask(msg[i].dart_port, | 252 sd->SetPortAndMask(msg[i].dart_port, |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 461 |
470 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 462 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
471 // The hashmap does not support keys with value 0. | 463 // The hashmap does not support keys with value 0. |
472 return dart::Utils::WordHash(fd + 1); | 464 return dart::Utils::WordHash(fd + 1); |
473 } | 465 } |
474 | 466 |
475 } // namespace bin | 467 } // namespace bin |
476 } // namespace dart | 468 } // namespace dart |
477 | 469 |
478 #endif // defined(TARGET_OS_MACOS) | 470 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |