diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 18:43:55 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 18:43:55 +0000 |
commit | 83039bbf2f2ec0e918f7000b5212d104f60f2bb7 (patch) | |
tree | b22dbd0051b57a437a588772a874271f0d02ffdb /remoting/jingle_glue/ssl_socket_adapter.cc | |
parent | e7456a206fe5b50aeb322ebabd6c26adc869a5fd (diff) | |
download | chromium_src-83039bbf2f2ec0e918f7000b5212d104f60f2bb7.zip chromium_src-83039bbf2f2ec0e918f7000b5212d104f60f2bb7.tar.gz chromium_src-83039bbf2f2ec0e918f7000b5212d104f60f2bb7.tar.bz2 |
Migrate net/socket/socket.h, net/socket/stream_socket.h to base::Bind().
This changes Socket::Read(), Socket::Write, and StreamSocket::Connect() to use CompletionCallback and fixes all users.
BUG=none
TEST=existing.
Review URL: http://codereview.chromium.org/8824006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/jingle_glue/ssl_socket_adapter.cc')
-rw-r--r-- | remoting/jingle_glue/ssl_socket_adapter.cc | 68 |
1 files changed, 17 insertions, 51 deletions
diff --git a/remoting/jingle_glue/ssl_socket_adapter.cc b/remoting/jingle_glue/ssl_socket_adapter.cc index 7414c4b..5bf2f73 100644 --- a/remoting/jingle_glue/ssl_socket_adapter.cc +++ b/remoting/jingle_glue/ssl_socket_adapter.cc @@ -27,12 +27,6 @@ SSLSocketAdapter::SSLSocketAdapter(AsyncSocket* socket) : SSLAdapter(socket), ignore_bad_cert_(false), cert_verifier_(new net::CertVerifier()), - ALLOW_THIS_IN_INITIALIZER_LIST( - connected_callback_(this, &SSLSocketAdapter::OnConnected)), - ALLOW_THIS_IN_INITIALIZER_LIST( - read_callback_(this, &SSLSocketAdapter::OnRead)), - ALLOW_THIS_IN_INITIALIZER_LIST( - write_callback_(this, &SSLSocketAdapter::OnWrite)), ssl_state_(SSLSTATE_NONE), read_state_(IOSTATE_NONE), write_state_(IOSTATE_NONE) { @@ -77,7 +71,8 @@ int SSLSocketAdapter::BeginSSL() { transport_socket_, net::HostPortPair(hostname_, 443), ssl_config, NULL /* ssl_host_info */, context)); - int result = ssl_socket_->Connect(&connected_callback_); + int result = ssl_socket_->Connect( + base::Bind(&SSLSocketAdapter::OnConnected, base::Unretained(this))); if (result == net::ERR_IO_PENDING || result == net::OK) { return 0; @@ -94,7 +89,8 @@ int SSLSocketAdapter::Send(const void* buf, size_t len) { scoped_refptr<net::IOBuffer> transport_buf(new net::IOBuffer(len)); memcpy(transport_buf->data(), buf, len); - int result = ssl_socket_->Write(transport_buf, len, NULL); + int result = ssl_socket_->Write(transport_buf, len, + net::CompletionCallback()); if (result == net::ERR_IO_PENDING) { SetError(EWOULDBLOCK); } @@ -116,7 +112,9 @@ int SSLSocketAdapter::Recv(void* buf, size_t len) { switch (read_state_) { case IOSTATE_NONE: { transport_buf_ = new net::IOBuffer(len); - int result = ssl_socket_->Read(transport_buf_, len, &read_callback_); + int result = ssl_socket_->Read( + transport_buf_, len, + base::Bind(&SSLSocketAdapter::OnRead, base::Unretained(this))); if (result >= 0) { memcpy(buf, transport_buf_->data(), len); } @@ -187,9 +185,7 @@ void SSLSocketAdapter::OnConnectEvent(talk_base::AsyncSocket* socket) { TransportSocket::TransportSocket(talk_base::AsyncSocket* socket, SSLSocketAdapter *ssl_adapter) - : old_read_callback_(NULL), - write_callback_(NULL), - read_buffer_len_(0), + : read_buffer_len_(0), write_buffer_len_(0), socket_(socket), was_used_to_convey_data_(false) { @@ -200,12 +196,6 @@ TransportSocket::TransportSocket(talk_base::AsyncSocket* socket, TransportSocket::~TransportSocket() { } -int TransportSocket::Connect(net::OldCompletionCallback* callback) { - // Connect is never called by SSLClientSocket, instead SSLSocketAdapter - // calls Connect() on socket_ directly. - NOTREACHED(); - return false; -} int TransportSocket::Connect(const net::CompletionCallback& callback) { // Connect is never called by SSLClientSocket, instead SSLSocketAdapter // calls Connect() on socket_ directly. @@ -288,27 +278,9 @@ base::TimeDelta TransportSocket::GetConnectTimeMicros() const { } int TransportSocket::Read(net::IOBuffer* buf, int buf_len, - net::OldCompletionCallback* callback) { - DCHECK(buf); - DCHECK(!old_read_callback_ && read_callback_.is_null()); - DCHECK(!read_buffer_.get()); - int result = socket_->Recv(buf->data(), buf_len); - if (result < 0) { - result = net::MapSystemError(socket_->GetError()); - if (result == net::ERR_IO_PENDING) { - old_read_callback_ = callback; - read_buffer_ = buf; - read_buffer_len_ = buf_len; - } - } - if (result != net::ERR_IO_PENDING) - was_used_to_convey_data_ = true; - return result; -} -int TransportSocket::Read(net::IOBuffer* buf, int buf_len, const net::CompletionCallback& callback) { DCHECK(buf); - DCHECK(!old_read_callback_ && read_callback_.is_null()); + DCHECK(read_callback_.is_null()); DCHECK(!read_buffer_.get()); int result = socket_->Recv(buf->data(), buf_len); if (result < 0) { @@ -325,9 +297,9 @@ int TransportSocket::Read(net::IOBuffer* buf, int buf_len, } int TransportSocket::Write(net::IOBuffer* buf, int buf_len, - net::OldCompletionCallback* callback) { + const net::CompletionCallback& callback) { DCHECK(buf); - DCHECK(!write_callback_); + DCHECK(write_callback_.is_null()); DCHECK(!write_buffer_.get()); int result = socket_->Send(buf->data(), buf_len); if (result < 0) { @@ -354,14 +326,12 @@ bool TransportSocket::SetSendBufferSize(int32 size) { } void TransportSocket::OnReadEvent(talk_base::AsyncSocket* socket) { - if (old_read_callback_ || !read_callback_.is_null()) { + if (!read_callback_.is_null()) { DCHECK(read_buffer_.get()); - net::OldCompletionCallback* old_callback = old_read_callback_; net::CompletionCallback callback = read_callback_; scoped_refptr<net::IOBuffer> buffer = read_buffer_; int buffer_len = read_buffer_len_; - old_read_callback_ = NULL; read_callback_.Reset(); read_buffer_ = NULL; read_buffer_len_ = 0; @@ -370,7 +340,6 @@ void TransportSocket::OnReadEvent(talk_base::AsyncSocket* socket) { if (result < 0) { result = net::MapSystemError(socket_->GetError()); if (result == net::ERR_IO_PENDING) { - old_read_callback_ = old_callback; read_callback_ = callback; read_buffer_ = buffer; read_buffer_len_ = buffer_len; @@ -378,21 +347,18 @@ void TransportSocket::OnReadEvent(talk_base::AsyncSocket* socket) { } } was_used_to_convey_data_ = true; - if (old_callback) - old_callback->RunWithParams(Tuple1<int>(result)); - else - callback.Run(result); + callback.Run(result); } } void TransportSocket::OnWriteEvent(talk_base::AsyncSocket* socket) { - if (write_callback_) { + if (!write_callback_.is_null()) { DCHECK(write_buffer_.get()); - net::OldCompletionCallback* callback = write_callback_; + net::CompletionCallback callback = write_callback_; scoped_refptr<net::IOBuffer> buffer = write_buffer_; int buffer_len = write_buffer_len_; - write_callback_ = NULL; + write_callback_.Reset(); write_buffer_ = NULL; write_buffer_len_ = 0; @@ -407,7 +373,7 @@ void TransportSocket::OnWriteEvent(talk_base::AsyncSocket* socket) { } } was_used_to_convey_data_ = true; - callback->RunWithParams(Tuple1<int>(result)); + callback.Run(result); } } |