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

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 4202004: Add named testing interface (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_channel.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/types.h> 10 #include <sys/types.h>
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 266 }
267 267
268 } // namespace 268 } // namespace
269 //------------------------------------------------------------------------------ 269 //------------------------------------------------------------------------------
270 270
271 Channel::ChannelImpl::ChannelImpl(const std::string& channel_id, Mode mode, 271 Channel::ChannelImpl::ChannelImpl(const std::string& channel_id, Mode mode,
272 Listener* listener) 272 Listener* listener)
273 : mode_(mode), 273 : mode_(mode),
274 is_blocked_on_write_(false), 274 is_blocked_on_write_(false),
275 message_send_bytes_written_(0), 275 message_send_bytes_written_(0),
276 uses_fifo_(CommandLine::ForCurrentProcess()->HasSwitch( 276 uses_fifo_(
277 switches::kIPCUseFIFO)), 277 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIPCUseFIFO) ||
278 mode == MODE_NAMED_SERVER || mode == MODE_NAMED_CLIENT),
278 server_listen_pipe_(-1), 279 server_listen_pipe_(-1),
279 pipe_(-1), 280 pipe_(-1),
280 client_pipe_(-1), 281 client_pipe_(-1),
281 #if !defined(OS_MACOSX) 282 #if !defined(OS_MACOSX)
282 fd_pipe_(-1), 283 fd_pipe_(-1),
283 remote_fd_pipe_(-1), 284 remote_fd_pipe_(-1),
284 #endif 285 #endif
285 listener_(listener), 286 listener_(listener),
286 waiting_connect_(true), 287 waiting_connect_(true),
287 factory_(this) { 288 factory_(this) {
288 if (!CreatePipe(channel_id, mode)) { 289 if (mode_ == MODE_NAMED_SERVER)
290 mode_ = MODE_SERVER;
291 if (mode_ == MODE_NAMED_CLIENT)
292 mode_ = MODE_CLIENT;
293
294 if (!CreatePipe(channel_id, mode_)) {
289 // The pipe may have been closed already. 295 // The pipe may have been closed already.
290 PLOG(WARNING) << "Unable to create pipe named \"" << channel_id 296 PLOG(WARNING) << "Unable to create pipe named \"" << channel_id
291 << "\" in " << (mode == MODE_SERVER ? "server" : "client") 297 << "\" in " << (mode_ == MODE_SERVER ? "server" : "client")
292 << " mode"; 298 << " mode";
293 } 299 }
294 } 300 }
295 301
296 Channel::ChannelImpl::~ChannelImpl() { 302 Channel::ChannelImpl::~ChannelImpl() {
297 Close(); 303 Close();
298 } 304 }
299 305
300 // static 306 // static
301 void AddChannelSocket(const std::string& name, int socket) { 307 void AddChannelSocket(const std::string& name, int socket) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 345
340 bool Channel::ChannelImpl::CreatePipe(const std::string& channel_id, 346 bool Channel::ChannelImpl::CreatePipe(const std::string& channel_id,
341 Mode mode) { 347 Mode mode) {
342 DCHECK(server_listen_pipe_ == -1 && pipe_ == -1); 348 DCHECK(server_listen_pipe_ == -1 && pipe_ == -1);
343 349
344 if (uses_fifo_) { 350 if (uses_fifo_) {
345 // This only happens in unit tests; see the comment above PipeMap. 351 // This only happens in unit tests; see the comment above PipeMap.
346 // TODO(playmobil): We shouldn't need to create fifos on disk. 352 // TODO(playmobil): We shouldn't need to create fifos on disk.
347 // TODO(playmobil): If we do, they should be in the user data directory. 353 // TODO(playmobil): If we do, they should be in the user data directory.
348 // TODO(playmobil): Cleanup any stale fifos. 354 // TODO(playmobil): Cleanup any stale fifos.
349 pipe_name_ = "/var/tmp/chrome_" + channel_id; 355 pipe_name_ = channel_id;
350 if (mode == MODE_SERVER) { 356 if (mode == MODE_SERVER) {
351 if (!CreateServerFifo(pipe_name_, &server_listen_pipe_)) { 357 if (!CreateServerFifo(pipe_name_, &server_listen_pipe_)) {
352 return false; 358 return false;
353 } 359 }
354 } else { 360 } else {
355 if (!ClientConnectToFifo(pipe_name_, &pipe_)) { 361 if (!ClientConnectToFifo(pipe_name_, &pipe_)) {
356 return false; 362 return false;
357 } 363 }
358 waiting_connect_ = false; 364 waiting_connect_ = false;
359 } 365 }
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 1082
1077 bool Channel::Send(Message* message) { 1083 bool Channel::Send(Message* message) {
1078 return channel_impl_->Send(message); 1084 return channel_impl_->Send(message);
1079 } 1085 }
1080 1086
1081 int Channel::GetClientFileDescriptor() const { 1087 int Channel::GetClientFileDescriptor() const {
1082 return channel_impl_->GetClientFileDescriptor(); 1088 return channel_impl_->GetClientFileDescriptor();
1083 } 1089 }
1084 1090
1085 } // namespace IPC 1091 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698