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

Unified Diff: net/quic/chromium/bidirectional_stream_quic_impl.cc

Issue 2877063002: Add an async ReadBody method to QuicChromiumClientStream::Handle (Closed)
Patch Set: format Created 3 years, 7 months 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: net/quic/chromium/bidirectional_stream_quic_impl.cc
diff --git a/net/quic/chromium/bidirectional_stream_quic_impl.cc b/net/quic/chromium/bidirectional_stream_quic_impl.cc
index 17a9f7960843122c69862de0016df3648b89ded8..2f5ad1dd1ed61062f1e1ab6933e81da514dc1221 100644
--- a/net/quic/chromium/bidirectional_stream_quic_impl.cc
+++ b/net/quic/chromium/bidirectional_stream_quic_impl.cc
@@ -112,20 +112,25 @@ int BidirectionalStreamQuicImpl::ReadData(IOBuffer* buffer, int buffer_len) {
// If the stream is already closed, there is no body to read.
return response_status_;
}
- int rv = stream_->Read(buffer, buffer_len);
- if (rv != ERR_IO_PENDING) {
- if (stream_->IsDoneReading()) {
- // If the write side is closed, OnFinRead() will call
- // BidirectionalStreamQuicImpl::OnClose().
- stream_->OnFinRead();
- }
+ int rv = stream_->ReadBody(
+ buffer, buffer_len,
+ base::Bind(&BidirectionalStreamQuicImpl::OnReadDataComplete,
+ weak_factory_.GetWeakPtr()));
+ if (rv == ERR_IO_PENDING) {
+ read_buffer_ = buffer;
+ read_buffer_len_ = buffer_len;
+ return ERR_IO_PENDING;
+ }
+
+ if (rv < 0)
return rv;
+
+ if (stream_->IsDoneReading()) {
+ // If the write side is closed, OnFinRead() will call
+ // BidirectionalStreamQuicImpl::OnClose().
+ stream_->OnFinRead();
}
- // Read will complete asynchronously and Delegate::OnReadCompleted will be
- // called upon completion.
- read_buffer_ = buffer;
- read_buffer_len_ = buffer_len;
- return ERR_IO_PENDING;
+ return rv;
}
void BidirectionalStreamQuicImpl::SendData(const scoped_refptr<IOBuffer>& data,
@@ -236,22 +241,6 @@ void BidirectionalStreamQuicImpl::OnTrailingHeadersAvailable(
// |this| can be destroyed after this point.
}
-void BidirectionalStreamQuicImpl::OnDataAvailable() {
- // Return early if ReadData has not been called.
- if (!read_buffer_)
- return;
-
- int rv = ReadData(read_buffer_.get(), read_buffer_len_);
- if (rv == ERR_IO_PENDING) {
- // Spurrious notification. Wait for the next one.
- return;
- }
- read_buffer_ = nullptr;
- read_buffer_len_ = 0;
- if (delegate_)
- delegate_->OnDataRead(rv);
-}
-
void BidirectionalStreamQuicImpl::OnClose() {
DCHECK(stream_);
@@ -323,6 +312,21 @@ void BidirectionalStreamQuicImpl::OnReadInitialHeadersComplete(int rv) {
delegate_->OnHeadersReceived(initial_headers_);
}
+void BidirectionalStreamQuicImpl::OnReadDataComplete(int rv) {
+ DCHECK_GE(rv, 0);
+ read_buffer_ = nullptr;
+ read_buffer_len_ = 0;
+
+ if (stream_->IsDoneReading()) {
+ // If the write side is closed, OnFinRead() will call
+ // BidirectionalStreamQuicImpl::OnClose().
+ stream_->OnFinRead();
+ }
+
+ if (delegate_)
+ delegate_->OnDataRead(rv);
+}
+
void BidirectionalStreamQuicImpl::NotifyError(int error) {
DCHECK_NE(OK, error);
DCHECK_NE(ERR_IO_PENDING, error);
« no previous file with comments | « net/quic/chromium/bidirectional_stream_quic_impl.h ('k') | net/quic/chromium/bidirectional_stream_quic_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698