OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_QUIC_QUIC_FLOW_CONTROLLER_H_ |
| 6 #define NET_QUIC_QUIC_FLOW_CONTROLLER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "net/base/net_export.h" |
| 10 #include "net/quic/quic_protocol.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 namespace test { |
| 15 class QuicFlowControllerPeer; |
| 16 } // namespace test |
| 17 |
| 18 class QuicConnection; |
| 19 |
| 20 // QuicFlowController allows a QUIC stream or connection to perform flow |
| 21 // control. The stream/connection owns a QuicFlowController which keeps track of |
| 22 // bytes sent/received, can tell the owner if it is flow control blocked, and |
| 23 // can send WINDOW_UPDATE or BLOCKED frames when needed. |
| 24 class NET_EXPORT_PRIVATE QuicFlowController { |
| 25 public: |
| 26 QuicFlowController(QuicStreamId id, |
| 27 bool is_server, |
| 28 uint64 send_window_offset, |
| 29 uint64 receive_window_offset, |
| 30 uint64 max_receive_window); |
| 31 ~QuicFlowController() {} |
| 32 |
| 33 // Called when bytes are received from the peer, and buffered. |
| 34 void AddBytesBuffered(uint64 bytes_buffered); |
| 35 |
| 36 // Called when bytes currently buffered locally, are removed from the buffer. |
| 37 void RemoveBytesBuffered(uint64 bytes_buffered); |
| 38 |
| 39 // Called when bytes received from the peer are consumed locally. |
| 40 void AddBytesConsumed(uint64 bytes_consumed); |
| 41 |
| 42 // Called when bytes are sent to the peer. |
| 43 void AddBytesSent(uint64 bytes_sent); |
| 44 |
| 45 // Set a new send window offset. |
| 46 // Returns true if this changes send_window_offset_, and false in the case |
| 47 // where |new_send_window| is <= send_window_offset_. |
| 48 bool UpdateSendWindowOffset(uint64 new_send_window_offset); |
| 49 |
| 50 // Returns the current available send window. |
| 51 uint64 SendWindowSize() const; |
| 52 |
| 53 // Send a BLOCKED frame on |connection| if appropriate. |
| 54 void MaybeSendBlocked(QuicConnection* connection); |
| 55 |
| 56 // Send a WINDOW_UPDATE frame on |connection| if appropriate. |
| 57 void MaybeSendWindowUpdate(QuicConnection* connection); |
| 58 |
| 59 // Disable flow control. |
| 60 void Disable(); |
| 61 |
| 62 // Returns true if flow control is enabled. |
| 63 bool IsEnabled() const; |
| 64 |
| 65 // Returns true if flow control send limits have been reached. |
| 66 bool IsBlocked() const; |
| 67 |
| 68 // Returns true if flow control receive limits have been violated by the peer. |
| 69 bool FlowControlViolation(); |
| 70 |
| 71 private: |
| 72 friend class test::QuicFlowControllerPeer; |
| 73 |
| 74 // Total received bytes is the sum of bytes buffered, and bytes consumed. |
| 75 uint64 TotalReceivedBytes() const; |
| 76 |
| 77 // ID of stream this flow controller belongs to. This can be 0 if this is a |
| 78 // connection level flow controller. |
| 79 QuicStreamId id_; |
| 80 |
| 81 // True if flow control is enabled. |
| 82 bool is_enabled_; |
| 83 |
| 84 // True if this is owned by a server. |
| 85 bool is_server_; |
| 86 |
| 87 // Track number of bytes received from the peer, which have been consumed |
| 88 // locally. |
| 89 uint64 bytes_consumed_; |
| 90 |
| 91 // Tracks number of bytes received from the peer, and buffered locally. |
| 92 uint64 bytes_buffered_; |
| 93 |
| 94 // Tracks number of bytes sent to the peer. |
| 95 uint64 bytes_sent_; |
| 96 |
| 97 // The absolute offset in the outgoing byte stream. If this offset is reached |
| 98 // then we become flow control blocked until we receive a WINDOW_UPDATE. |
| 99 uint64 send_window_offset_; |
| 100 |
| 101 // The absolute offset in the incoming byte stream. The peer should never send |
| 102 // us bytes which are beyond this offset. |
| 103 uint64 receive_window_offset_; |
| 104 |
| 105 // Largest size the receive window can grow to. |
| 106 uint64 max_receive_window_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(QuicFlowController); |
| 109 }; |
| 110 |
| 111 } // namespace net |
| 112 |
| 113 #endif // NET_QUIC_QUIC_FLOW_CONTROLLER_H_ |
OLD | NEW |