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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include <limits> | 14 #include <limits> |
15 | 15 |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/posix/global_descriptors.h" | 18 #include "base/posix/global_descriptors.h" |
19 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
Anand Mistry (off Chromium)
2016/01/28 02:26:24
You can remove since there are no other uses of ba
| |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
22 #include "mojo/edk/embedder/platform_handle.h" | 22 #include "mojo/edk/embedder/platform_handle.h" |
23 | 23 |
24 #if !defined(SO_PEEK_OFF) | 24 #if !defined(SO_PEEK_OFF) |
25 #define SO_PEEK_OFF 42 | 25 #define SO_PEEK_OFF 42 |
26 #endif | 26 #endif |
27 | 27 |
28 namespace mojo { | 28 namespace mojo { |
29 namespace edk { | 29 namespace edk { |
(...skipping 12 matching lines...) Expand all Loading... | |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 PlatformChannelPair::PlatformChannelPair(bool client_is_blocking) { | 45 PlatformChannelPair::PlatformChannelPair(bool client_is_blocking) { |
46 // Create the Unix domain socket. | 46 // Create the Unix domain socket. |
47 int fds[2]; | 47 int fds[2]; |
48 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. | 48 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. |
49 | 49 |
50 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); | 50 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); |
51 | 51 |
52 // Store a common id in the SO_PEEK_OFF option (which we don't use since we | |
53 // don't peek) as a way of determining later if two sockets are connected to | |
54 // each other. | |
55 int identifier = base::RandInt(std::numeric_limits<int32_t>::min(), | |
56 std::numeric_limits<int32_t>::max()); | |
57 setsockopt(fds[0], SOL_SOCKET, SO_PEEK_OFF, &identifier, sizeof(identifier)); | |
58 setsockopt(fds[1], SOL_SOCKET, SO_PEEK_OFF, &identifier, sizeof(identifier)); | |
59 | |
60 // Set the ends to nonblocking. | 52 // Set the ends to nonblocking. |
61 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); | 53 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); |
62 if (!client_is_blocking) | 54 if (!client_is_blocking) |
63 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); | 55 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); |
64 | 56 |
65 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
66 // This turns off |SIGPIPE| when writing to a closed socket (causing it to | 58 // This turns off |SIGPIPE| when writing to a closed socket (causing it to |
67 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with | 59 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with |
68 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. | 60 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. |
69 int no_sigpipe = 1; | 61 int no_sigpipe = 1; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 while (IsTargetDescriptorUsed(*handle_passing_info, target_fd)) | 129 while (IsTargetDescriptorUsed(*handle_passing_info, target_fd)) |
138 target_fd++; | 130 target_fd++; |
139 | 131 |
140 handle_passing_info->push_back( | 132 handle_passing_info->push_back( |
141 std::pair<int, int>(client_handle_.get().handle, target_fd)); | 133 std::pair<int, int>(client_handle_.get().handle, target_fd)); |
142 return base::IntToString(target_fd); | 134 return base::IntToString(target_fd); |
143 } | 135 } |
144 | 136 |
145 } // namespace edk | 137 } // namespace edk |
146 } // namespace mojo | 138 } // namespace mojo |
OLD | NEW |