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

Unified Diff: blimp/net/stream_packet_reader.cc

Issue 1452823011: Make PacketReader/PacketWriter interfaces async-only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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
« no previous file with comments | « blimp/net/stream_packet_reader.h ('k') | blimp/net/stream_packet_reader_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/net/stream_packet_reader.cc
diff --git a/blimp/net/stream_packet_reader.cc b/blimp/net/stream_packet_reader.cc
index 8da613020feaf66b7a840a186121379cbe6647cc..e50074865076abb84b88230070557093e2839f5e 100644
--- a/blimp/net/stream_packet_reader.cc
+++ b/blimp/net/stream_packet_reader.cc
@@ -9,6 +9,7 @@
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop.h"
#include "base/sys_byteorder.h"
#include "blimp/net/common.h"
#include "net/base/io_buffer.h"
@@ -42,7 +43,7 @@ StreamPacketReader::StreamPacketReader(net::StreamSocket* socket)
StreamPacketReader::~StreamPacketReader() {}
-int StreamPacketReader::ReadPacket(
+void StreamPacketReader::ReadPacket(
const scoped_refptr<net::GrowableIOBuffer>& buf,
const net::CompletionCallback& callback) {
DCHECK_EQ(ReadState::IDLE, read_state_);
@@ -54,17 +55,17 @@ int StreamPacketReader::ReadPacket(
read_state_ = ReadState::HEADER;
int result = DoReadLoop(net::OK);
- if (result == net::ERR_IO_PENDING) {
- // Store the completion callback to invoke when read completes
- // asynchronously.
- callback_ = callback;
- } else {
+ if (result != net::ERR_IO_PENDING) {
// Release the payload buffer, since the read 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 StreamPacketReader::DoReadLoop(int result) {
@@ -134,7 +135,7 @@ int StreamPacketReader::DoReadPayload(int result) {
// Finished reading the payload.
read_state_ = ReadState::IDLE;
- return payload_size_;
+ return net::OK;
}
void StreamPacketReader::OnReadComplete(int result) {
« no previous file with comments | « blimp/net/stream_packet_reader.h ('k') | blimp/net/stream_packet_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698