Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: blimp/net/stream_packet_writer.cc

Issue 1452823011: Make PacketReader/PacketWriter interfaces async-only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698