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