diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-08 23:51:15 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-08 23:51:15 +0000 |
commit | 293f154b854a3507de8ed4116e8529f633060810 (patch) | |
tree | 63cc680a578707f0188e2615ebcd407906040166 /remoting/protocol | |
parent | 4c6df432834aa4541044a0890f774b25e15e7746 (diff) | |
download | chromium_src-293f154b854a3507de8ed4116e8529f633060810.zip chromium_src-293f154b854a3507de8ed4116e8529f633060810.tar.gz chromium_src-293f154b854a3507de8ed4116e8529f633060810.tar.bz2 |
base::Bind: Convert Socket::Write.
BUG=none
TEST=none
R=csilv
Review URL: http://codereview.chromium.org/8831001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113699 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol')
-rw-r--r-- | remoting/protocol/fake_session.cc | 14 | ||||
-rw-r--r-- | remoting/protocol/fake_session.h | 4 | ||||
-rw-r--r-- | remoting/protocol/pepper_transport_socket_adapter.cc | 42 | ||||
-rw-r--r-- | remoting/protocol/pepper_transport_socket_adapter.h | 5 |
4 files changed, 57 insertions, 8 deletions
diff --git a/remoting/protocol/fake_session.cc b/remoting/protocol/fake_session.cc index f1a890a..18071fd 100644 --- a/remoting/protocol/fake_session.cc +++ b/remoting/protocol/fake_session.cc @@ -86,6 +86,13 @@ int FakeSocket::Write(net::IOBuffer* buf, int buf_len, buf->data(), buf->data() + buf_len); return buf_len; } +int FakeSocket::Write(net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback) { + EXPECT_EQ(message_loop_, MessageLoop::current()); + written_data_.insert(written_data_.end(), + buf->data(), buf->data() + buf_len); + return buf_len; +} bool FakeSocket::SetReceiveBufferSize(int32 size) { NOTIMPLEMENTED(); @@ -236,6 +243,13 @@ int FakeUdpSocket::Write(net::IOBuffer* buf, int buf_len, written_packets_.back().assign(buf->data(), buf->data() + buf_len); return buf_len; } +int FakeUdpSocket::Write(net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback) { + EXPECT_EQ(message_loop_, MessageLoop::current()); + written_packets_.push_back(std::string()); + written_packets_.back().assign(buf->data(), buf->data() + buf_len); + return buf_len; +} bool FakeUdpSocket::SetReceiveBufferSize(int32 size) { NOTIMPLEMENTED(); diff --git a/remoting/protocol/fake_session.h b/remoting/protocol/fake_session.h index a8239f5..c98d888 100644 --- a/remoting/protocol/fake_session.h +++ b/remoting/protocol/fake_session.h @@ -45,6 +45,8 @@ class FakeSocket : public net::StreamSocket { 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; @@ -105,6 +107,8 @@ class FakeUdpSocket : public net::Socket { 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; diff --git a/remoting/protocol/pepper_transport_socket_adapter.cc b/remoting/protocol/pepper_transport_socket_adapter.cc index 0385b9b..4876088 100644 --- a/remoting/protocol/pepper_transport_socket_adapter.cc +++ b/remoting/protocol/pepper_transport_socket_adapter.cc @@ -50,7 +50,7 @@ PepperTransportSocketAdapter::PepperTransportSocketAdapter( connected_(false), get_address_pending_(false), old_read_callback_(NULL), - write_callback_(NULL) { + old_write_callback_(NULL) { callback_factory_.Initialize(this); } @@ -112,7 +112,28 @@ int PepperTransportSocketAdapter::Read( int PepperTransportSocketAdapter::Write(net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) { DCHECK(CalledOnValidThread()); - DCHECK(!write_callback_); + DCHECK(!old_write_callback_ && write_callback_.is_null()); + DCHECK(!write_buffer_); + + if (!transport_.get()) + return net::ERR_SOCKET_NOT_CONNECTED; + + int result = PPErrorToNetError(transport_->Send( + buf->data(), buf_len, + callback_factory_.NewOptionalCallback( + &PepperTransportSocketAdapter::OnWrite))); + + if (result == net::ERR_IO_PENDING) { + old_write_callback_ = callback; + write_buffer_ = buf; + } + + return result; +} +int PepperTransportSocketAdapter::Write( + net::IOBuffer* buf, int buf_len, const net::CompletionCallback& callback) { + DCHECK(CalledOnValidThread()); + DCHECK(!old_write_callback_ && write_callback_.is_null()); DCHECK(!write_buffer_); if (!transport_.get()) @@ -336,13 +357,20 @@ void PepperTransportSocketAdapter::OnRead(int32_t result) { void PepperTransportSocketAdapter::OnWrite(int32_t result) { DCHECK(CalledOnValidThread()); - DCHECK(write_callback_); + DCHECK(old_write_callback_ || !write_callback_.is_null()); DCHECK(write_buffer_); - net::OldCompletionCallback* callback = write_callback_; - write_callback_ = NULL; - write_buffer_ = NULL; - callback->Run(PPErrorToNetError(result)); + if (old_write_callback_) { + net::OldCompletionCallback* callback = old_write_callback_; + old_write_callback_ = NULL; + write_buffer_ = NULL; + callback->Run(PPErrorToNetError(result)); + } else { + net::CompletionCallback callback = write_callback_; + write_callback_.Reset(); + write_buffer_ = NULL; + callback.Run(PPErrorToNetError(result)); + } } } // namespace protocol diff --git a/remoting/protocol/pepper_transport_socket_adapter.h b/remoting/protocol/pepper_transport_socket_adapter.h index 40b75ce..8453fc4 100644 --- a/remoting/protocol/pepper_transport_socket_adapter.h +++ b/remoting/protocol/pepper_transport_socket_adapter.h @@ -55,6 +55,8 @@ class PepperTransportSocketAdapter : public base::NonThreadSafe, 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; @@ -98,7 +100,8 @@ class PepperTransportSocketAdapter : public base::NonThreadSafe, net::CompletionCallback read_callback_; scoped_refptr<net::IOBuffer> read_buffer_; - net::OldCompletionCallback* write_callback_; + net::OldCompletionCallback* old_write_callback_; + net::CompletionCallback write_callback_; scoped_refptr<net::IOBuffer> write_buffer_; net::BoundNetLog net_log_; |