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

Side by Side Diff: net/quic/bidirectional_stream_quic_impl.cc

Issue 1856073002: Coalesce small buffers in net::BidirectionalStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Javadoc Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/bidirectional_stream_quic_impl.h" 5 #include "net/quic/bidirectional_stream_quic_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
11 #include "net/http/bidirectional_stream_request_info.h" 11 #include "net/http/bidirectional_stream_request_info.h"
12 #include "net/quic/quic_connection.h"
12 #include "net/socket/next_proto.h" 13 #include "net/socket/next_proto.h"
13 #include "net/spdy/spdy_header_block.h" 14 #include "net/spdy/spdy_header_block.h"
14 #include "net/spdy/spdy_http_utils.h" 15 #include "net/spdy/spdy_http_utils.h"
15 16
16 namespace net { 17 namespace net {
17 18
18 BidirectionalStreamQuicImpl::BidirectionalStreamQuicImpl( 19 BidirectionalStreamQuicImpl::BidirectionalStreamQuicImpl(
19 const base::WeakPtr<QuicChromiumClientSession>& session) 20 const base::WeakPtr<QuicChromiumClientSession>& session)
20 : session_(session), 21 : session_(session),
21 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()), 22 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()),
22 stream_(nullptr), 23 stream_(nullptr),
23 request_info_(nullptr), 24 request_info_(nullptr),
24 delegate_(nullptr), 25 delegate_(nullptr),
25 response_status_(OK), 26 response_status_(OK),
26 negotiated_protocol_(kProtoUnknown), 27 negotiated_protocol_(kProtoUnknown),
27 read_buffer_len_(0), 28 read_buffer_len_(0),
28 headers_bytes_received_(0), 29 headers_bytes_received_(0),
29 headers_bytes_sent_(0), 30 headers_bytes_sent_(0),
30 closed_stream_received_bytes_(0), 31 closed_stream_received_bytes_(0),
31 closed_stream_sent_bytes_(0), 32 closed_stream_sent_bytes_(0),
32 has_sent_headers_(false), 33 has_sent_headers_(false),
33 has_received_headers_(false), 34 has_received_headers_(false),
35 disable_auto_flush_(false),
34 weak_factory_(this) { 36 weak_factory_(this) {
35 DCHECK(session_); 37 DCHECK(session_);
36 session_->AddObserver(this); 38 session_->AddObserver(this);
37 } 39 }
38 40
39 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { 41 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() {
40 Cancel(); 42 Cancel();
41 if (session_) 43 if (session_)
42 session_->RemoveObserver(this); 44 session_->RemoveObserver(this);
43 } 45 }
44 46
45 void BidirectionalStreamQuicImpl::Start( 47 void BidirectionalStreamQuicImpl::Start(
46 const BidirectionalStreamRequestInfo* request_info, 48 const BidirectionalStreamRequestInfo* request_info,
47 const BoundNetLog& net_log, 49 const BoundNetLog& net_log,
50 bool disable_auto_flush,
48 BidirectionalStreamImpl::Delegate* delegate, 51 BidirectionalStreamImpl::Delegate* delegate,
49 scoped_ptr<base::Timer> /* timer */) { 52 scoped_ptr<base::Timer> /* timer */) {
50 DCHECK(!stream_); 53 DCHECK(!stream_);
51 54
55 disable_auto_flush_ = disable_auto_flush;
52 if (!session_) { 56 if (!session_) {
53 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR 57 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR
54 : ERR_QUIC_HANDSHAKE_FAILED); 58 : ERR_QUIC_HANDSHAKE_FAILED);
55 return; 59 return;
56 } 60 }
57 61
58 delegate_ = delegate; 62 delegate_ = delegate;
59 request_info_ = request_info; 63 request_info_ = request_info;
60 64
61 int rv = stream_request_.StartRequest( 65 int rv = stream_request_.StartRequest(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, 109 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
106 weak_factory_.GetWeakPtr())); 110 weak_factory_.GetWeakPtr()));
107 DCHECK(rv == OK || rv == ERR_IO_PENDING); 111 DCHECK(rv == OK || rv == ERR_IO_PENDING);
108 if (rv == OK) { 112 if (rv == OK) {
109 base::ThreadTaskRunnerHandle::Get()->PostTask( 113 base::ThreadTaskRunnerHandle::Get()->PostTask(
110 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, 114 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
111 weak_factory_.GetWeakPtr(), OK)); 115 weak_factory_.GetWeakPtr(), OK));
112 } 116 }
113 } 117 }
114 118
119 void BidirectionalStreamQuicImpl::SendvData(
120 const std::vector<IOBuffer*>& buffers,
121 const std::vector<int>& lengths,
122 bool end_stream) {
123 DCHECK(stream_);
124 DCHECK_EQ(buffers.size(), lengths.size());
125
126 QuicConnection::ScopedPacketBundler bundler(
127 session_->connection(), QuicConnection::SEND_ACK_IF_PENDING);
128 if (!has_sent_headers_) {
129 SendRequestHeaders();
130 }
131
132 std::vector<base::StringPiece> input_buffers;
133 for (size_t i = 0; i < buffers.size(); ++i) {
134 base::StringPiece string_data(buffers[i]->data(), lengths[i]);
135 input_buffers.push_back(string_data);
Ryan Hamilton 2016/04/13 03:42:28 Instead of allocating a new std::vector with Strin
xunjieli 2016/04/13 14:53:15 Done. I got rid of the newly allocated std::vector
136 }
137
138 int rv = stream_->WritevStreamData(
139 input_buffers, end_stream,
140 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
141 weak_factory_.GetWeakPtr()));
142
143 DCHECK(rv == OK || rv == ERR_IO_PENDING);
144 if (rv == OK) {
145 base::ThreadTaskRunnerHandle::Get()->PostTask(
146 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
147 weak_factory_.GetWeakPtr(), OK));
148 }
149 }
150
115 void BidirectionalStreamQuicImpl::Cancel() { 151 void BidirectionalStreamQuicImpl::Cancel() {
116 if (stream_) { 152 if (stream_) {
117 stream_->SetDelegate(nullptr); 153 stream_->SetDelegate(nullptr);
118 stream_->Reset(QUIC_STREAM_CANCELLED); 154 stream_->Reset(QUIC_STREAM_CANCELLED);
119 ResetStream(); 155 ResetStream();
120 } 156 }
121 } 157 }
122 158
123 NextProto BidirectionalStreamQuicImpl::GetProtocol() const { 159 NextProto BidirectionalStreamQuicImpl::GetProtocol() const {
124 return negotiated_protocol_; 160 return negotiated_protocol_;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 DCHECK_NE(OK, error); 237 DCHECK_NE(OK, error);
202 session_.reset(); 238 session_.reset();
203 NotifyError(error); 239 NotifyError(error);
204 } 240 }
205 241
206 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { 242 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) {
207 DCHECK_NE(ERR_IO_PENDING, rv); 243 DCHECK_NE(ERR_IO_PENDING, rv);
208 DCHECK(rv == OK || !stream_); 244 DCHECK(rv == OK || !stream_);
209 if (rv == OK) { 245 if (rv == OK) {
210 stream_->SetDelegate(this); 246 stream_->SetDelegate(this);
211 SendRequestHeaders(); 247 if (!disable_auto_flush_) {
248 SendRequestHeaders();
249 }
250 delegate_->OnStreamReady();
212 } else { 251 } else {
213 NotifyError(rv); 252 NotifyError(rv);
214 } 253 }
215 } 254 }
216 255
217 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { 256 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) {
218 DCHECK(rv == OK || !stream_); 257 DCHECK(rv == OK || !stream_);
219 if (rv == OK) { 258 if (rv == OK) {
220 delegate_->OnDataSent(); 259 delegate_->OnDataSent();
221 } else { 260 } else {
(...skipping 11 matching lines...) Expand all
233 http_request_info.method = request_info_->method; 272 http_request_info.method = request_info_->method;
234 http_request_info.extra_headers = request_info_->extra_headers; 273 http_request_info.extra_headers = request_info_->extra_headers;
235 274
236 CreateSpdyHeadersFromHttpRequest(http_request_info, 275 CreateSpdyHeadersFromHttpRequest(http_request_info,
237 http_request_info.extra_headers, HTTP2, true, 276 http_request_info.extra_headers, HTTP2, true,
238 &headers); 277 &headers);
239 size_t frame_len = stream_->WriteHeaders( 278 size_t frame_len = stream_->WriteHeaders(
240 headers, request_info_->end_stream_on_headers, nullptr); 279 headers, request_info_->end_stream_on_headers, nullptr);
241 headers_bytes_sent_ += frame_len; 280 headers_bytes_sent_ += frame_len;
242 has_sent_headers_ = true; 281 has_sent_headers_ = true;
243 delegate_->OnHeadersSent();
244 } 282 }
245 283
246 void BidirectionalStreamQuicImpl::NotifyError(int error) { 284 void BidirectionalStreamQuicImpl::NotifyError(int error) {
247 DCHECK_NE(OK, error); 285 DCHECK_NE(OK, error);
248 DCHECK_NE(ERR_IO_PENDING, error); 286 DCHECK_NE(ERR_IO_PENDING, error);
249 287
250 response_status_ = error; 288 response_status_ = error;
251 ResetStream(); 289 ResetStream();
252 delegate_->OnFailed(error); 290 delegate_->OnFailed(error);
253 } 291 }
254 292
255 void BidirectionalStreamQuicImpl::ResetStream() { 293 void BidirectionalStreamQuicImpl::ResetStream() {
256 if (!stream_) 294 if (!stream_)
257 return; 295 return;
258 closed_stream_received_bytes_ = stream_->stream_bytes_read(); 296 closed_stream_received_bytes_ = stream_->stream_bytes_read();
259 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); 297 closed_stream_sent_bytes_ = stream_->stream_bytes_written();
260 stream_->SetDelegate(nullptr); 298 stream_->SetDelegate(nullptr);
261 stream_ = nullptr; 299 stream_ = nullptr;
262 } 300 }
263 301
264 } // namespace net 302 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698