OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef IPC_IPC_CHANNEL_POSIX_H_ | 5 #ifndef IPC_IPC_CHANNEL_POSIX_H_ |
6 #define IPC_IPC_CHANNEL_POSIX_H_ | 6 #define IPC_IPC_CHANNEL_POSIX_H_ |
7 | 7 |
8 #include "ipc/ipc_channel.h" | 8 #include "ipc/ipc_channel.h" |
9 | 9 |
10 #include <sys/socket.h> // for CMSG macros | 10 #include <sys/socket.h> // for CMSG macros |
11 | 11 |
12 #include <queue> | 12 #include <queue> |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
| 17 #include "base/files/scoped_file.h" |
17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
18 #include "base/process/process.h" | 19 #include "base/process/process.h" |
19 #include "ipc/file_descriptor_set_posix.h" | 20 #include "ipc/file_descriptor_set_posix.h" |
20 #include "ipc/ipc_channel_reader.h" | 21 #include "ipc/ipc_channel_reader.h" |
21 | 22 |
22 #if !defined(OS_MACOSX) | 23 #if !defined(OS_MACOSX) |
23 // On Linux, the seccomp sandbox makes it very expensive to call | 24 // On Linux, the seccomp sandbox makes it very expensive to call |
24 // recvmsg() and sendmsg(). The restriction on calling read() and write(), which | 25 // recvmsg() and sendmsg(). The restriction on calling read() and write(), which |
25 // are cheap, is that we can't pass file descriptors over them. | 26 // are cheap, is that we can't pass file descriptors over them. |
26 // | 27 // |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // Indicates whether we're currently blocked waiting for a write to complete. | 147 // Indicates whether we're currently blocked waiting for a write to complete. |
147 bool is_blocked_on_write_; | 148 bool is_blocked_on_write_; |
148 bool waiting_connect_; | 149 bool waiting_connect_; |
149 | 150 |
150 // If sending a message blocks then we use this variable | 151 // If sending a message blocks then we use this variable |
151 // to keep track of where we are. | 152 // to keep track of where we are. |
152 size_t message_send_bytes_written_; | 153 size_t message_send_bytes_written_; |
153 | 154 |
154 // File descriptor we're listening on for new connections if we listen | 155 // File descriptor we're listening on for new connections if we listen |
155 // for connections. | 156 // for connections. |
156 int server_listen_pipe_; | 157 base::ScopedFD server_listen_pipe_; |
157 | 158 |
158 // The pipe used for communication. | 159 // The pipe used for communication. |
159 int pipe_; | 160 base::ScopedFD pipe_; |
160 | 161 |
161 // For a server, the client end of our socketpair() -- the other end of our | 162 // For a server, the client end of our socketpair() -- the other end of our |
162 // pipe_ that is passed to the client. | 163 // pipe_ that is passed to the client. |
163 int client_pipe_; | 164 base::ScopedFD client_pipe_; |
164 mutable base::Lock client_pipe_lock_; // Lock that protects |client_pipe_|. | 165 mutable base::Lock client_pipe_lock_; // Lock that protects |client_pipe_|. |
165 | 166 |
166 #if defined(IPC_USES_READWRITE) | 167 #if defined(IPC_USES_READWRITE) |
167 // Linux/BSD use a dedicated socketpair() for passing file descriptors. | 168 // Linux/BSD use a dedicated socketpair() for passing file descriptors. |
168 int fd_pipe_; | 169 base::ScopedFD fd_pipe_; |
169 int remote_fd_pipe_; | 170 base::ScopedFD remote_fd_pipe_; |
170 #endif | 171 #endif |
171 | 172 |
172 // The "name" of our pipe. On Windows this is the global identifier for | 173 // The "name" of our pipe. On Windows this is the global identifier for |
173 // the pipe. On POSIX it's used as a key in a local map of file descriptors. | 174 // the pipe. On POSIX it's used as a key in a local map of file descriptors. |
174 std::string pipe_name_; | 175 std::string pipe_name_; |
175 | 176 |
176 // Messages to be sent are queued here. | 177 // Messages to be sent are queued here. |
177 std::queue<Message*> output_queue_; | 178 std::queue<Message*> output_queue_; |
178 | 179 |
179 // We assume a worst case: kReadBufferSize bytes of messages, where each | 180 // We assume a worst case: kReadBufferSize bytes of messages, where each |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // If non-zero, overrides the process ID sent in the hello message. | 219 // If non-zero, overrides the process ID sent in the hello message. |
219 static int global_pid_; | 220 static int global_pid_; |
220 #endif // OS_LINUX | 221 #endif // OS_LINUX |
221 | 222 |
222 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); | 223 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); |
223 }; | 224 }; |
224 | 225 |
225 } // namespace IPC | 226 } // namespace IPC |
226 | 227 |
227 #endif // IPC_IPC_CHANNEL_POSIX_H_ | 228 #endif // IPC_IPC_CHANNEL_POSIX_H_ |
OLD | NEW |