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 #include "mojo/edk/embedder/platform_channel_pair.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 28 matching lines...) Expand all Loading... |
39 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. | 39 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. |
40 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); | 40 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); |
41 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); | 41 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); |
42 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); | 42 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); |
43 | 43 |
44 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
45 // This turns off |SIGPIPE| when writing to a closed socket (causing it to | 45 // This turns off |SIGPIPE| when writing to a closed socket (causing it to |
46 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with | 46 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with |
47 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. | 47 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. |
48 int no_sigpipe = 1; | 48 int no_sigpipe = 1; |
49 PCHECK( | 49 PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, |
50 setsockopt( | 50 sizeof(no_sigpipe)) == 0); |
51 fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, sizeof(no_sigpipe)) == | 51 PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, |
52 0); | 52 sizeof(no_sigpipe)) == 0); |
53 PCHECK( | |
54 setsockopt( | |
55 fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, sizeof(no_sigpipe)) == | |
56 0); | |
57 #endif // defined(OS_MACOSX) | 53 #endif // defined(OS_MACOSX) |
58 | 54 |
59 server_handle_.reset(PlatformHandle(fds[0])); | 55 server_handle_.reset(PlatformHandle(fds[0])); |
60 DCHECK(server_handle_.is_valid()); | 56 DCHECK(server_handle_.is_valid()); |
61 client_handle_.reset(PlatformHandle(fds[1])); | 57 client_handle_.reset(PlatformHandle(fds[1])); |
62 DCHECK(client_handle_.is_valid()); | 58 DCHECK(client_handle_.is_valid()); |
63 } | 59 } |
64 | 60 |
65 // static | 61 // static |
66 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( | 62 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 << kMojoPlatformChannelHandleSwitch << "=" | 102 << kMojoPlatformChannelHandleSwitch << "=" |
107 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); | 103 << command_line->GetSwitchValueASCII(kMojoPlatformChannelHandleSwitch); |
108 // (Any existing switch won't actually be removed from the command line, but | 104 // (Any existing switch won't actually be removed from the command line, but |
109 // the last one appended takes precedence.) | 105 // the last one appended takes precedence.) |
110 command_line->AppendSwitchASCII(kMojoPlatformChannelHandleSwitch, | 106 command_line->AppendSwitchASCII(kMojoPlatformChannelHandleSwitch, |
111 base::IntToString(target_fd)); | 107 base::IntToString(target_fd)); |
112 } | 108 } |
113 | 109 |
114 } // namespace embedder | 110 } // namespace embedder |
115 } // namespace mojo | 111 } // namespace mojo |
OLD | NEW |