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

Side by Side Diff: net/spdy/bidirectional_stream_spdy_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, 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 unified diff | Download patch
« no previous file with comments | « net/spdy/bidirectional_stream_spdy_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/spdy/bidirectional_stream_spdy_impl.h" 5 #include "net/spdy/bidirectional_stream_spdy_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/time/time.h" 10 #include "base/time/time.h"
(...skipping 20 matching lines...) Expand all
31 : spdy_session_(spdy_session), 31 : spdy_session_(spdy_session),
32 request_info_(nullptr), 32 request_info_(nullptr),
33 delegate_(nullptr), 33 delegate_(nullptr),
34 negotiated_protocol_(kProtoUnknown), 34 negotiated_protocol_(kProtoUnknown),
35 more_read_data_pending_(false), 35 more_read_data_pending_(false),
36 read_buffer_len_(0), 36 read_buffer_len_(0),
37 stream_closed_(false), 37 stream_closed_(false),
38 closed_stream_status_(ERR_FAILED), 38 closed_stream_status_(ERR_FAILED),
39 closed_stream_received_bytes_(0), 39 closed_stream_received_bytes_(0),
40 closed_stream_sent_bytes_(0), 40 closed_stream_sent_bytes_(0),
41 disable_auto_flush_(false),
41 weak_factory_(this) {} 42 weak_factory_(this) {}
42 43
43 BidirectionalStreamSpdyImpl::~BidirectionalStreamSpdyImpl() { 44 BidirectionalStreamSpdyImpl::~BidirectionalStreamSpdyImpl() {
44 if (stream_) { 45 if (stream_) {
45 stream_->DetachDelegate(); 46 stream_->DetachDelegate();
46 DCHECK(!stream_); 47 DCHECK(!stream_);
47 } 48 }
48 } 49 }
49 50
50 void BidirectionalStreamSpdyImpl::Start( 51 void BidirectionalStreamSpdyImpl::Start(
51 const BidirectionalStreamRequestInfo* request_info, 52 const BidirectionalStreamRequestInfo* request_info,
52 const BoundNetLog& net_log, 53 const BoundNetLog& net_log,
54 bool disable_auto_flush,
53 BidirectionalStreamImpl::Delegate* delegate, 55 BidirectionalStreamImpl::Delegate* delegate,
54 std::unique_ptr<base::Timer> timer) { 56 std::unique_ptr<base::Timer> timer) {
55 DCHECK(!stream_); 57 DCHECK(!stream_);
56 DCHECK(timer); 58 DCHECK(timer);
57 59
60 disable_auto_flush_ = disable_auto_flush;
58 delegate_ = delegate; 61 delegate_ = delegate;
59 timer_ = std::move(timer); 62 timer_ = std::move(timer);
60 63
61 if (!spdy_session_) { 64 if (!spdy_session_) {
62 delegate_->OnFailed(ERR_CONNECTION_CLOSED); 65 delegate_->OnFailed(ERR_CONNECTION_CLOSED);
63 return; 66 return;
64 } 67 }
65 68
66 request_info_ = request_info; 69 request_info_ = request_info;
67 70
(...skipping 25 matching lines...) Expand all
93 read_buffer_ = buf; 96 read_buffer_ = buf;
94 read_buffer_len_ = buf_len; 97 read_buffer_len_ = buf_len;
95 return ERR_IO_PENDING; 98 return ERR_IO_PENDING;
96 } 99 }
97 100
98 void BidirectionalStreamSpdyImpl::SendData(IOBuffer* data, 101 void BidirectionalStreamSpdyImpl::SendData(IOBuffer* data,
99 int length, 102 int length,
100 bool end_stream) { 103 bool end_stream) {
101 DCHECK(!stream_closed_); 104 DCHECK(!stream_closed_);
102 DCHECK(stream_); 105 DCHECK(stream_);
106 DCHECK(!disable_auto_flush_);
103 107
104 stream_->SendData(data, length, 108 stream_->SendData(data, length,
105 end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); 109 end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND);
106 } 110 }
107 111
112 void BidirectionalStreamSpdyImpl::SendvData(
113 const std::vector<IOBuffer*>& buffers,
114 const std::vector<int>& lengths,
115 bool end_stream) {
116 DCHECK(!stream_closed_);
117 DCHECK(stream_);
118 DCHECK(disable_auto_flush_);
119 DCHECK_EQ(buffers.size(), lengths.size());
120
121 int total_len = 0;
122 for (int len : lengths) {
123 total_len += len;
124 }
125
126 pending_combined_buffer_ = new net::IOBuffer(total_len);
127 int len = 0;
128 // TODO(xunjieli): Get rid of extra copy. Coalesce headers and data frames.
129 for (size_t i = 0; i < buffers.size(); ++i) {
130 memcpy(pending_combined_buffer_->data() + len, buffers[i]->data(),
131 lengths[i]);
132 len += lengths[i];
133 }
134 stream_->SendData(pending_combined_buffer_.get(), total_len,
135 end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND);
136 }
137
108 void BidirectionalStreamSpdyImpl::Cancel() { 138 void BidirectionalStreamSpdyImpl::Cancel() {
109 if (!stream_) 139 if (!stream_)
110 return; 140 return;
111 // Cancels the stream and detaches the delegate so it doesn't get called back. 141 // Cancels the stream and detaches the delegate so it doesn't get called back.
112 stream_->DetachDelegate(); 142 stream_->DetachDelegate();
113 DCHECK(!stream_); 143 DCHECK(!stream_);
114 } 144 }
115 145
116 NextProto BidirectionalStreamSpdyImpl::GetProtocol() const { 146 NextProto BidirectionalStreamSpdyImpl::GetProtocol() const {
117 return negotiated_protocol_; 147 return negotiated_protocol_;
(...skipping 16 matching lines...) Expand all
134 if (!stream_) 164 if (!stream_)
135 return 0; 165 return 0;
136 166
137 return stream_->raw_sent_bytes(); 167 return stream_->raw_sent_bytes();
138 } 168 }
139 169
140 void BidirectionalStreamSpdyImpl::OnRequestHeadersSent() { 170 void BidirectionalStreamSpdyImpl::OnRequestHeadersSent() {
141 DCHECK(stream_); 171 DCHECK(stream_);
142 172
143 negotiated_protocol_ = stream_->GetProtocol(); 173 negotiated_protocol_ = stream_->GetProtocol();
144 delegate_->OnHeadersSent();
145 } 174 }
146 175
147 SpdyResponseHeadersStatus BidirectionalStreamSpdyImpl::OnResponseHeadersUpdated( 176 SpdyResponseHeadersStatus BidirectionalStreamSpdyImpl::OnResponseHeadersUpdated(
148 const SpdyHeaderBlock& response_headers) { 177 const SpdyHeaderBlock& response_headers) {
149 DCHECK(stream_); 178 DCHECK(stream_);
150 179
151 delegate_->OnHeadersReceived(response_headers); 180 delegate_->OnHeadersReceived(response_headers);
152 return RESPONSE_HEADERS_ARE_COMPLETE; 181 return RESPONSE_HEADERS_ARE_COMPLETE;
153 } 182 }
154 183
(...skipping 14 matching lines...) Expand all
169 // Handing small chunks of data to the caller creates measurable overhead. 198 // Handing small chunks of data to the caller creates measurable overhead.
170 // So buffer data in short time-spans and send a single read notification. 199 // So buffer data in short time-spans and send a single read notification.
171 ScheduleBufferedRead(); 200 ScheduleBufferedRead();
172 } 201 }
173 } 202 }
174 203
175 void BidirectionalStreamSpdyImpl::OnDataSent() { 204 void BidirectionalStreamSpdyImpl::OnDataSent() {
176 DCHECK(stream_); 205 DCHECK(stream_);
177 DCHECK(!stream_closed_); 206 DCHECK(!stream_closed_);
178 207
208 if (disable_auto_flush_) {
209 DCHECK(pending_combined_buffer_);
210 pending_combined_buffer_ = nullptr;
211 }
179 delegate_->OnDataSent(); 212 delegate_->OnDataSent();
180 } 213 }
181 214
182 void BidirectionalStreamSpdyImpl::OnTrailers(const SpdyHeaderBlock& trailers) { 215 void BidirectionalStreamSpdyImpl::OnTrailers(const SpdyHeaderBlock& trailers) {
183 DCHECK(stream_); 216 DCHECK(stream_);
184 DCHECK(!stream_closed_); 217 DCHECK(!stream_closed_);
185 218
186 delegate_->OnTrailersReceived(trailers); 219 delegate_->OnTrailersReceived(trailers);
187 } 220 }
188 221
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 ? NO_MORE_DATA_TO_SEND 254 ? NO_MORE_DATA_TO_SEND
222 : MORE_DATA_TO_SEND); 255 : MORE_DATA_TO_SEND);
223 } 256 }
224 257
225 void BidirectionalStreamSpdyImpl::OnStreamInitialized(int rv) { 258 void BidirectionalStreamSpdyImpl::OnStreamInitialized(int rv) {
226 DCHECK_NE(ERR_IO_PENDING, rv); 259 DCHECK_NE(ERR_IO_PENDING, rv);
227 if (rv == OK) { 260 if (rv == OK) {
228 stream_ = stream_request_.ReleaseStream(); 261 stream_ = stream_request_.ReleaseStream();
229 stream_->SetDelegate(this); 262 stream_->SetDelegate(this);
230 SendRequestHeaders(); 263 SendRequestHeaders();
264 delegate_->OnStreamReady();
231 return; 265 return;
232 } 266 }
233 delegate_->OnFailed(rv); 267 delegate_->OnFailed(rv);
234 } 268 }
235 269
236 void BidirectionalStreamSpdyImpl::ScheduleBufferedRead() { 270 void BidirectionalStreamSpdyImpl::ScheduleBufferedRead() {
237 // If there is already a scheduled DoBufferedRead, don't issue 271 // If there is already a scheduled DoBufferedRead, don't issue
238 // another one. Mark that we have received more data and return. 272 // another one. Mark that we have received more data and return.
239 if (timer_->IsRunning()) { 273 if (timer_->IsRunning()) {
240 more_read_data_pending_ = true; 274 more_read_data_pending_ = true;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 306
273 bool BidirectionalStreamSpdyImpl::ShouldWaitForMoreBufferedData() const { 307 bool BidirectionalStreamSpdyImpl::ShouldWaitForMoreBufferedData() const {
274 if (stream_closed_) 308 if (stream_closed_)
275 return false; 309 return false;
276 DCHECK_GT(read_buffer_len_, 0); 310 DCHECK_GT(read_buffer_len_, 0);
277 return read_data_queue_.GetTotalSize() < 311 return read_data_queue_.GetTotalSize() <
278 static_cast<size_t>(read_buffer_len_); 312 static_cast<size_t>(read_buffer_len_);
279 } 313 }
280 314
281 } // namespace net 315 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/bidirectional_stream_spdy_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698