OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic_flow_controller.h" | 5 #include "net/quic/quic_flow_controller.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "net/quic/quic_connection.h" | 8 #include "net/quic/quic_connection.h" |
9 #include "net/quic/quic_flags.h" | 9 #include "net/quic/quic_flags.h" |
10 #include "net/quic/quic_protocol.h" | 10 #include "net/quic/quic_protocol.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") | 14 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") |
15 | 15 |
16 QuicFlowController::QuicFlowController(QuicVersion version, | 16 QuicFlowController::QuicFlowController(QuicVersion version, |
17 QuicStreamId id, | 17 QuicStreamId id, |
18 bool is_server, | 18 bool is_server, |
19 uint64 send_window_offset, | 19 uint64 send_window_offset, |
20 uint64 receive_window_offset, | 20 uint64 receive_window_offset, |
21 uint64 max_receive_window) | 21 uint64 max_receive_window) |
22 : id_(id), | 22 : id_(id), |
23 is_enabled_(true), | 23 is_enabled_(true), |
24 is_server_(is_server), | 24 is_server_(is_server), |
25 bytes_consumed_(0), | 25 bytes_consumed_(0), |
26 bytes_buffered_(0), | 26 bytes_buffered_(0), |
27 bytes_sent_(0), | 27 bytes_sent_(0), |
28 send_window_offset_(send_window_offset), | 28 send_window_offset_(send_window_offset), |
29 receive_window_offset_(receive_window_offset), | 29 receive_window_offset_(receive_window_offset), |
30 max_receive_window_(max_receive_window), | 30 max_receive_window_(max_receive_window), |
31 last_blocked_send_window_offset_(0) { | 31 last_blocked_send_window_offset_(0) { |
32 DVLOG(1) << ENDPOINT << "Created flow controller for stream " << id_ | 32 DVLOG(1) << ENDPOINT << "Created flow controller for stream " << id_ |
33 << ", setting initial receive window offset to: " | 33 << ", setting initial receive window offset to: " |
34 << receive_window_offset_ | 34 << receive_window_offset_ |
35 << ", max receive window to: " | 35 << ", max receive window to: " << max_receive_window_ |
36 << max_receive_window_ | |
37 << ", setting send window offset to: " << send_window_offset_; | 36 << ", setting send window offset to: " << send_window_offset_; |
38 if (version < QUIC_VERSION_17) { | 37 if (version < QUIC_VERSION_17) { |
39 DVLOG(1) << ENDPOINT << "Disabling QuicFlowController for stream " << id_ | 38 DVLOG(1) << ENDPOINT << "Disabling QuicFlowController for stream " << id_ |
40 << ", QUIC version " << version; | 39 << ", QUIC version " << version; |
41 Disable(); | 40 Disable(); |
42 } | 41 } |
43 } | 42 } |
44 | 43 |
45 void QuicFlowController::AddBytesConsumed(uint64 bytes_consumed) { | 44 void QuicFlowController::AddBytesConsumed(uint64 bytes_consumed) { |
46 if (!IsEnabled()) { | 45 if (!IsEnabled()) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 bytes_sent_ += bytes_sent; | 91 bytes_sent_ += bytes_sent; |
93 DVLOG(1) << ENDPOINT << "Stream " << id_ << " sent: " << bytes_sent_; | 92 DVLOG(1) << ENDPOINT << "Stream " << id_ << " sent: " << bytes_sent_; |
94 } | 93 } |
95 | 94 |
96 bool QuicFlowController::FlowControlViolation() { | 95 bool QuicFlowController::FlowControlViolation() { |
97 if (!IsEnabled()) { | 96 if (!IsEnabled()) { |
98 return false; | 97 return false; |
99 } | 98 } |
100 | 99 |
101 if (receive_window_offset_ < TotalReceivedBytes()) { | 100 if (receive_window_offset_ < TotalReceivedBytes()) { |
102 LOG(ERROR) | 101 LOG(ERROR) << ENDPOINT << "Flow control violation on stream " << id_ |
103 << ENDPOINT << "Flow control violation on stream " << id_ | 102 << ", receive window: " << receive_window_offset_ |
104 << ", receive window: " << receive_window_offset_ | 103 << ", bytes received: " << TotalReceivedBytes(); |
105 << ", bytes received: " << TotalReceivedBytes(); | |
106 | 104 |
107 return true; | 105 return true; |
108 } | 106 } |
109 return false; | 107 return false; |
110 } | 108 } |
111 | 109 |
112 void QuicFlowController::MaybeSendWindowUpdate(QuicConnection* connection) { | 110 void QuicFlowController::MaybeSendWindowUpdate(QuicConnection* connection) { |
113 if (!IsEnabled()) { | 111 if (!IsEnabled()) { |
114 return; | 112 return; |
115 } | 113 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return 0; | 190 return 0; |
193 } | 191 } |
194 return send_window_offset_ - bytes_sent_; | 192 return send_window_offset_ - bytes_sent_; |
195 } | 193 } |
196 | 194 |
197 uint64 QuicFlowController::TotalReceivedBytes() const { | 195 uint64 QuicFlowController::TotalReceivedBytes() const { |
198 return bytes_consumed_ + bytes_buffered_; | 196 return bytes_consumed_ + bytes_buffered_; |
199 } | 197 } |
200 | 198 |
201 } // namespace net | 199 } // namespace net |
OLD | NEW |