diff options
Diffstat (limited to 'jingle/glue/channel_socket_adapter.cc')
-rw-r--r-- | jingle/glue/channel_socket_adapter.cc | 74 |
1 files changed, 23 insertions, 51 deletions
diff --git a/jingle/glue/channel_socket_adapter.cc b/jingle/glue/channel_socket_adapter.cc index 3e22a35..ae7150a 100644 --- a/jingle/glue/channel_socket_adapter.cc +++ b/jingle/glue/channel_socket_adapter.cc @@ -18,8 +18,6 @@ TransportChannelSocketAdapter::TransportChannelSocketAdapter( cricket::TransportChannel* channel) : message_loop_(MessageLoop::current()), channel_(channel), - old_read_callback_(NULL), - write_callback_(NULL), closed_error_code_(net::OK) { DCHECK(channel_); @@ -35,30 +33,13 @@ TransportChannelSocketAdapter::~TransportChannelSocketAdapter() { } int TransportChannelSocketAdapter::Read( - net::IOBuffer* buf, int buffer_size, net::OldCompletionCallback* callback) { - DCHECK_EQ(MessageLoop::current(), message_loop_); - DCHECK(buf); - DCHECK(callback); - CHECK(!old_read_callback_ && read_callback_.is_null()); - - if (!channel_) { - DCHECK(closed_error_code_ != net::OK); - return closed_error_code_; - } - - old_read_callback_ = callback; - read_buffer_ = buf; - read_buffer_size_ = buffer_size; - - return net::ERR_IO_PENDING; -} -int TransportChannelSocketAdapter::Read( - net::IOBuffer* buf, int buffer_size, + net::IOBuffer* buf, + int buffer_size, const net::CompletionCallback& callback) { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK(buf); DCHECK(!callback.is_null()); - CHECK(!old_read_callback_ && read_callback_.is_null()); + CHECK(read_callback_.is_null()); if (!channel_) { DCHECK(closed_error_code_ != net::OK); @@ -73,11 +54,13 @@ int TransportChannelSocketAdapter::Read( } int TransportChannelSocketAdapter::Write( - net::IOBuffer* buffer, int buffer_size, net::OldCompletionCallback* callback) { + net::IOBuffer* buffer, + int buffer_size, + const net::CompletionCallback& callback) { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK(buffer); - DCHECK(callback); - CHECK(!write_callback_); + DCHECK(!callback.is_null()); + CHECK(write_callback_.is_null()); if (!channel_) { DCHECK(closed_error_code_ != net::OK); @@ -129,23 +112,18 @@ void TransportChannelSocketAdapter::Close(int error_code) { channel_->SignalDestroyed.disconnect(this); channel_ = NULL; - if (old_read_callback_) { - net::OldCompletionCallback* callback = old_read_callback_; - old_read_callback_ = NULL; - read_buffer_ = NULL; - callback->Run(error_code); - } else if (!read_callback_.is_null()) { + if (!read_callback_.is_null()) { net::CompletionCallback callback = read_callback_; read_callback_.Reset(); read_buffer_ = NULL; callback.Run(error_code); } - if (write_callback_) { - net::OldCompletionCallback* callback = write_callback_; - write_callback_ = NULL; + if (!write_callback_.is_null()) { + net::CompletionCallback callback = write_callback_; + write_callback_.Reset(); write_buffer_ = NULL; - callback->Run(error_code); + callback.Run(error_code); } } @@ -153,7 +131,7 @@ void TransportChannelSocketAdapter::OnNewPacket( cricket::TransportChannel* channel, const char* data, size_t data_size) { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK_EQ(channel, channel_); - if (old_read_callback_ || !read_callback_.is_null()) { + if (!read_callback_.is_null()) { DCHECK(read_buffer_); CHECK_LT(data_size, static_cast<size_t>(std::numeric_limits<int>::max())); @@ -165,17 +143,11 @@ void TransportChannelSocketAdapter::OnNewPacket( memcpy(read_buffer_->data(), data, data_size); - if (old_read_callback_) { - net::OldCompletionCallback* callback = old_read_callback_; - old_read_callback_ = NULL; - read_buffer_ = NULL; - callback->Run(data_size); - } else { - net::CompletionCallback callback = read_callback_; - read_callback_.Reset(); - read_buffer_ = NULL; - callback.Run(data_size); - } + net::CompletionCallback callback = read_callback_; + read_callback_.Reset(); + read_buffer_ = NULL; + + callback.Run(data_size); } else { LOG(WARNING) << "Data was received without a callback. Dropping the packet."; @@ -186,17 +158,17 @@ void TransportChannelSocketAdapter::OnWritableState( cricket::TransportChannel* channel) { DCHECK_EQ(MessageLoop::current(), message_loop_); // Try to send the packet if there is a pending write. - if (write_callback_) { + if (!write_callback_.is_null()) { int result = channel_->SendPacket(write_buffer_->data(), write_buffer_size_); if (result < 0) result = net::MapSystemError(channel_->GetError()); if (result != net::ERR_IO_PENDING) { - net::OldCompletionCallback* callback = write_callback_; - write_callback_ = NULL; + net::CompletionCallback callback = write_callback_; + write_callback_.Reset(); write_buffer_ = NULL; - callback->Run(result); + callback.Run(result); } } } |