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

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 30133002: Fix posix IPC channel hanging problem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make new test pass Created 7 years, 1 month 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 | « no previous file | ipc/ipc_channel_posix_unittest.cc » ('j') | ipc/ipc_channel_posix_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 << " with type " << message->type() 516 << " with type " << message->type()
516 << " (" << output_queue_.size() << " in queue)"; 517 << " (" << output_queue_.size() << " in queue)";
517 518
518 #ifdef IPC_MESSAGE_LOG_ENABLED 519 #ifdef IPC_MESSAGE_LOG_ENABLED
519 Logging::GetInstance()->OnSendMessage(message, ""); 520 Logging::GetInstance()->OnSendMessage(message, "");
520 #endif // IPC_MESSAGE_LOG_ENABLED 521 #endif // IPC_MESSAGE_LOG_ENABLED
521 522
522 message->TraceMessageBegin(); 523 message->TraceMessageBegin();
523 output_queue_.push(message); 524 output_queue_.push(message);
524 if (!is_blocked_on_write_ && !waiting_connect_) { 525 if (!is_blocked_on_write_ && !waiting_connect_) {
525 return ProcessOutgoingMessages(); 526 if (!ProcessOutgoingMessages()) {
527 ClosePipeOnError();
528 return false;
529 }
526 } 530 }
527 531
528 return true; 532 return true;
529 } 533 }
530 534
531 int Channel::ChannelImpl::GetClientFileDescriptor() { 535 int Channel::ChannelImpl::GetClientFileDescriptor() {
532 base::AutoLock lock(client_pipe_lock_); 536 base::AutoLock lock(client_pipe_lock_);
533 return client_pipe_; 537 return client_pipe_;
534 } 538 }
535 539
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 bool Channel::ChannelImpl::AcceptConnection() { 704 bool Channel::ChannelImpl::AcceptConnection() {
701 base::MessageLoopForIO::current()->WatchFileDescriptor( 705 base::MessageLoopForIO::current()->WatchFileDescriptor(
702 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this); 706 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this);
703 QueueHelloMessage(); 707 QueueHelloMessage();
704 708
705 if (mode_ & MODE_CLIENT_FLAG) { 709 if (mode_ & MODE_CLIENT_FLAG) {
706 // If we are a client we want to send a hello message out immediately. 710 // 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 711 // In server mode we will send a hello message when we receive one from a
708 // client. 712 // client.
709 waiting_connect_ = false; 713 waiting_connect_ = false;
710 return ProcessOutgoingMessages(); 714 if (!ProcessOutgoingMessages()) {
715 ClosePipeOnError();
716 return false;
717 }
718 return true;
711 } else if (mode_ & MODE_SERVER_FLAG) { 719 } else if (mode_ & MODE_SERVER_FLAG) {
712 waiting_connect_ = true; 720 waiting_connect_ = true;
713 return true; 721 return true;
714 } else { 722 } else {
715 NOTREACHED(); 723 NOTREACHED();
716 return false; 724 return false;
717 } 725 }
718 } 726 }
719 727
720 void Channel::ChannelImpl::ClosePipeOnError() { 728 void Channel::ChannelImpl::ClosePipeOnError() {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 1109
1102 1110
1103 #if defined(OS_LINUX) 1111 #if defined(OS_LINUX)
1104 // static 1112 // static
1105 void Channel::SetGlobalPid(int pid) { 1113 void Channel::SetGlobalPid(int pid) {
1106 ChannelImpl::SetGlobalPid(pid); 1114 ChannelImpl::SetGlobalPid(pid);
1107 } 1115 }
1108 #endif // OS_LINUX 1116 #endif // OS_LINUX
1109 1117
1110 } // namespace IPC 1118 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc_channel_posix_unittest.cc » ('j') | ipc/ipc_channel_posix_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698