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 // The base class for client/server reliable streams. | 5 // The base class for client/server reliable streams. |
6 | 6 |
7 #ifndef NET_QUIC_RELIABLE_QUIC_STREAM_H_ | 7 #ifndef NET_QUIC_RELIABLE_QUIC_STREAM_H_ |
8 #define NET_QUIC_RELIABLE_QUIC_STREAM_H_ | 8 #define NET_QUIC_RELIABLE_QUIC_STREAM_H_ |
9 | 9 |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 | 11 |
12 #include <list> | 12 #include <list> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 #include "net/base/iovec.h" | 17 #include "net/base/iovec.h" |
18 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
19 #include "net/quic/quic_ack_notifier.h" | 19 #include "net/quic/quic_ack_notifier.h" |
| 20 #include "net/quic/quic_flow_controller.h" |
20 #include "net/quic/quic_protocol.h" | 21 #include "net/quic/quic_protocol.h" |
21 #include "net/quic/quic_stream_sequencer.h" | 22 #include "net/quic/quic_stream_sequencer.h" |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 | 25 |
25 namespace test { | 26 namespace test { |
26 class ReliableQuicStreamPeer; | 27 class ReliableQuicStreamPeer; |
27 } // namespace test | 28 } // namespace test |
28 | 29 |
29 class QuicSession; | 30 class QuicSession; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 uint64 stream_bytes_written() const { return stream_bytes_written_; } | 87 uint64 stream_bytes_written() const { return stream_bytes_written_; } |
87 | 88 |
88 QuicVersion version() const; | 89 QuicVersion version() const; |
89 | 90 |
90 void set_fin_sent(bool fin_sent) { fin_sent_ = fin_sent; } | 91 void set_fin_sent(bool fin_sent) { fin_sent_ = fin_sent; } |
91 void set_rst_sent(bool rst_sent) { rst_sent_ = rst_sent; } | 92 void set_rst_sent(bool rst_sent) { rst_sent_ = rst_sent; } |
92 | 93 |
93 // Adjust our flow control windows according to new offset in |frame|. | 94 // Adjust our flow control windows according to new offset in |frame|. |
94 virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame); | 95 virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame); |
95 | 96 |
96 // True if this stream is blocked from writing due to flow control limits. | |
97 bool IsFlowControlBlocked() const; | |
98 | |
99 // Updates our send window offset (if offset larger). | 97 // Updates our send window offset (if offset larger). |
100 void UpdateFlowControlSendLimit(QuicStreamOffset offset); | 98 void UpdateFlowControlSendLimit(QuicStreamOffset offset); |
101 | 99 |
102 // If our receive window has dropped below the threshold, then send a | 100 // If our receive window has dropped below the threshold, then send a |
103 // WINDOW_UPDATE frame. This is called whenever bytes are consumed from the | 101 // WINDOW_UPDATE frame. This is called whenever bytes are consumed from the |
104 // sequencer's buffer. | 102 // sequencer's buffer. |
105 void MaybeSendWindowUpdate(); | 103 void MaybeSendWindowUpdate(); |
106 | 104 |
107 int num_frames_received(); | 105 int num_frames_received(); |
108 | 106 |
109 int num_duplicate_frames_received(); | 107 int num_duplicate_frames_received(); |
110 | 108 |
| 109 QuicFlowController* flow_controller() { return &flow_controller_; } |
| 110 |
111 protected: | 111 protected: |
112 // Sends as much of 'data' to the connection as the connection will consume, | 112 // Sends as much of 'data' to the connection as the connection will consume, |
113 // and then buffers any remaining data in queued_data_. | 113 // and then buffers any remaining data in queued_data_. |
114 void WriteOrBufferData( | 114 void WriteOrBufferData( |
115 base::StringPiece data, | 115 base::StringPiece data, |
116 bool fin, | 116 bool fin, |
117 QuicAckNotifier::DelegateInterface* ack_notifier_delegate); | 117 QuicAckNotifier::DelegateInterface* ack_notifier_delegate); |
118 | 118 |
119 // Sends as many bytes in the first |count| buffers of |iov| to the connection | 119 // Sends as many bytes in the first |count| buffers of |iov| to the connection |
120 // as the connection will consume. | 120 // as the connection will consume. |
(...skipping 15 matching lines...) Expand all Loading... |
136 bool HasBufferedData(); | 136 bool HasBufferedData(); |
137 | 137 |
138 bool fin_buffered() { return fin_buffered_; } | 138 bool fin_buffered() { return fin_buffered_; } |
139 | 139 |
140 const QuicSession* session() const { return session_; } | 140 const QuicSession* session() const { return session_; } |
141 QuicSession* session() { return session_; } | 141 QuicSession* session() { return session_; } |
142 | 142 |
143 const QuicStreamSequencer* sequencer() const { return &sequencer_; } | 143 const QuicStreamSequencer* sequencer() const { return &sequencer_; } |
144 QuicStreamSequencer* sequencer() { return &sequencer_; } | 144 QuicStreamSequencer* sequencer() { return &sequencer_; } |
145 | 145 |
146 // Returns true if flow control is enabled for this stream. | 146 void DisableFlowControl() { |
147 virtual bool IsFlowControlEnabled() const = 0; | 147 flow_controller_.Disable(); |
| 148 } |
148 | 149 |
149 private: | 150 private: |
150 friend class test::ReliableQuicStreamPeer; | 151 friend class test::ReliableQuicStreamPeer; |
151 friend class QuicStreamUtils; | 152 friend class QuicStreamUtils; |
152 class ProxyAckNotifierDelegate; | 153 class ProxyAckNotifierDelegate; |
153 | 154 |
154 struct PendingData { | 155 struct PendingData { |
155 PendingData(string data_in, | 156 PendingData(string data_in, |
156 scoped_refptr<ProxyAckNotifierDelegate> delegate_in); | 157 scoped_refptr<ProxyAckNotifierDelegate> delegate_in); |
157 ~PendingData(); | 158 ~PendingData(); |
(...skipping 21 matching lines...) Expand all Loading... |
179 uint64 stream_bytes_written_; | 180 uint64 stream_bytes_written_; |
180 | 181 |
181 // Stream error code received from a RstStreamFrame or error code sent by the | 182 // Stream error code received from a RstStreamFrame or error code sent by the |
182 // visitor or sequencer in the RstStreamFrame. | 183 // visitor or sequencer in the RstStreamFrame. |
183 QuicRstStreamErrorCode stream_error_; | 184 QuicRstStreamErrorCode stream_error_; |
184 // Connection error code due to which the stream was closed. |stream_error_| | 185 // Connection error code due to which the stream was closed. |stream_error_| |
185 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers | 186 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers |
186 // should check |connection_error_|. | 187 // should check |connection_error_|. |
187 QuicErrorCode connection_error_; | 188 QuicErrorCode connection_error_; |
188 | 189 |
189 // Stream level flow control. | |
190 // This stream is allowed to send up to flow_control_send_limit_ bytes. Once | |
191 // it has reached this limit it must not send more data until it receives a | |
192 // suitable WINDOW_UPDATE frame from the peer. | |
193 QuicStreamOffset flow_control_send_limit_; | |
194 | |
195 // Stream level flow control. | |
196 // The maximum size of the stream receive window. Used to determine by how | |
197 // much we should increase the window offset when sending a WINDOW_UPDATE. | |
198 uint64 max_flow_control_receive_window_bytes_; | |
199 | |
200 // Stream level flow control. | |
201 // This stream expects to receive up to receive_window_offset_bytes_. | |
202 // If the peer sends more than this (without sending us a WINDOW_UPDATE frame | |
203 // first), then this is a flow control error. | |
204 QuicStreamOffset flow_control_receive_window_offset_bytes_; | |
205 | |
206 // True if the read side is closed and further frames should be rejected. | 190 // True if the read side is closed and further frames should be rejected. |
207 bool read_side_closed_; | 191 bool read_side_closed_; |
208 // True if the write side is closed, and further writes should fail. | 192 // True if the write side is closed, and further writes should fail. |
209 bool write_side_closed_; | 193 bool write_side_closed_; |
210 | 194 |
211 bool fin_buffered_; | 195 bool fin_buffered_; |
212 bool fin_sent_; | 196 bool fin_sent_; |
213 | 197 |
214 // In combination with fin_sent_, used to ensure that a FIN and/or a RST is | 198 // In combination with fin_sent_, used to ensure that a FIN and/or a RST is |
215 // always sent before stream termination. | 199 // always sent before stream termination. |
216 bool rst_sent_; | 200 bool rst_sent_; |
217 | 201 |
218 // True if the session this stream is running under is a server session. | 202 // True if the session this stream is running under is a server session. |
219 bool is_server_; | 203 bool is_server_; |
220 | 204 |
| 205 QuicFlowController flow_controller_; |
| 206 |
221 DISALLOW_COPY_AND_ASSIGN(ReliableQuicStream); | 207 DISALLOW_COPY_AND_ASSIGN(ReliableQuicStream); |
222 }; | 208 }; |
223 | 209 |
224 } // namespace net | 210 } // namespace net |
225 | 211 |
226 #endif // NET_QUIC_RELIABLE_QUIC_STREAM_H_ | 212 #endif // NET_QUIC_RELIABLE_QUIC_STREAM_H_ |
OLD | NEW |