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