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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 void ReliableQuicStream::TerminateFromPeer(bool half_close) { | 89 void ReliableQuicStream::TerminateFromPeer(bool half_close) { |
90 if (!half_close) { | 90 if (!half_close) { |
91 CloseWriteSide(); | 91 CloseWriteSide(); |
92 } | 92 } |
93 CloseReadSide(); | 93 CloseReadSide(); |
94 } | 94 } |
95 | 95 |
96 void ReliableQuicStream::Close(QuicRstStreamErrorCode error) { | 96 void ReliableQuicStream::Close(QuicRstStreamErrorCode error) { |
97 stream_error_ = error; | 97 stream_error_ = error; |
98 session()->SendRstStream(id(), error); | 98 if (error != QUIC_STREAM_NO_ERROR) { |
| 99 // Sending a RstStream results in calling CloseStream. |
| 100 session()->SendRstStream(id(), error); |
| 101 } else { |
| 102 session_->CloseStream(id()); |
| 103 } |
99 } | 104 } |
100 | 105 |
101 int ReliableQuicStream::Readv(const struct iovec* iov, size_t iov_len) { | 106 int ReliableQuicStream::Readv(const struct iovec* iov, size_t iov_len) { |
102 if (headers_decompressed_ && decompressed_headers_.empty()) { | 107 if (headers_decompressed_ && decompressed_headers_.empty()) { |
103 return sequencer_.Readv(iov, iov_len); | 108 return sequencer_.Readv(iov, iov_len); |
104 } | 109 } |
105 size_t bytes_consumed = 0; | 110 size_t bytes_consumed = 0; |
106 size_t iov_index = 0; | 111 size_t iov_index = 0; |
107 while (iov_index < iov_len && | 112 while (iov_index < iov_len && |
108 decompressed_headers_.length() > bytes_consumed) { | 113 decompressed_headers_.length() > bytes_consumed) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 153 |
149 const IPEndPoint& ReliableQuicStream::GetPeerAddress() const { | 154 const IPEndPoint& ReliableQuicStream::GetPeerAddress() const { |
150 return session_->peer_address(); | 155 return session_->peer_address(); |
151 } | 156 } |
152 | 157 |
153 QuicSpdyCompressor* ReliableQuicStream::compressor() { | 158 QuicSpdyCompressor* ReliableQuicStream::compressor() { |
154 return session_->compressor(); | 159 return session_->compressor(); |
155 } | 160 } |
156 | 161 |
157 QuicConsumedData ReliableQuicStream::WriteData(StringPiece data, bool fin) { | 162 QuicConsumedData ReliableQuicStream::WriteData(StringPiece data, bool fin) { |
| 163 DCHECK(data.size() > 0 || fin); |
158 return WriteOrBuffer(data, fin); | 164 return WriteOrBuffer(data, fin); |
159 } | 165 } |
160 | 166 |
161 QuicConsumedData ReliableQuicStream::WriteOrBuffer(StringPiece data, bool fin) { | 167 QuicConsumedData ReliableQuicStream::WriteOrBuffer(StringPiece data, bool fin) { |
162 DCHECK(!fin_buffered_); | 168 DCHECK(!fin_buffered_); |
163 | 169 |
164 QuicConsumedData consumed_data(0, false); | 170 QuicConsumedData consumed_data(0, false); |
165 fin_buffered_ = fin; | 171 fin_buffered_ = fin; |
166 | 172 |
167 if (queued_data_.empty()) { | 173 if (queued_data_.empty()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 return QuicConsumedData(0, false); | 211 return QuicConsumedData(0, false); |
206 } | 212 } |
207 | 213 |
208 QuicConsumedData consumed_data = | 214 QuicConsumedData consumed_data = |
209 session()->WriteData(id(), data, stream_bytes_written_, fin); | 215 session()->WriteData(id(), data, stream_bytes_written_, fin); |
210 stream_bytes_written_ += consumed_data.bytes_consumed; | 216 stream_bytes_written_ += consumed_data.bytes_consumed; |
211 if (consumed_data.bytes_consumed == data.length()) { | 217 if (consumed_data.bytes_consumed == data.length()) { |
212 if (fin && consumed_data.fin_consumed) { | 218 if (fin && consumed_data.fin_consumed) { |
213 fin_sent_ = true; | 219 fin_sent_ = true; |
214 CloseWriteSide(); | 220 CloseWriteSide(); |
| 221 } else if (fin && !consumed_data.fin_consumed) { |
| 222 session_->MarkWriteBlocked(id()); |
215 } | 223 } |
216 } else { | 224 } else { |
217 session_->MarkWriteBlocked(id()); | 225 session_->MarkWriteBlocked(id()); |
218 } | 226 } |
219 return consumed_data; | 227 return consumed_data; |
220 } | 228 } |
221 | 229 |
222 void ReliableQuicStream::CloseReadSide() { | 230 void ReliableQuicStream::CloseReadSide() { |
223 if (read_side_closed_) { | 231 if (read_side_closed_) { |
224 return; | 232 return; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 if (visitor_) { | 402 if (visitor_) { |
395 Visitor* visitor = visitor_; | 403 Visitor* visitor = visitor_; |
396 // Calling Visitor::OnClose() may result the destruction of the visitor, | 404 // Calling Visitor::OnClose() may result the destruction of the visitor, |
397 // so we need to ensure we don't call it again. | 405 // so we need to ensure we don't call it again. |
398 visitor_ = NULL; | 406 visitor_ = NULL; |
399 visitor->OnClose(this); | 407 visitor->OnClose(this); |
400 } | 408 } |
401 } | 409 } |
402 | 410 |
403 } // namespace net | 411 } // namespace net |
OLD | NEW |