diff options
Diffstat (limited to 'remoting/jingle_glue')
-rw-r--r-- | remoting/jingle_glue/ssl_socket_adapter.cc | 36 | ||||
-rw-r--r-- | remoting/jingle_glue/ssl_socket_adapter.h | 5 |
2 files changed, 34 insertions, 7 deletions
diff --git a/remoting/jingle_glue/ssl_socket_adapter.cc b/remoting/jingle_glue/ssl_socket_adapter.cc index 7414c4b..3df508e 100644 --- a/remoting/jingle_glue/ssl_socket_adapter.cc +++ b/remoting/jingle_glue/ssl_socket_adapter.cc @@ -188,7 +188,7 @@ void SSLSocketAdapter::OnConnectEvent(talk_base::AsyncSocket* socket) { TransportSocket::TransportSocket(talk_base::AsyncSocket* socket, SSLSocketAdapter *ssl_adapter) : old_read_callback_(NULL), - write_callback_(NULL), + old_write_callback_(NULL), read_buffer_len_(0), write_buffer_len_(0), socket_(socket), @@ -327,7 +327,25 @@ int TransportSocket::Read(net::IOBuffer* buf, int buf_len, int TransportSocket::Write(net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) { DCHECK(buf); - DCHECK(!write_callback_); + DCHECK(!old_write_callback_ && write_callback_.is_null()); + DCHECK(!write_buffer_.get()); + int result = socket_->Send(buf->data(), buf_len); + if (result < 0) { + result = net::MapSystemError(socket_->GetError()); + if (result == net::ERR_IO_PENDING) { + old_write_callback_ = callback; + write_buffer_ = buf; + write_buffer_len_ = buf_len; + } + } + if (result != net::ERR_IO_PENDING) + was_used_to_convey_data_ = true; + return result; +} +int TransportSocket::Write(net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback) { + DCHECK(buf); + DCHECK(!old_write_callback_ && write_callback_.is_null()); DCHECK(!write_buffer_.get()); int result = socket_->Send(buf->data(), buf_len); if (result < 0) { @@ -386,13 +404,15 @@ void TransportSocket::OnReadEvent(talk_base::AsyncSocket* socket) { } void TransportSocket::OnWriteEvent(talk_base::AsyncSocket* socket) { - if (write_callback_) { + if (old_write_callback_ || !write_callback_.is_null()) { DCHECK(write_buffer_.get()); - net::OldCompletionCallback* callback = write_callback_; + net::OldCompletionCallback* old_callback = old_write_callback_; + net::CompletionCallback callback = write_callback_; scoped_refptr<net::IOBuffer> buffer = write_buffer_; int buffer_len = write_buffer_len_; - write_callback_ = NULL; + old_write_callback_ = NULL; + write_callback_.Reset(); write_buffer_ = NULL; write_buffer_len_ = 0; @@ -400,6 +420,7 @@ void TransportSocket::OnWriteEvent(talk_base::AsyncSocket* socket) { if (result < 0) { result = net::MapSystemError(socket_->GetError()); if (result == net::ERR_IO_PENDING) { + old_write_callback_ = old_callback; write_callback_ = callback; write_buffer_ = buffer; write_buffer_len_ = buffer_len; @@ -407,7 +428,10 @@ void TransportSocket::OnWriteEvent(talk_base::AsyncSocket* socket) { } } was_used_to_convey_data_ = true; - callback->RunWithParams(Tuple1<int>(result)); + if (old_callback) + old_callback->RunWithParams(Tuple1<int>(result)); + else + callback.Run(result); } } diff --git a/remoting/jingle_glue/ssl_socket_adapter.h b/remoting/jingle_glue/ssl_socket_adapter.h index f929bf8..3638ae1 100644 --- a/remoting/jingle_glue/ssl_socket_adapter.h +++ b/remoting/jingle_glue/ssl_socket_adapter.h @@ -62,6 +62,8 @@ class TransportSocket : public net::StreamSocket, public sigslot::has_slots<> { const net::CompletionCallback& callback) OVERRIDE; virtual int Write(net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) OVERRIDE; + virtual int Write(net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback) OVERRIDE; virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; virtual bool SetSendBufferSize(int32 size) OVERRIDE; @@ -73,7 +75,8 @@ class TransportSocket : public net::StreamSocket, public sigslot::has_slots<> { net::OldCompletionCallback* old_read_callback_; net::CompletionCallback read_callback_; - net::OldCompletionCallback* write_callback_; + net::OldCompletionCallback* old_write_callback_; + net::CompletionCallback write_callback_; scoped_refptr<net::IOBuffer> read_buffer_; int read_buffer_len_; |