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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 #ifdef IPC_MESSAGE_LOG_ENABLED | 518 #ifdef IPC_MESSAGE_LOG_ENABLED |
520 Logging::GetInstance()->OnSendMessage(message, ""); | 519 Logging::GetInstance()->OnSendMessage(message, ""); |
521 #endif // IPC_MESSAGE_LOG_ENABLED | 520 #endif // IPC_MESSAGE_LOG_ENABLED |
522 | 521 |
523 if (!waiting_connect_ && pipe_ == -1) { | |
524 delete message; | |
525 return false; | |
526 } | |
527 | |
528 message->TraceMessageBegin(); | 522 message->TraceMessageBegin(); |
529 output_queue_.push(message); | 523 output_queue_.push(message); |
530 if (!is_blocked_on_write_ && !waiting_connect_) { | 524 if (!is_blocked_on_write_ && !waiting_connect_) { |
531 if (!ProcessOutgoingMessages()) { | 525 return ProcessOutgoingMessages(); |
532 ClosePipeOnError(); | |
533 return false; | |
534 } | |
535 } | 526 } |
536 | 527 |
537 return true; | 528 return true; |
538 } | 529 } |
539 | 530 |
540 int Channel::ChannelImpl::GetClientFileDescriptor() { | 531 int Channel::ChannelImpl::GetClientFileDescriptor() { |
541 base::AutoLock lock(client_pipe_lock_); | 532 base::AutoLock lock(client_pipe_lock_); |
542 return client_pipe_; | 533 return client_pipe_; |
543 } | 534 } |
544 | 535 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 bool Channel::ChannelImpl::AcceptConnection() { | 700 bool Channel::ChannelImpl::AcceptConnection() { |
710 base::MessageLoopForIO::current()->WatchFileDescriptor( | 701 base::MessageLoopForIO::current()->WatchFileDescriptor( |
711 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this); | 702 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this); |
712 QueueHelloMessage(); | 703 QueueHelloMessage(); |
713 | 704 |
714 if (mode_ & MODE_CLIENT_FLAG) { | 705 if (mode_ & MODE_CLIENT_FLAG) { |
715 // 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. |
716 // 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 |
717 // client. | 708 // client. |
718 waiting_connect_ = false; | 709 waiting_connect_ = false; |
719 if (!ProcessOutgoingMessages()) { | 710 return ProcessOutgoingMessages(); |
720 ClosePipeOnError(); | |
721 return false; | |
722 } | |
723 return true; | |
724 } else if (mode_ & MODE_SERVER_FLAG) { | 711 } else if (mode_ & MODE_SERVER_FLAG) { |
725 waiting_connect_ = true; | 712 waiting_connect_ = true; |
726 return true; | 713 return true; |
727 } else { | 714 } else { |
728 NOTREACHED(); | 715 NOTREACHED(); |
729 return false; | 716 return false; |
730 } | 717 } |
731 } | 718 } |
732 | 719 |
733 void Channel::ChannelImpl::ClosePipeOnError() { | 720 void Channel::ChannelImpl::ClosePipeOnError() { |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 | 1101 |
1115 | 1102 |
1116 #if defined(OS_LINUX) | 1103 #if defined(OS_LINUX) |
1117 // static | 1104 // static |
1118 void Channel::SetGlobalPid(int pid) { | 1105 void Channel::SetGlobalPid(int pid) { |
1119 ChannelImpl::SetGlobalPid(pid); | 1106 ChannelImpl::SetGlobalPid(pid); |
1120 } | 1107 } |
1121 #endif // OS_LINUX | 1108 #endif // OS_LINUX |
1122 | 1109 |
1123 } // namespace IPC | 1110 } // namespace IPC |
OLD | NEW |