Chromium Code Reviews| 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 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 base::ScopedFD remote_fd_pipe_; | 167 base::ScopedFD remote_fd_pipe_; |
| 168 #endif | 168 #endif |
| 169 | 169 |
| 170 // The "name" of our pipe. On Windows this is the global identifier for | 170 // The "name" of our pipe. On Windows this is the global identifier for |
| 171 // the pipe. On POSIX it's used as a key in a local map of file descriptors. | 171 // the pipe. On POSIX it's used as a key in a local map of file descriptors. |
| 172 std::string pipe_name_; | 172 std::string pipe_name_; |
| 173 | 173 |
| 174 // Messages to be sent are queued here. | 174 // Messages to be sent are queued here. |
| 175 std::queue<Message*> output_queue_; | 175 std::queue<Message*> output_queue_; |
| 176 | 176 |
| 177 // We assume a worst case: kReadBufferSize bytes of messages, where each | 177 // Worst case for file descriptors would be : kReadBufferSize bytes |
| 178 // message has no payload and a full complement of descriptors. | 178 // of messages, where each message has no payload and a full |
| 179 static const size_t kMaxReadFDs = | 179 // complement of descriptors: |
| 180 (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) * | 180 // CMSG_SPACE(sizeof(int) * |
| 181 MessageAttachmentSet::kMaxDescriptorsPerMessage; | 181 // (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) * |
| 182 | 182 // MessageAttachmentSet::kMaxDescriptorsPerMessage) |
| 183 // Buffer size for file descriptors used for recvmsg. On Mac the CMSG macros | 183 // |
| 184 // don't seem to be constant so we have to pick a "large enough" value. | 184 // If we allocate memory for that in recvmsg we would waste hundreds |
| 185 #if defined(OS_MACOSX) | 185 // of KB. Instead we note that we will only send file descriptors |
|
Mark Seaborn
2015/05/06 17:50:16
This assumption seems rather risky to me, because
| |
| 186 static const size_t kMaxReadFDBuffer = 1024; | 186 // occasionally and use a reasonable buffer of 8 KB. |
| 187 #else | 187 static const size_t kMaxReadFDBuffer = 8192; |
| 188 static const size_t kMaxReadFDBuffer = CMSG_SPACE(sizeof(int) * kMaxReadFDs); | |
| 189 #endif | |
| 190 | |
| 191 // Temporary buffer used to receive the file descriptors from recvmsg. | |
| 192 // Code that writes into this should immediately read them out and save | |
| 193 // them to input_fds_, since this buffer will be re-used anytime we call | |
| 194 // recvmsg. | |
| 195 char input_cmsg_buf_[kMaxReadFDBuffer]; | |
| 196 | 188 |
| 197 // File descriptors extracted from messages coming off of the channel. The | 189 // File descriptors extracted from messages coming off of the channel. The |
| 198 // handles may span messages and come off different channels from the message | 190 // handles may span messages and come off different channels from the message |
| 199 // data (in the case of READWRITE), and are processed in FIFO here. | 191 // data (in the case of READWRITE), and are processed in FIFO here. |
| 200 // NOTE: The implementation assumes underlying storage here is contiguous, so | 192 // NOTE: The implementation assumes underlying storage here is contiguous, so |
| 201 // don't change to something like std::deque<> without changing the | 193 // don't change to something like std::deque<> without changing the |
| 202 // implementation! | 194 // implementation! |
| 203 std::vector<int> input_fds_; | 195 std::vector<int> input_fds_; |
| 204 | 196 |
| 205 | 197 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 220 // If non-zero, overrides the process ID sent in the hello message. | 212 // If non-zero, overrides the process ID sent in the hello message. |
| 221 static int global_pid_; | 213 static int global_pid_; |
| 222 #endif // OS_LINUX | 214 #endif // OS_LINUX |
| 223 | 215 |
| 224 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); | 216 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); |
| 225 }; | 217 }; |
| 226 | 218 |
| 227 } // namespace IPC | 219 } // namespace IPC |
| 228 | 220 |
| 229 #endif // IPC_IPC_CHANNEL_POSIX_H_ | 221 #endif // IPC_IPC_CHANNEL_POSIX_H_ |
| OLD | NEW |