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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/quic/iovector.h" | 8 #include "net/quic/iovector.h" |
9 #include "net/quic/quic_bug_tracker.h" | 9 #include "net/quic/quic_bug_tracker.h" |
10 #include "net/quic/quic_flags.h" | 10 #include "net/quic/quic_flags.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 stream_bytes_written_(0), | 59 stream_bytes_written_(0), |
60 stream_error_(QUIC_STREAM_NO_ERROR), | 60 stream_error_(QUIC_STREAM_NO_ERROR), |
61 connection_error_(QUIC_NO_ERROR), | 61 connection_error_(QUIC_NO_ERROR), |
62 read_side_closed_(false), | 62 read_side_closed_(false), |
63 write_side_closed_(false), | 63 write_side_closed_(false), |
64 fin_buffered_(false), | 64 fin_buffered_(false), |
65 fin_sent_(false), | 65 fin_sent_(false), |
66 fin_received_(false), | 66 fin_received_(false), |
67 rst_sent_(false), | 67 rst_sent_(false), |
68 rst_received_(false), | 68 rst_received_(false), |
69 fec_policy_(FEC_PROTECT_OPTIONAL), | |
70 perspective_(session_->perspective()), | 69 perspective_(session_->perspective()), |
71 flow_controller_(session_->connection(), | 70 flow_controller_(session_->connection(), |
72 id_, | 71 id_, |
73 perspective_, | 72 perspective_, |
74 GetReceivedFlowControlWindow(session), | 73 GetReceivedFlowControlWindow(session), |
75 GetInitialStreamFlowControlWindowToSend(session), | 74 GetInitialStreamFlowControlWindowToSend(session), |
76 session_->flow_controller()->auto_tune_receive_window()), | 75 session_->flow_controller()->auto_tune_receive_window()), |
77 connection_flow_controller_(session_->flow_controller()), | 76 connection_flow_controller_(session_->flow_controller()), |
78 stream_contributes_to_connection_flow_control_(true) { | 77 stream_contributes_to_connection_flow_control_(true) { |
79 SetFromConfig(); | 78 SetFromConfig(); |
80 } | 79 } |
81 | 80 |
82 ReliableQuicStream::~ReliableQuicStream() {} | 81 ReliableQuicStream::~ReliableQuicStream() {} |
83 | 82 |
84 void ReliableQuicStream::SetFromConfig() { | 83 void ReliableQuicStream::SetFromConfig() {} |
85 if (session_->config()->HasClientSentConnectionOption(kFSTR, perspective_)) { | |
86 fec_policy_ = FEC_PROTECT_ALWAYS; | |
87 } | |
88 } | |
89 | 84 |
90 void ReliableQuicStream::OnStreamFrame(const QuicStreamFrame& frame) { | 85 void ReliableQuicStream::OnStreamFrame(const QuicStreamFrame& frame) { |
91 DCHECK_EQ(frame.stream_id, id_); | 86 DCHECK_EQ(frame.stream_id, id_); |
92 | 87 |
93 DCHECK(!(read_side_closed_ && write_side_closed_)); | 88 DCHECK(!(read_side_closed_ && write_side_closed_)); |
94 | 89 |
95 if (frame.fin) { | 90 if (frame.fin) { |
96 fin_received_ = true; | 91 fin_received_ = true; |
97 if (fin_sent_) { | 92 if (fin_sent_) { |
98 session_->StreamDraining(id_); | 93 session_->StreamDraining(id_); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 299 } |
305 | 300 |
306 if (write_length > send_window) { | 301 if (write_length > send_window) { |
307 // Don't send the FIN unless all the data will be sent. | 302 // Don't send the FIN unless all the data will be sent. |
308 fin = false; | 303 fin = false; |
309 | 304 |
310 // Writing more data would be a violation of flow control. | 305 // Writing more data would be a violation of flow control. |
311 write_length = static_cast<size_t>(send_window); | 306 write_length = static_cast<size_t>(send_window); |
312 } | 307 } |
313 | 308 |
314 QuicConsumedData consumed_data = session()->WritevData( | 309 QuicConsumedData consumed_data = |
315 id(), QuicIOVector(iov, iov_count, write_length), stream_bytes_written_, | 310 session()->WritevData(id(), QuicIOVector(iov, iov_count, write_length), |
316 fin, GetFecProtection(), ack_listener); | 311 stream_bytes_written_, fin, ack_listener); |
317 stream_bytes_written_ += consumed_data.bytes_consumed; | 312 stream_bytes_written_ += consumed_data.bytes_consumed; |
318 | 313 |
319 AddBytesSent(consumed_data.bytes_consumed); | 314 AddBytesSent(consumed_data.bytes_consumed); |
320 | 315 |
321 // The write may have generated a write error causing this stream to be | 316 // The write may have generated a write error causing this stream to be |
322 // closed. If so, simply return without marking the stream write blocked. | 317 // closed. If so, simply return without marking the stream write blocked. |
323 if (write_side_closed_) { | 318 if (write_side_closed_) { |
324 return consumed_data; | 319 return consumed_data; |
325 } | 320 } |
326 | 321 |
327 if (consumed_data.bytes_consumed == write_length) { | 322 if (consumed_data.bytes_consumed == write_length) { |
328 if (!fin_with_zero_data) { | 323 if (!fin_with_zero_data) { |
329 MaybeSendBlocked(); | 324 MaybeSendBlocked(); |
330 } | 325 } |
331 if (fin && consumed_data.fin_consumed) { | 326 if (fin && consumed_data.fin_consumed) { |
332 fin_sent_ = true; | 327 fin_sent_ = true; |
333 if (fin_received_) { | 328 if (fin_received_) { |
334 session_->StreamDraining(id_); | 329 session_->StreamDraining(id_); |
335 } | 330 } |
336 CloseWriteSide(); | 331 CloseWriteSide(); |
337 } else if (fin && !consumed_data.fin_consumed) { | 332 } else if (fin && !consumed_data.fin_consumed) { |
338 session_->MarkConnectionLevelWriteBlocked(id()); | 333 session_->MarkConnectionLevelWriteBlocked(id()); |
339 } | 334 } |
340 } else { | 335 } else { |
341 session_->MarkConnectionLevelWriteBlocked(id()); | 336 session_->MarkConnectionLevelWriteBlocked(id()); |
342 } | 337 } |
343 return consumed_data; | 338 return consumed_data; |
344 } | 339 } |
345 | 340 |
346 FecProtection ReliableQuicStream::GetFecProtection() { | |
347 return fec_policy_ == FEC_PROTECT_ALWAYS ? MUST_FEC_PROTECT : MAY_FEC_PROTECT; | |
348 } | |
349 | |
350 void ReliableQuicStream::CloseReadSide() { | 341 void ReliableQuicStream::CloseReadSide() { |
351 if (read_side_closed_) { | 342 if (read_side_closed_) { |
352 return; | 343 return; |
353 } | 344 } |
354 DVLOG(1) << ENDPOINT << "Done reading from stream " << id(); | 345 DVLOG(1) << ENDPOINT << "Done reading from stream " << id(); |
355 | 346 |
356 read_side_closed_ = true; | 347 read_side_closed_ = true; |
357 if (write_side_closed_) { | 348 if (write_side_closed_) { |
358 DVLOG(1) << ENDPOINT << "Closing stream: " << id(); | 349 DVLOG(1) << ENDPOINT << "Closing stream: " << id(); |
359 session_->CloseStream(id()); | 350 session_->CloseStream(id()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 } | 450 } |
460 } | 451 } |
461 | 452 |
462 void ReliableQuicStream::UpdateSendWindowOffset(QuicStreamOffset new_window) { | 453 void ReliableQuicStream::UpdateSendWindowOffset(QuicStreamOffset new_window) { |
463 if (flow_controller_.UpdateSendWindowOffset(new_window)) { | 454 if (flow_controller_.UpdateSendWindowOffset(new_window)) { |
464 OnCanWrite(); | 455 OnCanWrite(); |
465 } | 456 } |
466 } | 457 } |
467 | 458 |
468 } // namespace net | 459 } // namespace net |
OLD | NEW |