Chromium Code Reviews| Index: blimp/net/stream_packet_writer.cc |
| diff --git a/blimp/net/stream_packet_writer.cc b/blimp/net/stream_packet_writer.cc |
| index 221cdd170e7fa87eb5b0f31742de8e8b9591f4f8..2d4ee0a2f21c6c6ddddd0066fa58f606a8b85c35 100644 |
| --- a/blimp/net/stream_packet_writer.cc |
| +++ b/blimp/net/stream_packet_writer.cc |
| @@ -47,14 +47,15 @@ StreamPacketWriter::StreamPacketWriter(net::StreamSocket* socket) |
| StreamPacketWriter::~StreamPacketWriter() {} |
| -int StreamPacketWriter::WritePacket(scoped_refptr<net::DrainableIOBuffer> data, |
| - const net::CompletionCallback& callback) { |
| +void StreamPacketWriter::WritePacket(scoped_refptr<net::DrainableIOBuffer> data, |
| + const net::CompletionCallback& callback) { |
| DCHECK_EQ(WriteState::IDLE, write_state_); |
| DCHECK(data); |
| if (data->BytesRemaining() == 0) { |
| // The packet is empty; your argument is invalid. |
| DLOG(ERROR) << "Attempted to write zero-length packet."; |
| - return net::ERR_INVALID_ARGUMENT; |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, base::Bind(callback, net::ERR_INVALID_ARGUMENT)); |
| } |
| write_state_ = WriteState::HEADER; |
| @@ -65,16 +66,16 @@ int StreamPacketWriter::WritePacket(scoped_refptr<net::DrainableIOBuffer> data, |
| int result = DoWriteLoop(false); |
|
Wez
2015/11/20 23:42:13
Why are we passing DoWriteLoop a bool here, when i
Kevin M
2015/11/24 21:34:36
Done.
|
| if (result == net::ERR_IO_PENDING) { |
| - // Store the completion callback to invoke when DoWriteLoop completes |
| - // asynchronously. |
| - callback_ = callback; |
| - } else { |
| // Release the payload buffer, since the write operation has completed |
| // synchronously. |
|
Wez
2015/11/20 23:42:13
Not according to the result test above, it hasn't.
Kevin M
2015/11/24 21:34:36
Done. I must've been interrupted mid-CL, because t
|
| payload_buffer_ = nullptr; |
| - } |
| - return result; |
| + // Adapt synchronous completion to an asynchronous style. |
| + base::MessageLoop::current()->PostTask(FROM_HERE, |
| + base::Bind(callback, result)); |
| + } else { |
| + callback_ = callback; |
| + } |
| } |
| int StreamPacketWriter::DoWriteLoop(int result) { |