| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/edk/embedder/platform_channel_pair.h" | 5 // This file implements the class declared in |
| 6 // //mojo/edk/platform/platform_pipe.h. |
| 7 |
| 8 #include "mojo/edk/platform/platform_pipe.h" |
| 6 | 9 |
| 7 #include <fcntl.h> | 10 #include <fcntl.h> |
| 8 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 9 #include <sys/types.h> | 12 #include <sys/types.h> |
| 10 #include <unistd.h> | 13 #include <unistd.h> |
| 11 | 14 |
| 12 #include "base/logging.h" | 15 #include "base/logging.h" |
| 13 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 14 #include "mojo/edk/platform/platform_handle.h" | 17 #include "mojo/edk/platform/platform_handle.h" |
| 15 | 18 |
| 16 using mojo::platform::PlatformHandle; | 19 namespace mojo { |
| 20 namespace platform { |
| 17 | 21 |
| 18 namespace mojo { | 22 PlatformPipe::PlatformPipe() { |
| 19 namespace embedder { | |
| 20 | |
| 21 PlatformChannelPair::PlatformChannelPair() { | |
| 22 // Create the Unix domain socket and set the ends to nonblocking. | 23 // Create the Unix domain socket and set the ends to nonblocking. |
| 23 int fds[2]; | 24 int fds[2]; |
| 24 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. | 25 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. |
| 25 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); | 26 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); |
| 26 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); | 27 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); |
| 27 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); | 28 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); |
| 28 | 29 |
| 29 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
| 30 // This turns off |SIGPIPE| when writing to a closed socket (causing it to | 31 // This turns off |SIGPIPE| when writing to a closed socket (causing it to |
| 31 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with | 32 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with |
| 32 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. | 33 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. |
| 33 int no_sigpipe = 1; | 34 int no_sigpipe = 1; |
| 34 PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, | 35 PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, |
| 35 sizeof(no_sigpipe)) == 0); | 36 sizeof(no_sigpipe)) == 0); |
| 36 PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, | 37 PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, |
| 37 sizeof(no_sigpipe)) == 0); | 38 sizeof(no_sigpipe)) == 0); |
| 38 #endif // defined(OS_MACOSX) | 39 #endif // defined(OS_MACOSX) |
| 39 | 40 |
| 40 handle0.reset(PlatformHandle(fds[0])); | 41 handle0.reset(PlatformHandle(fds[0])); |
| 41 DCHECK(handle0.is_valid()); | 42 DCHECK(handle0.is_valid()); |
| 42 handle1.reset(PlatformHandle(fds[1])); | 43 handle1.reset(PlatformHandle(fds[1])); |
| 43 DCHECK(handle1.is_valid()); | 44 DCHECK(handle1.is_valid()); |
| 44 } | 45 } |
| 45 | 46 |
| 46 PlatformChannelPair::~PlatformChannelPair() {} | 47 PlatformPipe::~PlatformPipe() {} |
| 47 | 48 |
| 48 } // namespace embedder | 49 } // namespace platform |
| 49 } // namespace mojo | 50 } // namespace mojo |
| OLD | NEW |