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

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 14383024: ipc: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months 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
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 bool Channel::ChannelImpl::Connect() { 328 bool Channel::ChannelImpl::Connect() {
329 if (server_listen_pipe_ == -1 && pipe_ == -1) { 329 if (server_listen_pipe_ == -1 && pipe_ == -1) {
330 DLOG(INFO) << "Channel creation failed: " << pipe_name_; 330 DLOG(INFO) << "Channel creation failed: " << pipe_name_;
331 return false; 331 return false;
332 } 332 }
333 333
334 bool did_connect = true; 334 bool did_connect = true;
335 if (server_listen_pipe_ != -1) { 335 if (server_listen_pipe_ != -1) {
336 // Watch the pipe for connections, and turn any connections into 336 // Watch the pipe for connections, and turn any connections into
337 // active sockets. 337 // active sockets.
338 MessageLoopForIO::current()->WatchFileDescriptor( 338 base::MessageLoopForIO::current()->WatchFileDescriptor(
339 server_listen_pipe_, 339 server_listen_pipe_,
340 true, 340 true,
341 MessageLoopForIO::WATCH_READ, 341 base::MessageLoopForIO::WATCH_READ,
342 &server_listen_connection_watcher_, 342 &server_listen_connection_watcher_,
343 this); 343 this);
344 } else { 344 } else {
345 did_connect = AcceptConnection(); 345 did_connect = AcceptConnection();
346 } 346 }
347 return did_connect; 347 return did_connect;
348 } 348 }
349 349
350 bool Channel::ChannelImpl::ProcessOutgoingMessages() { 350 bool Channel::ChannelImpl::ProcessOutgoingMessages() {
351 DCHECK(!waiting_connect_); // Why are we trying to send messages if there's 351 DCHECK(!waiting_connect_); // Why are we trying to send messages if there's
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 462 }
463 463
464 if (static_cast<size_t>(bytes_written) != amt_to_write) { 464 if (static_cast<size_t>(bytes_written) != amt_to_write) {
465 if (bytes_written > 0) { 465 if (bytes_written > 0) {
466 // If write() fails with EAGAIN then bytes_written will be -1. 466 // If write() fails with EAGAIN then bytes_written will be -1.
467 message_send_bytes_written_ += bytes_written; 467 message_send_bytes_written_ += bytes_written;
468 } 468 }
469 469
470 // Tell libevent to call us back once things are unblocked. 470 // Tell libevent to call us back once things are unblocked.
471 is_blocked_on_write_ = true; 471 is_blocked_on_write_ = true;
472 MessageLoopForIO::current()->WatchFileDescriptor( 472 base::MessageLoopForIO::current()->WatchFileDescriptor(
473 pipe_, 473 pipe_,
474 false, // One shot 474 false, // One shot
475 MessageLoopForIO::WATCH_WRITE, 475 base::MessageLoopForIO::WATCH_WRITE,
476 &write_watcher_, 476 &write_watcher_,
477 this); 477 this);
478 return true; 478 return true;
479 } else { 479 } else {
480 message_send_bytes_written_ = 0; 480 message_send_bytes_written_ = 0;
481 481
482 // Message sent OK! 482 // Message sent OK!
483 DVLOG(2) << "sent message @" << msg << " on channel @" << this 483 DVLOG(2) << "sent message @" << msg << " on channel @" << this
484 << " with type " << msg->type() << " on fd " << pipe_; 484 << " with type " << msg->type() << " on fd " << pipe_;
485 delete output_queue_.front(); 485 delete output_queue_.front();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 // Called by libevent when we can write to the pipe without blocking. 660 // Called by libevent when we can write to the pipe without blocking.
661 void Channel::ChannelImpl::OnFileCanWriteWithoutBlocking(int fd) { 661 void Channel::ChannelImpl::OnFileCanWriteWithoutBlocking(int fd) {
662 DCHECK_EQ(pipe_, fd); 662 DCHECK_EQ(pipe_, fd);
663 is_blocked_on_write_ = false; 663 is_blocked_on_write_ = false;
664 if (!ProcessOutgoingMessages()) { 664 if (!ProcessOutgoingMessages()) {
665 ClosePipeOnError(); 665 ClosePipeOnError();
666 } 666 }
667 } 667 }
668 668
669 bool Channel::ChannelImpl::AcceptConnection() { 669 bool Channel::ChannelImpl::AcceptConnection() {
670 MessageLoopForIO::current()->WatchFileDescriptor(pipe_, 670 base::MessageLoopForIO::current()->WatchFileDescriptor(
671 true, 671 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this);
672 MessageLoopForIO::WATCH_READ,
673 &read_watcher_,
674 this);
675 QueueHelloMessage(); 672 QueueHelloMessage();
676 673
677 if (mode_ & MODE_CLIENT_FLAG) { 674 if (mode_ & MODE_CLIENT_FLAG) {
678 // If we are a client we want to send a hello message out immediately. 675 // If we are a client we want to send a hello message out immediately.
679 // In server mode we will send a hello message when we receive one from a 676 // In server mode we will send a hello message when we receive one from a
680 // client. 677 // client.
681 waiting_connect_ = false; 678 waiting_connect_ = false;
682 return ProcessOutgoingMessages(); 679 return ProcessOutgoingMessages();
683 } else if (mode_ & MODE_SERVER_FLAG) { 680 } else if (mode_ & MODE_SERVER_FLAG) {
684 waiting_connect_ = true; 681 waiting_connect_ = true;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 1024
1028 1025
1029 #if defined(OS_LINUX) 1026 #if defined(OS_LINUX)
1030 // static 1027 // static
1031 void Channel::SetGlobalPid(int pid) { 1028 void Channel::SetGlobalPid(int pid) {
1032 ChannelImpl::SetGlobalPid(pid); 1029 ChannelImpl::SetGlobalPid(pid);
1033 } 1030 }
1034 #endif // OS_LINUX 1031 #endif // OS_LINUX
1035 1032
1036 } // namespace IPC 1033 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698