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(QuicConnection* connection, | 16 QuicFlowController::QuicFlowController(QuicConnection* connection, |
17 QuicStreamId id, | 17 QuicStreamId id, |
18 bool is_server, | 18 bool is_server, |
19 uint64 send_window_offset, | 19 QuicStreamOffset send_window_offset, |
20 uint64 receive_window_offset, | 20 QuicStreamOffset receive_window_offset, |
21 uint64 max_receive_window) | 21 QuicByteCount max_receive_window) |
22 : connection_(connection), | 22 : connection_(connection), |
23 id_(id), | 23 id_(id), |
24 is_enabled_(true), | 24 is_enabled_(true), |
25 is_server_(is_server), | 25 is_server_(is_server), |
26 bytes_consumed_(0), | 26 bytes_consumed_(0), |
27 highest_received_byte_offset_(0), | 27 highest_received_byte_offset_(0), |
28 bytes_sent_(0), | 28 bytes_sent_(0), |
29 send_window_offset_(send_window_offset), | 29 send_window_offset_(send_window_offset), |
30 receive_window_offset_(receive_window_offset), | 30 receive_window_offset_(receive_window_offset), |
31 max_receive_window_(max_receive_window), | 31 max_receive_window_(max_receive_window), |
32 last_blocked_send_window_offset_(0) { | 32 last_blocked_send_window_offset_(0) { |
33 DVLOG(1) << ENDPOINT << "Created flow controller for stream " << id_ | 33 DVLOG(1) << ENDPOINT << "Created flow controller for stream " << id_ |
34 << ", setting initial receive window offset to: " | 34 << ", setting initial receive window offset to: " |
35 << receive_window_offset_ | 35 << receive_window_offset_ |
36 << ", max receive window to: " | 36 << ", max receive window to: " |
37 << max_receive_window_ | 37 << max_receive_window_ |
38 << ", setting send window offset to: " << send_window_offset_; | 38 << ", setting send window offset to: " << send_window_offset_; |
39 } | 39 } |
40 | 40 |
41 void QuicFlowController::AddBytesConsumed(uint64 bytes_consumed) { | 41 void QuicFlowController::AddBytesConsumed(QuicByteCount bytes_consumed) { |
42 if (!IsEnabled()) { | 42 if (!IsEnabled()) { |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
46 bytes_consumed_ += bytes_consumed; | 46 bytes_consumed_ += bytes_consumed; |
47 DVLOG(1) << ENDPOINT << "Stream " << id_ << " consumed: " << bytes_consumed_; | 47 DVLOG(1) << ENDPOINT << "Stream " << id_ << " consumed: " << bytes_consumed_; |
48 | 48 |
49 MaybeSendWindowUpdate(); | 49 MaybeSendWindowUpdate(); |
50 } | 50 } |
51 | 51 |
52 bool QuicFlowController::UpdateHighestReceivedOffset(uint64 new_offset) { | 52 bool QuicFlowController::UpdateHighestReceivedOffset( |
| 53 QuicStreamOffset new_offset) { |
53 if (!IsEnabled()) { | 54 if (!IsEnabled()) { |
54 return false; | 55 return false; |
55 } | 56 } |
56 | 57 |
57 // Only update if offset has increased. | 58 // Only update if offset has increased. |
58 if (new_offset <= highest_received_byte_offset_) { | 59 if (new_offset <= highest_received_byte_offset_) { |
59 return false; | 60 return false; |
60 } | 61 } |
61 | 62 |
62 DVLOG(1) << ENDPOINT << "Stream " << id_ | 63 DVLOG(1) << ENDPOINT << "Stream " << id_ |
63 << " highest byte offset increased from: " | 64 << " highest byte offset increased from: " |
64 << highest_received_byte_offset_ << " to " << new_offset; | 65 << highest_received_byte_offset_ << " to " << new_offset; |
65 highest_received_byte_offset_ = new_offset; | 66 highest_received_byte_offset_ = new_offset; |
66 return true; | 67 return true; |
67 } | 68 } |
68 | 69 |
69 void QuicFlowController::AddBytesSent(uint64 bytes_sent) { | 70 void QuicFlowController::AddBytesSent(QuicByteCount bytes_sent) { |
70 if (!IsEnabled()) { | 71 if (!IsEnabled()) { |
71 return; | 72 return; |
72 } | 73 } |
73 | 74 |
74 if (bytes_sent_ + bytes_sent > send_window_offset_) { | 75 if (bytes_sent_ + bytes_sent > send_window_offset_) { |
75 LOG(DFATAL) << ENDPOINT << "Stream " << id_ << " Trying to send an extra " | 76 LOG(DFATAL) << ENDPOINT << "Stream " << id_ << " Trying to send an extra " |
76 << bytes_sent << " bytes, when bytes_sent = " << bytes_sent_ | 77 << bytes_sent << " bytes, when bytes_sent = " << bytes_sent_ |
77 << ", and send_window_offset_ = " << send_window_offset_; | 78 << ", and send_window_offset_ = " << send_window_offset_; |
78 bytes_sent_ = send_window_offset_; | 79 bytes_sent_ = send_window_offset_; |
79 | 80 |
(...skipping 24 matching lines...) Expand all Loading... |
104 | 105 |
105 void QuicFlowController::MaybeSendWindowUpdate() { | 106 void QuicFlowController::MaybeSendWindowUpdate() { |
106 if (!IsEnabled()) { | 107 if (!IsEnabled()) { |
107 return; | 108 return; |
108 } | 109 } |
109 | 110 |
110 // Send WindowUpdate to increase receive window if | 111 // Send WindowUpdate to increase receive window if |
111 // (receive window offset - consumed bytes) < (max window / 2). | 112 // (receive window offset - consumed bytes) < (max window / 2). |
112 // This is behaviour copied from SPDY. | 113 // This is behaviour copied from SPDY. |
113 DCHECK_LT(bytes_consumed_, receive_window_offset_); | 114 DCHECK_LT(bytes_consumed_, receive_window_offset_); |
114 size_t consumed_window = receive_window_offset_ - bytes_consumed_; | 115 QuicStreamOffset consumed_window = receive_window_offset_ - bytes_consumed_; |
115 size_t threshold = (max_receive_window_ / 2); | 116 QuicByteCount threshold = (max_receive_window_ / 2); |
116 | 117 |
117 if (consumed_window < threshold) { | 118 if (consumed_window < threshold) { |
118 // Update our receive window. | 119 // Update our receive window. |
119 receive_window_offset_ += (max_receive_window_ - consumed_window); | 120 receive_window_offset_ += (max_receive_window_ - consumed_window); |
120 | 121 |
121 DVLOG(1) << ENDPOINT << "Sending WindowUpdate frame for stream " << id_ | 122 DVLOG(1) << ENDPOINT << "Sending WindowUpdate frame for stream " << id_ |
122 << ", consumed bytes: " << bytes_consumed_ | 123 << ", consumed bytes: " << bytes_consumed_ |
123 << ", consumed window: " << consumed_window | 124 << ", consumed window: " << consumed_window |
124 << ", and threshold: " << threshold | 125 << ", and threshold: " << threshold |
125 << ", and max recvw: " << max_receive_window_ | 126 << ", and max recvw: " << max_receive_window_ |
(...skipping 18 matching lines...) Expand all Loading... |
144 // The entire send_window has been consumed, we are now flow control | 145 // The entire send_window has been consumed, we are now flow control |
145 // blocked. | 146 // blocked. |
146 connection_->SendBlocked(id_); | 147 connection_->SendBlocked(id_); |
147 | 148 |
148 // Keep track of when we last sent a BLOCKED frame so that we only send one | 149 // Keep track of when we last sent a BLOCKED frame so that we only send one |
149 // at a given send offset. | 150 // at a given send offset. |
150 last_blocked_send_window_offset_ = send_window_offset_; | 151 last_blocked_send_window_offset_ = send_window_offset_; |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 bool QuicFlowController::UpdateSendWindowOffset(uint64 new_send_window_offset) { | 155 bool QuicFlowController::UpdateSendWindowOffset( |
| 156 QuicStreamOffset new_send_window_offset) { |
155 if (!IsEnabled()) { | 157 if (!IsEnabled()) { |
156 return false; | 158 return false; |
157 } | 159 } |
158 | 160 |
159 // Only update if send window has increased. | 161 // Only update if send window has increased. |
160 if (new_send_window_offset <= send_window_offset_) { | 162 if (new_send_window_offset <= send_window_offset_) { |
161 return false; | 163 return false; |
162 } | 164 } |
163 | 165 |
164 DVLOG(1) << ENDPOINT << "UpdateSendWindowOffset for stream " << id_ | 166 DVLOG(1) << ENDPOINT << "UpdateSendWindowOffset for stream " << id_ |
(...skipping 19 matching lines...) Expand all Loading... |
184 } | 186 } |
185 | 187 |
186 uint64 QuicFlowController::SendWindowSize() const { | 188 uint64 QuicFlowController::SendWindowSize() const { |
187 if (bytes_sent_ > send_window_offset_) { | 189 if (bytes_sent_ > send_window_offset_) { |
188 return 0; | 190 return 0; |
189 } | 191 } |
190 return send_window_offset_ - bytes_sent_; | 192 return send_window_offset_ - bytes_sent_; |
191 } | 193 } |
192 | 194 |
193 } // namespace net | 195 } // namespace net |
OLD | NEW |