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 #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 13 matching lines...) Expand all Loading... |
24 #include "base/file_util.h" | 24 #include "base/file_util.h" |
25 #include "base/files/file_path.h" | 25 #include "base/files/file_path.h" |
26 #include "base/location.h" | 26 #include "base/location.h" |
27 #include "base/logging.h" | 27 #include "base/logging.h" |
28 #include "base/memory/scoped_ptr.h" | 28 #include "base/memory/scoped_ptr.h" |
29 #include "base/memory/singleton.h" | 29 #include "base/memory/singleton.h" |
30 #include "base/posix/eintr_wrapper.h" | 30 #include "base/posix/eintr_wrapper.h" |
31 #include "base/posix/global_descriptors.h" | 31 #include "base/posix/global_descriptors.h" |
32 #include "base/process/process_handle.h" | 32 #include "base/process/process_handle.h" |
33 #include "base/rand_util.h" | 33 #include "base/rand_util.h" |
34 #include "base/run_loop.h" | |
35 #include "base/stl_util.h" | 34 #include "base/stl_util.h" |
36 #include "base/strings/string_util.h" | 35 #include "base/strings/string_util.h" |
37 #include "base/synchronization/lock.h" | 36 #include "base/synchronization/lock.h" |
38 #include "ipc/file_descriptor_set_posix.h" | 37 #include "ipc/file_descriptor_set_posix.h" |
39 #include "ipc/ipc_descriptors.h" | 38 #include "ipc/ipc_descriptors.h" |
40 #include "ipc/ipc_listener.h" | 39 #include "ipc/ipc_listener.h" |
41 #include "ipc/ipc_logging.h" | 40 #include "ipc/ipc_logging.h" |
42 #include "ipc/ipc_message_utils.h" | 41 #include "ipc/ipc_message_utils.h" |
43 #include "ipc/ipc_switches.h" | 42 #include "ipc/ipc_switches.h" |
44 #include "ipc/unix_domain_socket_util.h" | 43 #include "ipc/unix_domain_socket_util.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 server_listen_pipe_ = local_pipe; | 320 server_listen_pipe_ = local_pipe; |
322 local_pipe = -1; | 321 local_pipe = -1; |
323 } | 322 } |
324 | 323 |
325 pipe_ = local_pipe; | 324 pipe_ = local_pipe; |
326 return true; | 325 return true; |
327 } | 326 } |
328 | 327 |
329 bool Channel::ChannelImpl::Connect() { | 328 bool Channel::ChannelImpl::Connect() { |
330 if (server_listen_pipe_ == -1 && pipe_ == -1) { | 329 if (server_listen_pipe_ == -1 && pipe_ == -1) { |
331 DLOG(WARNING) << "Channel creation failed: " << pipe_name_; | 330 DLOG(INFO) << "Channel creation failed: " << pipe_name_; |
332 return false; | 331 return false; |
333 } | 332 } |
334 | 333 |
335 bool did_connect = true; | 334 bool did_connect = true; |
336 if (server_listen_pipe_ != -1) { | 335 if (server_listen_pipe_ != -1) { |
337 // Watch the pipe for connections, and turn any connections into | 336 // Watch the pipe for connections, and turn any connections into |
338 // active sockets. | 337 // active sockets. |
339 base::MessageLoopForIO::current()->WatchFileDescriptor( | 338 base::MessageLoopForIO::current()->WatchFileDescriptor( |
340 server_listen_pipe_, | 339 server_listen_pipe_, |
341 true, | 340 true, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 } | 508 } |
510 } | 509 } |
511 return true; | 510 return true; |
512 } | 511 } |
513 | 512 |
514 bool Channel::ChannelImpl::Send(Message* message) { | 513 bool Channel::ChannelImpl::Send(Message* message) { |
515 DVLOG(2) << "sending message @" << message << " on channel @" << this | 514 DVLOG(2) << "sending message @" << message << " on channel @" << this |
516 << " with type " << message->type() | 515 << " with type " << message->type() |
517 << " (" << output_queue_.size() << " in queue)"; | 516 << " (" << output_queue_.size() << " in queue)"; |
518 | 517 |
519 if (!waiting_connect_ && pipe_ == -1) | |
520 return false; | |
521 | |
522 #ifdef IPC_MESSAGE_LOG_ENABLED | 518 #ifdef IPC_MESSAGE_LOG_ENABLED |
523 Logging::GetInstance()->OnSendMessage(message, ""); | 519 Logging::GetInstance()->OnSendMessage(message, ""); |
524 #endif // IPC_MESSAGE_LOG_ENABLED | 520 #endif // IPC_MESSAGE_LOG_ENABLED |
525 | 521 |
526 message->TraceMessageBegin(); | 522 message->TraceMessageBegin(); |
527 output_queue_.push(message); | 523 output_queue_.push(message); |
528 if (!is_blocked_on_write_ && !waiting_connect_) { | 524 if (!is_blocked_on_write_ && !waiting_connect_) { |
529 if (!ProcessOutgoingMessages()) { | 525 return ProcessOutgoingMessages(); |
530 ClosePipeOnError(); | |
531 return false; | |
532 } | |
533 } | 526 } |
534 | 527 |
535 return true; | 528 return true; |
536 } | 529 } |
537 | 530 |
538 int Channel::ChannelImpl::GetClientFileDescriptor() { | 531 int Channel::ChannelImpl::GetClientFileDescriptor() { |
539 base::AutoLock lock(client_pipe_lock_); | 532 base::AutoLock lock(client_pipe_lock_); |
540 return client_pipe_; | 533 return client_pipe_; |
541 } | 534 } |
542 | 535 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 bool Channel::ChannelImpl::AcceptConnection() { | 700 bool Channel::ChannelImpl::AcceptConnection() { |
708 base::MessageLoopForIO::current()->WatchFileDescriptor( | 701 base::MessageLoopForIO::current()->WatchFileDescriptor( |
709 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this); | 702 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this); |
710 QueueHelloMessage(); | 703 QueueHelloMessage(); |
711 | 704 |
712 if (mode_ & MODE_CLIENT_FLAG) { | 705 if (mode_ & MODE_CLIENT_FLAG) { |
713 // If we are a client we want to send a hello message out immediately. | 706 // If we are a client we want to send a hello message out immediately. |
714 // In server mode we will send a hello message when we receive one from a | 707 // In server mode we will send a hello message when we receive one from a |
715 // client. | 708 // client. |
716 waiting_connect_ = false; | 709 waiting_connect_ = false; |
717 if (!ProcessOutgoingMessages()) { | 710 return ProcessOutgoingMessages(); |
718 ClosePipeOnError(); | |
719 return false; | |
720 } | |
721 return true; | |
722 } else if (mode_ & MODE_SERVER_FLAG) { | 711 } else if (mode_ & MODE_SERVER_FLAG) { |
723 waiting_connect_ = true; | 712 waiting_connect_ = true; |
724 return true; | 713 return true; |
725 } else { | 714 } else { |
726 NOTREACHED(); | 715 NOTREACHED(); |
727 return false; | 716 return false; |
728 } | 717 } |
729 } | 718 } |
730 | 719 |
731 void Channel::ChannelImpl::ClosePipeOnError() { | 720 void Channel::ChannelImpl::ClosePipeOnError() { |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 | 1101 |
1113 | 1102 |
1114 #if defined(OS_LINUX) | 1103 #if defined(OS_LINUX) |
1115 // static | 1104 // static |
1116 void Channel::SetGlobalPid(int pid) { | 1105 void Channel::SetGlobalPid(int pid) { |
1117 ChannelImpl::SetGlobalPid(pid); | 1106 ChannelImpl::SetGlobalPid(pid); |
1118 } | 1107 } |
1119 #endif // OS_LINUX | 1108 #endif // OS_LINUX |
1120 | 1109 |
1121 } // namespace IPC | 1110 } // namespace IPC |
OLD | NEW |