Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 196343019: IPC: Make ipc_perftests run on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "ipc/ipc_channel_posix.h" 5 #include "ipc/ipc_channel_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 << "(fd " << i->second << ") still exists"; 128 << "(fd " << i->second << ") still exists";
129 map_[channel_id] = fd; 129 map_[channel_id] = fd;
130 } 130 }
131 131
132 private: 132 private:
133 base::Lock lock_; 133 base::Lock lock_;
134 typedef std::map<std::string, int> ChannelToFDMap; 134 typedef std::map<std::string, int> ChannelToFDMap;
135 ChannelToFDMap map_; 135 ChannelToFDMap map_;
136 136
137 friend struct DefaultSingletonTraits<PipeMap>; 137 friend struct DefaultSingletonTraits<PipeMap>;
138 friend void ::IPC::Channel::NotifyProcessForkedForTesting();
138 }; 139 };
139 140
140 //------------------------------------------------------------------------------ 141 //------------------------------------------------------------------------------
141 142
142 bool SocketWriteErrorIsRecoverable() { 143 bool SocketWriteErrorIsRecoverable() {
143 #if defined(OS_MACOSX) 144 #if defined(OS_MACOSX)
144 // On OS X if sendmsg() is trying to send fds between processes and there 145 // On OS X if sendmsg() is trying to send fds between processes and there
145 // isn't enough room in the output buffer to send the fd structure over 146 // isn't enough room in the output buffer to send the fd structure over
146 // atomically then EMSGSIZE is returned. 147 // atomically then EMSGSIZE is returned.
147 // 148 //
148 // EMSGSIZE presents a problem since the system APIs can only call us when 149 // EMSGSIZE presents a problem since the system APIs can only call us when
149 // there's room in the socket buffer and not when there is "enough" room. 150 // there's room in the socket buffer and not when there is "enough" room.
150 // 151 //
151 // The current behavior is to return to the event loop when EMSGSIZE is 152 // The current behavior is to return to the event loop when EMSGSIZE is
152 // received and hopefull service another FD. This is however still 153 // received and hopefull service another FD. This is however still
153 // technically a busy wait since the event loop will call us right back until 154 // technically a busy wait since the event loop will call us right back until
154 // the receiver has read enough data to allow passing the FD over atomically. 155 // the receiver has read enough data to allow passing the FD over atomically.
155 return errno == EAGAIN || errno == EMSGSIZE; 156 return errno == EAGAIN || errno == EMSGSIZE;
156 #else 157 #else
157 return errno == EAGAIN; 158 return errno == EAGAIN;
158 #endif // OS_MACOSX 159 #endif // OS_MACOSX
159 } 160 }
160 161
161 } // namespace 162 } // namespace
163
164 #if defined(OS_ANDROID)
165 // When we fork for simple tests on Android, we can't 'exec', so we need to
166 // reset these entries manually to get the expected testing behavior.
167 void Channel::NotifyProcessForkedForTesting() {
168 PipeMap::GetInstance()->map_.clear();
169 }
170 #endif
171
162 //------------------------------------------------------------------------------ 172 //------------------------------------------------------------------------------
163 173
164 #if defined(OS_LINUX) 174 #if defined(OS_LINUX)
165 int Channel::ChannelImpl::global_pid_ = 0; 175 int Channel::ChannelImpl::global_pid_ = 0;
166 #endif // OS_LINUX 176 #endif // OS_LINUX
167 177
168 Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle& channel_handle, 178 Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle& channel_handle,
169 Mode mode, Listener* listener) 179 Mode mode, Listener* listener)
170 : ChannelReader(listener), 180 : ChannelReader(listener),
171 mode_(mode), 181 mode_(mode),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 230 }
221 231
222 bool Channel::ChannelImpl::CreatePipe( 232 bool Channel::ChannelImpl::CreatePipe(
223 const IPC::ChannelHandle& channel_handle) { 233 const IPC::ChannelHandle& channel_handle) {
224 DCHECK(server_listen_pipe_ == -1 && pipe_ == -1); 234 DCHECK(server_listen_pipe_ == -1 && pipe_ == -1);
225 235
226 // Four possible cases: 236 // Four possible cases:
227 // 1) It's a channel wrapping a pipe that is given to us. 237 // 1) It's a channel wrapping a pipe that is given to us.
228 // 2) It's for a named channel, so we create it. 238 // 2) It's for a named channel, so we create it.
229 // 3) It's for a client that we implement ourself. This is used 239 // 3) It's for a client that we implement ourself. This is used
230 // in unittesting. 240 // in single-process unittesting.
231 // 4) It's the initial IPC channel: 241 // 4) It's the initial IPC channel:
232 // 4a) Client side: Pull the pipe out of the GlobalDescriptors set. 242 // 4a) Client side: Pull the pipe out of the GlobalDescriptors set.
233 // 4b) Server side: create the pipe. 243 // 4b) Server side: create the pipe.
234 244
235 int local_pipe = -1; 245 int local_pipe = -1;
236 if (channel_handle.socket.fd != -1) { 246 if (channel_handle.socket.fd != -1) {
237 // Case 1 from comment above. 247 // Case 1 from comment above.
238 local_pipe = channel_handle.socket.fd; 248 local_pipe = channel_handle.socket.fd;
239 #if defined(IPC_USES_READWRITE) 249 #if defined(IPC_USES_READWRITE)
240 // Test the socket passed into us to make sure it is nonblocking. 250 // Test the socket passed into us to make sure it is nonblocking.
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 1115
1106 1116
1107 #if defined(OS_LINUX) 1117 #if defined(OS_LINUX)
1108 // static 1118 // static
1109 void Channel::SetGlobalPid(int pid) { 1119 void Channel::SetGlobalPid(int pid) {
1110 ChannelImpl::SetGlobalPid(pid); 1120 ChannelImpl::SetGlobalPid(pid);
1111 } 1121 }
1112 #endif // OS_LINUX 1122 #endif // OS_LINUX
1113 1123
1114 } // namespace IPC 1124 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698