diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 23:33:24 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 23:33:24 +0000 |
commit | dbf036fcb743cfdcd5be421364c8b89b10ee3f55 (patch) | |
tree | 034c3028c8b523d2bb6c2703416b26a81bc31663 /net/curvecp | |
parent | ad24b1827fe58c4a22c0cddb5791a95f2ab1b21b (diff) | |
download | chromium_src-dbf036fcb743cfdcd5be421364c8b89b10ee3f55.zip chromium_src-dbf036fcb743cfdcd5be421364c8b89b10ee3f55.tar.gz chromium_src-dbf036fcb743cfdcd5be421364c8b89b10ee3f55.tar.bz2 |
base::Bind: Convert StreamSocket::Connect.
BUG=none
TEST=none
R=csilv
Review URL: http://codereview.chromium.org/8801004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113283 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/curvecp')
-rw-r--r-- | net/curvecp/client_packetizer.cc | 36 | ||||
-rw-r--r-- | net/curvecp/client_packetizer.h | 12 | ||||
-rw-r--r-- | net/curvecp/curvecp_client_socket.cc | 4 | ||||
-rw-r--r-- | net/curvecp/curvecp_client_socket.h | 3 |
4 files changed, 43 insertions, 12 deletions
diff --git a/net/curvecp/client_packetizer.cc b/net/curvecp/client_packetizer.cc index 72bf4a0..77ddfda 100644 --- a/net/curvecp/client_packetizer.cc +++ b/net/curvecp/client_packetizer.cc @@ -33,7 +33,7 @@ ClientPacketizer::ClientPacketizer() : Packetizer(), next_state_(NONE), listener_(NULL), - user_callback_(NULL), + old_user_callback_(NULL), current_address_(NULL), hello_attempts_(0), initiate_sent_(false), @@ -52,7 +52,23 @@ ClientPacketizer::~ClientPacketizer() { int ClientPacketizer::Connect(const AddressList& server, Packetizer::Listener* listener, OldCompletionCallback* callback) { - DCHECK(!user_callback_); + DCHECK(!old_user_callback_); + DCHECK(!socket_.get()); + DCHECK(!listener_); + + listener_ = listener; + + addresses_ = server; + + old_user_callback_ = callback; + next_state_ = LOOKUP_COOKIE; + + return DoLoop(OK); +} +int ClientPacketizer::Connect(const AddressList& server, + Packetizer::Listener* listener, + const net::CompletionCallback& callback) { + DCHECK(user_callback_.is_null()); DCHECK(!socket_.get()); DCHECK(!listener_); @@ -279,11 +295,17 @@ int ClientPacketizer::DoConnected(int rv) { void ClientPacketizer::DoCallback(int result) { DCHECK_NE(result, ERR_IO_PENDING); - DCHECK(user_callback_); - - OldCompletionCallback* callback = user_callback_; - user_callback_ = NULL; - callback->Run(result); + DCHECK(old_user_callback_ || !user_callback_.is_null()); + + if (old_user_callback_) { + OldCompletionCallback* callback = old_user_callback_; + old_user_callback_ = NULL; + callback->Run(result); + } else { + CompletionCallback callback = user_callback_; + user_callback_.Reset(); + callback.Run(result); + } } int ClientPacketizer::ConnectNextAddress() { diff --git a/net/curvecp/client_packetizer.h b/net/curvecp/client_packetizer.h index 4915bbe..f8edeaf 100644 --- a/net/curvecp/client_packetizer.h +++ b/net/curvecp/client_packetizer.h @@ -30,8 +30,11 @@ class ClientPacketizer : public Packetizer { int Connect(const AddressList& server, Packetizer::Listener* listener, OldCompletionCallback* callback); + int Connect(const AddressList& server, + Packetizer::Listener* listener, + const CompletionCallback& callback); - // Packetizer methods + // Packetizer implementation. virtual int SendMessage(ConnectionKey key, const char* data, size_t length, @@ -83,13 +86,14 @@ class ClientPacketizer : public Packetizer { StateType next_state_; scoped_ptr<UDPClientSocket> socket_; Packetizer::Listener* listener_; - OldCompletionCallback* user_callback_; + OldCompletionCallback* old_user_callback_; + CompletionCallback user_callback_; AddressList addresses_; const struct addrinfo* current_address_; int hello_attempts_; // Number of attempts to send a Hello Packet. - bool initiate_sent_; // Indicates whether the Initialte Packet was sent. + bool initiate_sent_; // Indicates whether the Initiate Packet was sent. - scoped_refptr<IOBuffer> read_buffer_; // Buffer for interal reads. + scoped_refptr<IOBuffer> read_buffer_; // Buffer for internal reads. uchar shortterm_public_key_[32]; diff --git a/net/curvecp/curvecp_client_socket.cc b/net/curvecp/curvecp_client_socket.cc index cba3d0e..8074016 100644 --- a/net/curvecp/curvecp_client_socket.cc +++ b/net/curvecp/curvecp_client_socket.cc @@ -25,6 +25,10 @@ int CurveCPClientSocket::Connect(OldCompletionCallback* callback) { return packetizer_.Connect(addresses_, &messenger_, callback); } +int CurveCPClientSocket::Connect(const net::CompletionCallback& callback) { + return packetizer_.Connect(addresses_, &messenger_, callback); +} + void CurveCPClientSocket::Disconnect() { // TODO(mbelshe): DCHECK that we're connected. // Record the ConnectionKey so that we can disconnect it properly. diff --git a/net/curvecp/curvecp_client_socket.h b/net/curvecp/curvecp_client_socket.h index fc56440..85f8817 100644 --- a/net/curvecp/curvecp_client_socket.h +++ b/net/curvecp/curvecp_client_socket.h @@ -25,8 +25,9 @@ class CurveCPClientSocket : public StreamSocket { const net::NetLog::Source& source); virtual ~CurveCPClientSocket(); - // ClientSocket methods: + // ClientSocket implementation. virtual int Connect(OldCompletionCallback* callback) OVERRIDE; + virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; virtual void Disconnect() OVERRIDE; virtual bool IsConnected() const OVERRIDE; virtual bool IsConnectedAndIdle() const OVERRIDE; |