OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/reliable_quic_stream.h" | 5 #include "net/quic/reliable_quic_stream.h" |
6 | 6 |
7 #include "net/quic/quic_session.h" | 7 #include "net/quic/quic_session.h" |
8 #include "net/quic/quic_spdy_decompressor.h" | 8 #include "net/quic/quic_spdy_decompressor.h" |
9 | 9 |
10 using base::StringPiece; | 10 using base::StringPiece; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 DLOG(INFO) << "Ignoring frame " << frame.stream_id; | 51 DLOG(INFO) << "Ignoring frame " << frame.stream_id; |
52 // We don't want to be reading: blackhole the data. | 52 // We don't want to be reading: blackhole the data. |
53 return true; | 53 return true; |
54 } | 54 } |
55 // Note: This count include duplicate data received. | 55 // Note: This count include duplicate data received. |
56 stream_bytes_read_ += frame.data.length(); | 56 stream_bytes_read_ += frame.data.length(); |
57 | 57 |
58 bool accepted = sequencer_.OnStreamFrame(frame); | 58 bool accepted = sequencer_.OnStreamFrame(frame); |
59 | 59 |
60 if (frame.fin) { | 60 if (frame.fin) { |
61 sequencer_.CloseStreamAtOffset(frame.offset + frame.data.size(), true); | 61 sequencer_.CloseStreamAtOffset(frame.offset + frame.data.size()); |
62 } | 62 } |
63 | 63 |
64 return accepted; | 64 return accepted; |
65 } | 65 } |
66 | 66 |
67 void ReliableQuicStream::OnStreamReset(QuicRstStreamErrorCode error) { | 67 void ReliableQuicStream::OnStreamReset(QuicRstStreamErrorCode error) { |
68 stream_error_ = error; | 68 stream_error_ = error; |
69 TerminateFromPeer(false); // Full close. | 69 TerminateFromPeer(false); // Full close. |
70 } | 70 } |
71 | 71 |
72 void ReliableQuicStream::ConnectionClose(QuicErrorCode error, bool from_peer) { | 72 void ReliableQuicStream::ConnectionClose(QuicErrorCode error, bool from_peer) { |
73 if (IsClosed()) { | 73 if (read_side_closed_ && write_side_closed_) { |
74 return; | 74 return; |
75 } | 75 } |
76 if (error != QUIC_NO_ERROR) { | 76 if (error != QUIC_NO_ERROR) { |
77 stream_error_ = QUIC_STREAM_CONNECTION_ERROR; | 77 stream_error_ = QUIC_STREAM_CONNECTION_ERROR; |
78 connection_error_ = error; | 78 connection_error_ = error; |
79 } | 79 } |
80 | 80 |
81 if (from_peer) { | 81 if (from_peer) { |
82 TerminateFromPeer(false); | 82 TerminateFromPeer(false); |
83 } else { | 83 } else { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return 1; | 136 return 1; |
137 } | 137 } |
138 | 138 |
139 bool ReliableQuicStream::IsHalfClosed() const { | 139 bool ReliableQuicStream::IsHalfClosed() const { |
140 if (!headers_decompressed_ || !decompressed_headers_.empty()) { | 140 if (!headers_decompressed_ || !decompressed_headers_.empty()) { |
141 return false; | 141 return false; |
142 } | 142 } |
143 return sequencer_.IsHalfClosed(); | 143 return sequencer_.IsHalfClosed(); |
144 } | 144 } |
145 | 145 |
146 bool ReliableQuicStream::IsClosed() const { | |
147 return write_side_closed_ && (read_side_closed_ || IsHalfClosed()); | |
148 } | |
149 | |
150 bool ReliableQuicStream::HasBytesToRead() const { | 146 bool ReliableQuicStream::HasBytesToRead() const { |
151 return !decompressed_headers_.empty() || sequencer_.HasBytesToRead(); | 147 return !decompressed_headers_.empty() || sequencer_.HasBytesToRead(); |
152 } | 148 } |
153 | 149 |
154 const IPEndPoint& ReliableQuicStream::GetPeerAddress() const { | 150 const IPEndPoint& ReliableQuicStream::GetPeerAddress() const { |
155 return session_->peer_address(); | 151 return session_->peer_address(); |
156 } | 152 } |
157 | 153 |
158 QuicSpdyCompressor* ReliableQuicStream::compressor() { | 154 QuicSpdyCompressor* ReliableQuicStream::compressor() { |
159 return session_->compressor(); | 155 return session_->compressor(); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 StringPiece(static_cast<char*>(iovecs[i].iov_base), | 353 StringPiece(static_cast<char*>(iovecs[i].iov_base), |
358 iovecs[i].iov_len), this); | 354 iovecs[i].iov_len), this); |
359 | 355 |
360 headers_decompressed_ = | 356 headers_decompressed_ = |
361 session_->decompressor()->current_header_id() != headers_id_; | 357 session_->decompressor()->current_header_id() != headers_id_; |
362 } | 358 } |
363 } | 359 } |
364 | 360 |
365 // Either the headers are complete, or the all data as been consumed. | 361 // Either the headers are complete, or the all data as been consumed. |
366 sequencer_.MarkConsumed(total_bytes_consumed); | 362 sequencer_.MarkConsumed(total_bytes_consumed); |
367 | |
368 ProcessHeaderData(); // Unprocessed headers remain in decompressed_headers_. | 363 ProcessHeaderData(); // Unprocessed headers remain in decompressed_headers_. |
369 | 364 if (IsHalfClosed()) { |
370 if (headers_decompressed_ && decompressed_headers_.empty()) { | 365 TerminateFromPeer(true); |
| 366 } else if (headers_decompressed_ && decompressed_headers_.empty()) { |
371 sequencer_.FlushBufferedFrames(); | 367 sequencer_.FlushBufferedFrames(); |
372 } | 368 } |
373 } | 369 } |
374 | 370 |
375 bool ReliableQuicStream::OnDecompressedData(StringPiece data) { | 371 bool ReliableQuicStream::OnDecompressedData(StringPiece data) { |
376 data.AppendToString(&decompressed_headers_); | 372 data.AppendToString(&decompressed_headers_); |
377 return true; | 373 return true; |
378 } | 374 } |
379 | 375 |
380 void ReliableQuicStream::OnDecompressionError() { | 376 void ReliableQuicStream::OnDecompressionError() { |
(...skipping 21 matching lines...) Expand all Loading... |
402 if (visitor_) { | 398 if (visitor_) { |
403 Visitor* visitor = visitor_; | 399 Visitor* visitor = visitor_; |
404 // Calling Visitor::OnClose() may result the destruction of the visitor, | 400 // Calling Visitor::OnClose() may result the destruction of the visitor, |
405 // so we need to ensure we don't call it again. | 401 // so we need to ensure we don't call it again. |
406 visitor_ = NULL; | 402 visitor_ = NULL; |
407 visitor->OnClose(this); | 403 visitor->OnClose(this); |
408 } | 404 } |
409 } | 405 } |
410 | 406 |
411 } // namespace net | 407 } // namespace net |
OLD | NEW |