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

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: Resync 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..4674f4d65ea5cafe9dc673456eb43ba157fd63ba 100644
--- a/blimp/net/stream_packet_writer.cc
+++ b/blimp/net/stream_packet_writer.cc
@@ -47,14 +47,16 @@ 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));
+ return;
Wez 2015/11/24 23:43:18 If we're mandating no zero-sized packets then writ
Kevin M 2015/11/25 01:18:37 Done.
}
write_state_ = WriteState::HEADER;
@@ -63,18 +65,18 @@ int StreamPacketWriter::WritePacket(scoped_refptr<net::DrainableIOBuffer> data,
base::HostToNet32(data->BytesRemaining());
payload_buffer_ = data;
- int result = DoWriteLoop(false);
- if (result == net::ERR_IO_PENDING) {
- // Store the completion callback to invoke when DoWriteLoop completes
- // asynchronously.
- callback_ = callback;
- } else {
+ int result = DoWriteLoop(net::OK);
+ if (result != net::ERR_IO_PENDING) {
// Release the payload buffer, since the write operation has completed
// synchronously.
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