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

Unified Diff: net/socket/tcp_client_socket_libevent.cc

Issue 8801004: base::Bind: Convert StreamSocket::Connect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/socket/tcp_client_socket_libevent.h ('k') | net/socket/tcp_client_socket_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/tcp_client_socket_libevent.cc
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index 2a490e1efc3e2d1564611f2194002ec0cc51d286..7c8af80e674ed41aefc52610ee5512cba9fb55c6 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -131,7 +131,7 @@ TCPClientSocketLibevent::TCPClientSocketLibevent(
read_watcher_(this),
write_watcher_(this),
read_callback_(NULL),
- write_callback_(NULL),
+ old_write_callback_(NULL),
next_connect_state_(CONNECT_STATE_NONE),
connect_os_error_(0),
net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
@@ -227,6 +227,38 @@ int TCPClientSocketLibevent::Connect(OldCompletionCallback* callback) {
if (rv == ERR_IO_PENDING) {
// Synchronous operation not supported.
DCHECK(callback);
+ old_write_callback_ = callback;
+ } else {
+ LogConnectCompletion(rv);
+ }
+
+ return rv;
+}
+int TCPClientSocketLibevent::Connect(const CompletionCallback& callback) {
+ DCHECK(CalledOnValidThread());
+
+ // If already connected, then just return OK.
+ if (socket_ != kInvalidSocket)
+ return OK;
+
+ base::StatsCounter connects("tcp.connect");
+ connects.Increment();
+
+ DCHECK(!waiting_connect());
+
+ net_log_.BeginEvent(
+ NetLog::TYPE_TCP_CONNECT,
+ make_scoped_refptr(new AddressListNetLogParam(addresses_)));
+
+ // We will try to connect to each address in addresses_. Start with the
+ // first one in the list.
+ next_connect_state_ = CONNECT_STATE_CONNECT;
+ current_ai_ = addresses_.head();
+
+ int rv = DoConnectLoop(OK);
+ if (rv == ERR_IO_PENDING) {
+ // Synchronous operation not supported.
+ DCHECK(!callback.is_null());
write_callback_ = callback;
} else {
LogConnectCompletion(rv);
@@ -473,7 +505,7 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf,
DCHECK(CalledOnValidThread());
DCHECK_NE(kInvalidSocket, socket_);
DCHECK(!waiting_connect());
- DCHECK(!write_callback_);
+ DCHECK(!old_write_callback_ && write_callback_.is_null());
// Synchronous operation not supported
DCHECK(callback);
DCHECK_GT(buf_len, 0);
@@ -500,7 +532,7 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf,
write_buf_ = buf;
write_buf_len_ = buf_len;
- write_callback_ = callback;
+ old_write_callback_ = callback;
return ERR_IO_PENDING;
}
@@ -596,12 +628,18 @@ void TCPClientSocketLibevent::DoReadCallback(int rv) {
void TCPClientSocketLibevent::DoWriteCallback(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
- DCHECK(write_callback_);
+ DCHECK(old_write_callback_ || !write_callback_.is_null());
// since Run may result in Write being called, clear write_callback_ up front.
- OldCompletionCallback* c = write_callback_;
- write_callback_ = NULL;
- c->Run(rv);
+ if (old_write_callback_) {
+ OldCompletionCallback* c = old_write_callback_;
+ old_write_callback_ = NULL;
+ c->Run(rv);
+ } else {
+ CompletionCallback c = write_callback_;
+ write_callback_.Reset();
+ c.Run(rv);
+ }
}
void TCPClientSocketLibevent::DidCompleteConnect() {
« no previous file with comments | « net/socket/tcp_client_socket_libevent.h ('k') | net/socket/tcp_client_socket_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698