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