diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 19:09:47 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 19:09:47 +0000 |
commit | eb8c76326fb39a429dc8bda38da22a86bb6802b3 (patch) | |
tree | 2155abfd972894d6ca5bfdf11a8fed37da065d4c /net/base/tcp_client_socket_libevent.cc | |
parent | b3d64d5c0d00415968935942b00d37704cd7507c (diff) | |
download | chromium_src-eb8c76326fb39a429dc8bda38da22a86bb6802b3.zip chromium_src-eb8c76326fb39a429dc8bda38da22a86bb6802b3.tar.gz chromium_src-eb8c76326fb39a429dc8bda38da22a86bb6802b3.tar.bz2 |
message_pump_libevent refactor:
* Unify WatchSocket & WatchFileHandle.
* Better encapsulate libevent.
* Fix a bug with blocking writes in ipc_posix.cc
Review URL: http://codereview.chromium.org/13757
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6911 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/tcp_client_socket_libevent.cc')
-rw-r--r-- | net/base/tcp_client_socket_libevent.cc | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/net/base/tcp_client_socket_libevent.cc b/net/base/tcp_client_socket_libevent.cc index 79909c20..933e95b 100644 --- a/net/base/tcp_client_socket_libevent.cc +++ b/net/base/tcp_client_socket_libevent.cc @@ -68,7 +68,6 @@ TCPClientSocket::TCPClientSocket(const AddressList& addresses) addresses_(addresses), current_ai_(addresses_.head()), waiting_connect_(false), - event_(new event), write_callback_(NULL), callback_(NULL) { } @@ -110,8 +109,8 @@ int TCPClientSocket::Connect(CompletionCallback* callback) { // POLLOUT is set if the connection is established. // POLLIN is set if the connection fails, // so select for both read and write. - MessageLoopForIO::current()->WatchSocket( - socket_, EV_READ|EV_WRITE|EV_PERSIST, event_.get(), this); + MessageLoopForIO::current()->WatchFileDescriptor( + socket_, true, MessageLoopForIO::WATCH_READ_WRITE, &socket_watcher_, this); waiting_connect_ = true; callback_ = callback; @@ -127,7 +126,7 @@ void TCPClientSocket::Disconnect() { if (socket_ == kInvalidSocket) return; - MessageLoopForIO::current()->UnwatchSocket(event_.get()); + socket_watcher_.StopWatchingFileDescriptor(); close(socket_); socket_ = kInvalidSocket; waiting_connect_ = false; @@ -170,8 +169,8 @@ int TCPClientSocket::Read(char* buf, return MapPosixError(errno); } - MessageLoopForIO::current()->WatchSocket( - socket_, EV_READ|EV_PERSIST, event_.get(), this); + MessageLoopForIO::current()->WatchFileDescriptor( + socket_, true, MessageLoopForIO::WATCH_READ, &socket_watcher_, this); buf_ = buf; buf_len_ = buf_len; @@ -196,8 +195,9 @@ int TCPClientSocket::Write(const char* buf, if (errno != EAGAIN && errno != EWOULDBLOCK) return MapPosixError(errno); - MessageLoopForIO::current()->WatchSocket( - socket_, EV_WRITE|EV_PERSIST, event_.get(), this); + MessageLoopForIO::current()->WatchFileDescriptor( + socket_, true, MessageLoopForIO::WATCH_WRITE, &socket_watcher_, this); + write_buf_ = buf; write_buf_len_ = buf_len; @@ -263,7 +263,7 @@ void TCPClientSocket::DidCompleteConnect() { result = Connect(callback_); } else { result = MapPosixError(error_code); - MessageLoopForIO::current()->UnwatchSocket(event_.get()); + socket_watcher_.StopWatchingFileDescriptor(); waiting_connect_ = false; } @@ -285,7 +285,7 @@ void TCPClientSocket::DidCompleteRead() { if (result != ERR_IO_PENDING) { buf_ = NULL; buf_len_ = 0; - MessageLoopForIO::current()->UnwatchSocket(event_.get()); + socket_watcher_.StopWatchingFileDescriptor(); DoCallback(result); } } @@ -304,21 +304,24 @@ void TCPClientSocket::DidCompleteWrite() { if (result != ERR_IO_PENDING) { write_buf_ = NULL; write_buf_len_ = 0; - MessageLoopForIO::current()->UnwatchSocket(event_.get()); + socket_watcher_.StopWatchingFileDescriptor(); DoWriteCallback(result); } } -void TCPClientSocket::OnSocketReady(short flags) { - // the only used bits of flags are EV_READ and EV_WRITE +void TCPClientSocket::OnFileCanReadWithoutBlocking(int fd) { + if (waiting_connect_) { + DidCompleteConnect(); + } else if (callback_) { + DidCompleteRead(); + } +} +void TCPClientSocket::OnFileCanWriteWithoutBlocking(int fd) { if (waiting_connect_) { DidCompleteConnect(); - } else { - if ((flags & EV_WRITE) && write_callback_) - DidCompleteWrite(); - if ((flags & EV_READ) && callback_) - DidCompleteRead(); + } else if (write_callback_) { + DidCompleteWrite(); } } |