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

Side by Side Diff: net/quic/core/quic_spdy_stream.cc

Issue 2487613002: Landing Recent QUIC changes until 12:43 PM, Nov 5, 2016 UTC+8 (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_spdy_stream.h ('k') | net/quic/core/quic_spdy_stream_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/core/quic_spdy_stream.h" 5 #include "net/quic/core/quic_spdy_stream.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "net/quic/core/quic_bug_tracker.h" 11 #include "net/quic/core/quic_bug_tracker.h"
12 #include "net/quic/core/quic_spdy_session.h" 12 #include "net/quic/core/quic_spdy_session.h"
13 #include "net/quic/core/quic_utils.h" 13 #include "net/quic/core/quic_utils.h"
14 #include "net/quic/core/quic_write_blocked_list.h" 14 #include "net/quic/core/quic_write_blocked_list.h"
15 #include "net/quic/core/spdy_utils.h" 15 #include "net/quic/core/spdy_utils.h"
16 16
17 using base::IntToString; 17 using base::IntToString;
18 using base::StringPiece; 18 using base::StringPiece;
19 using std::min; 19 using std::min;
20 using std::string; 20 using std::string;
21 21
22 namespace net { 22 namespace net {
23 23
24 #define ENDPOINT \ 24 #define ENDPOINT \
25 (session()->perspective() == Perspective::IS_SERVER ? "Server: " : "Client:" \ 25 (session()->perspective() == Perspective::IS_SERVER ? "Server: " : "Client:" \
26 " ") 26 " ")
27 27
28 QuicSpdyStream::QuicSpdyStream(QuicStreamId id, QuicSpdySession* spdy_session) 28 QuicSpdyStream::QuicSpdyStream(QuicStreamId id, QuicSpdySession* spdy_session)
29 : ReliableQuicStream(id, spdy_session), 29 : QuicStream(id, spdy_session),
30 spdy_session_(spdy_session), 30 spdy_session_(spdy_session),
31 visitor_(nullptr), 31 visitor_(nullptr),
32 allow_bidirectional_data_(false), 32 allow_bidirectional_data_(false),
33 headers_decompressed_(false), 33 headers_decompressed_(false),
34 priority_(kDefaultPriority), 34 priority_(kDefaultPriority),
35 trailers_decompressed_(false), 35 trailers_decompressed_(false),
36 trailers_consumed_(false) { 36 trailers_consumed_(false) {
37 DCHECK_NE(kCryptoStreamId, id); 37 DCHECK_NE(kCryptoStreamId, id);
38 // Don't receive any callbacks from the sequencer until headers 38 // Don't receive any callbacks from the sequencer until headers
39 // are complete. 39 // are complete.
40 sequencer()->SetBlockedUntilFlush(); 40 sequencer()->SetBlockedUntilFlush();
41 spdy_session_->RegisterStreamPriority(id, priority_); 41 spdy_session_->RegisterStreamPriority(id, priority_);
42 } 42 }
43 43
44 QuicSpdyStream::~QuicSpdyStream() { 44 QuicSpdyStream::~QuicSpdyStream() {
45 if (spdy_session_ != nullptr) { 45 if (spdy_session_ != nullptr) {
46 spdy_session_->UnregisterStreamPriority(id()); 46 spdy_session_->UnregisterStreamPriority(id());
47 } 47 }
48 } 48 }
49 49
50 void QuicSpdyStream::CloseWriteSide() { 50 void QuicSpdyStream::CloseWriteSide() {
51 if (!fin_received() && !rst_received() && sequencer()->ignore_read_data() && 51 if (!fin_received() && !rst_received() && sequencer()->ignore_read_data() &&
52 !rst_sent()) { 52 !rst_sent()) {
53 DCHECK(fin_sent()); 53 DCHECK(fin_sent());
54 // Tell the peer to stop sending further data. 54 // Tell the peer to stop sending further data.
55 DVLOG(1) << ENDPOINT << "Send QUIC_STREAM_NO_ERROR on stream " << id(); 55 DVLOG(1) << ENDPOINT << "Send QUIC_STREAM_NO_ERROR on stream " << id();
56 Reset(QUIC_STREAM_NO_ERROR); 56 Reset(QUIC_STREAM_NO_ERROR);
57 } 57 }
58 58
59 ReliableQuicStream::CloseWriteSide(); 59 QuicStream::CloseWriteSide();
60 } 60 }
61 61
62 void QuicSpdyStream::StopReading() { 62 void QuicSpdyStream::StopReading() {
63 if (!fin_received() && !rst_received() && write_side_closed() && 63 if (!fin_received() && !rst_received() && write_side_closed() &&
64 !rst_sent()) { 64 !rst_sent()) {
65 DCHECK(fin_sent()); 65 DCHECK(fin_sent());
66 // Tell the peer to stop sending further data. 66 // Tell the peer to stop sending further data.
67 DVLOG(1) << ENDPOINT << "Send QUIC_STREAM_NO_ERROR on stream " << id(); 67 DVLOG(1) << ENDPOINT << "Send QUIC_STREAM_NO_ERROR on stream " << id();
68 Reset(QUIC_STREAM_NO_ERROR); 68 Reset(QUIC_STREAM_NO_ERROR);
69 } 69 }
70 ReliableQuicStream::StopReading(); 70 QuicStream::StopReading();
71 } 71 }
72 72
73 size_t QuicSpdyStream::WriteHeaders( 73 size_t QuicSpdyStream::WriteHeaders(
74 SpdyHeaderBlock header_block, 74 SpdyHeaderBlock header_block,
75 bool fin, 75 bool fin,
76 QuicAckListenerInterface* ack_notifier_delegate) { 76 QuicAckListenerInterface* ack_notifier_delegate) {
77 size_t bytes_written = spdy_session_->WriteHeaders( 77 size_t bytes_written = spdy_session_->WriteHeaders(
78 id(), std::move(header_block), fin, priority_, ack_notifier_delegate); 78 id(), std::move(header_block), fin, priority_, ack_notifier_delegate);
79 if (fin) { 79 if (fin) {
80 // TODO(rch): Add test to ensure fin_sent_ is set whenever a fin is sent. 80 // TODO(rch): Add test to ensure fin_sent_ is set whenever a fin is sent.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 QUIC_INVALID_HEADERS_STREAM_DATA, "Trailers are malformed", 251 QUIC_INVALID_HEADERS_STREAM_DATA, "Trailers are malformed",
252 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); 252 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
253 return; 253 return;
254 } 254 }
255 trailers_decompressed_ = true; 255 trailers_decompressed_ = true;
256 OnStreamFrame(QuicStreamFrame(id(), fin, final_byte_offset, StringPiece())); 256 OnStreamFrame(QuicStreamFrame(id(), fin, final_byte_offset, StringPiece()));
257 } 257 }
258 258
259 void QuicSpdyStream::OnStreamReset(const QuicRstStreamFrame& frame) { 259 void QuicSpdyStream::OnStreamReset(const QuicRstStreamFrame& frame) {
260 if (frame.error_code != QUIC_STREAM_NO_ERROR) { 260 if (frame.error_code != QUIC_STREAM_NO_ERROR) {
261 ReliableQuicStream::OnStreamReset(frame); 261 QuicStream::OnStreamReset(frame);
262 return; 262 return;
263 } 263 }
264 DVLOG(1) << "Received QUIC_STREAM_NO_ERROR, not discarding response"; 264 DVLOG(1) << "Received QUIC_STREAM_NO_ERROR, not discarding response";
265 set_rst_received(true); 265 set_rst_received(true);
266 MaybeIncreaseHighestReceivedOffset(frame.byte_offset); 266 MaybeIncreaseHighestReceivedOffset(frame.byte_offset);
267 set_stream_error(frame.error_code); 267 set_stream_error(frame.error_code);
268 CloseWriteSide(); 268 CloseWriteSide();
269 } 269 }
270 270
271 void QuicSpdyStream::OnClose() { 271 void QuicSpdyStream::OnClose() {
272 ReliableQuicStream::OnClose(); 272 QuicStream::OnClose();
273 273
274 if (visitor_) { 274 if (visitor_) {
275 Visitor* visitor = visitor_; 275 Visitor* visitor = visitor_;
276 // Calling Visitor::OnClose() may result the destruction of the visitor, 276 // Calling Visitor::OnClose() may result the destruction of the visitor,
277 // so we need to ensure we don't call it again. 277 // so we need to ensure we don't call it again.
278 visitor_ = nullptr; 278 visitor_ = nullptr;
279 visitor->OnClose(this); 279 visitor->OnClose(this);
280 } 280 }
281 } 281 }
282 282
283 void QuicSpdyStream::OnCanWrite() { 283 void QuicSpdyStream::OnCanWrite() {
284 ReliableQuicStream::OnCanWrite(); 284 QuicStream::OnCanWrite();
285 285
286 // Trailers (and hence a FIN) may have been sent ahead of queued body bytes. 286 // Trailers (and hence a FIN) may have been sent ahead of queued body bytes.
287 if (!HasBufferedData() && fin_sent()) { 287 if (!HasBufferedData() && fin_sent()) {
288 CloseWriteSide(); 288 CloseWriteSide();
289 } 289 }
290 } 290 }
291 291
292 bool QuicSpdyStream::FinishedReadingHeaders() const { 292 bool QuicSpdyStream::FinishedReadingHeaders() const {
293 return headers_decompressed_ && header_list_.empty(); 293 return headers_decompressed_ && header_list_.empty();
294 } 294 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 QuicConsumedData QuicSpdyStream::WritevDataInner( 337 QuicConsumedData QuicSpdyStream::WritevDataInner(
338 QuicIOVector iov, 338 QuicIOVector iov,
339 QuicStreamOffset offset, 339 QuicStreamOffset offset,
340 bool fin, 340 bool fin,
341 QuicAckListenerInterface* ack_notifier_delegate) { 341 QuicAckListenerInterface* ack_notifier_delegate) {
342 if (spdy_session_->headers_stream() != nullptr && 342 if (spdy_session_->headers_stream() != nullptr &&
343 spdy_session_->force_hol_blocking()) { 343 spdy_session_->force_hol_blocking()) {
344 return spdy_session_->headers_stream()->WritevStreamData( 344 return spdy_session_->headers_stream()->WritevStreamData(
345 id(), iov, offset, fin, ack_notifier_delegate); 345 id(), iov, offset, fin, ack_notifier_delegate);
346 } 346 }
347 return ReliableQuicStream::WritevDataInner(iov, offset, fin, 347 return QuicStream::WritevDataInner(iov, offset, fin, ack_notifier_delegate);
348 ack_notifier_delegate);
349 } 348 }
350 349
351 } // namespace net 350 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_spdy_stream.h ('k') | net/quic/core/quic_spdy_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698