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 // Responsible for generating packets on behalf of a QuicConnection. | 5 // Responsible for generating packets on behalf of a QuicConnection. |
6 // Packets are serialized just-in-time. Control frames are queued. | 6 // Packets are serialized just-in-time. Control frames are queued. |
7 // Ack and Feedback frames will be requested from the Connection | 7 // Ack and Feedback frames will be requested from the Connection |
8 // just-in-time. When a packet needs to be sent, the Generator | 8 // just-in-time. When a packet needs to be sent, the Generator |
9 // will serialize a packet and pass it to QuicConnection::SendOrQueuePacket() | 9 // will serialize a packet and pass it to QuicConnection::SendOrQueuePacket() |
10 // | 10 // |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // even if the Delegate has become unwritable after handling the | 50 // even if the Delegate has become unwritable after handling the |
51 // data packet immediately proceeding the FEC packet. | 51 // data packet immediately proceeding the FEC packet. |
52 | 52 |
53 #ifndef NET_QUIC_QUIC_PACKET_GENERATOR_H_ | 53 #ifndef NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
54 #define NET_QUIC_QUIC_PACKET_GENERATOR_H_ | 54 #define NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
55 | 55 |
56 #include "net/quic/quic_packet_creator.h" | 56 #include "net/quic/quic_packet_creator.h" |
57 | 57 |
58 namespace net { | 58 namespace net { |
59 | 59 |
| 60 class QuicAckNotifier; |
| 61 |
60 class NET_EXPORT_PRIVATE QuicPacketGenerator { | 62 class NET_EXPORT_PRIVATE QuicPacketGenerator { |
61 public: | 63 public: |
62 class NET_EXPORT_PRIVATE DelegateInterface { | 64 class NET_EXPORT_PRIVATE DelegateInterface { |
63 public: | 65 public: |
64 virtual ~DelegateInterface() {} | 66 virtual ~DelegateInterface() {} |
65 virtual bool CanWrite(Retransmission retransmission, | 67 virtual bool CanWrite(Retransmission retransmission, |
66 HasRetransmittableData retransmittable, | 68 HasRetransmittableData retransmittable, |
67 IsHandshake handshake) = 0; | 69 IsHandshake handshake) = 0; |
68 virtual QuicAckFrame* CreateAckFrame() = 0; | 70 virtual QuicAckFrame* CreateAckFrame() = 0; |
69 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() = 0; | 71 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
83 }; | 85 }; |
84 | 86 |
85 QuicPacketGenerator(DelegateInterface* delegate, | 87 QuicPacketGenerator(DelegateInterface* delegate, |
86 DebugDelegateInterface* debug_delegate, | 88 DebugDelegateInterface* debug_delegate, |
87 QuicPacketCreator* creator); | 89 QuicPacketCreator* creator); |
88 | 90 |
89 virtual ~QuicPacketGenerator(); | 91 virtual ~QuicPacketGenerator(); |
90 | 92 |
91 void SetShouldSendAck(bool also_send_feedback); | 93 void SetShouldSendAck(bool also_send_feedback); |
92 void AddControlFrame(const QuicFrame& frame); | 94 void AddControlFrame(const QuicFrame& frame); |
| 95 |
| 96 // Given some data, may consume part or all of it and pass it to the packet |
| 97 // creator to be serialized into packets. If not in batch mode, these packets |
| 98 // will also be sent during this call. |
93 QuicConsumedData ConsumeData(QuicStreamId id, | 99 QuicConsumedData ConsumeData(QuicStreamId id, |
94 base::StringPiece data, | 100 base::StringPiece data, |
95 QuicStreamOffset offset, | 101 QuicStreamOffset offset, |
96 bool fin); | 102 bool fin); |
97 | 103 |
| 104 // As above, but attaches a QuicAckNotifier to any created stream frames, |
| 105 // which will be called once the frame is ACKed by the peer. |
| 106 // The QuicAckNotifier is owned by the QuicConnection. |
| 107 QuicConsumedData ConsumeData(QuicStreamId id, |
| 108 base::StringPiece data, |
| 109 QuicStreamOffset offset, |
| 110 bool fin, |
| 111 QuicAckNotifier* notifier); |
| 112 |
98 // Indicates whether batch mode is currently enabled. | 113 // Indicates whether batch mode is currently enabled. |
99 bool InBatchMode(); | 114 bool InBatchMode(); |
100 // Disables flushing. | 115 // Disables flushing. |
101 void StartBatchOperations(); | 116 void StartBatchOperations(); |
102 // Enables flushing and flushes queued data. | 117 // Enables flushing and flushes queued data. |
103 void FinishBatchOperations(); | 118 void FinishBatchOperations(); |
104 | 119 |
105 bool HasQueuedFrames() const; | 120 bool HasQueuedFrames() const; |
106 | 121 |
107 void set_debug_delegate(DebugDelegateInterface* debug_delegate) { | 122 void set_debug_delegate(DebugDelegateInterface* debug_delegate) { |
108 debug_delegate_ = debug_delegate; | 123 debug_delegate_ = debug_delegate; |
109 } | 124 } |
110 | 125 |
111 private: | 126 private: |
112 void SendQueuedFrames(); | 127 void SendQueuedFrames(); |
113 | 128 |
114 // Test to see if we have pending ack, feedback, or control frames. | 129 // Test to see if we have pending ack, feedback, or control frames. |
115 bool HasPendingFrames() const; | 130 bool HasPendingFrames() const; |
116 // Test to see if the addition of a pending frame (which might be | 131 // Test to see if the addition of a pending frame (which might be |
117 // retransmittable) would still allow the resulting packet to be sent now. | 132 // retransmittable) would still allow the resulting packet to be sent now. |
118 bool CanSendWithNextPendingFrameAddition() const; | 133 bool CanSendWithNextPendingFrameAddition() const; |
119 // Add exactly one pending frame, preferring ack over feedback over control | 134 // Add exactly one pending frame, preferring ack over feedback over control |
120 // frames. | 135 // frames. |
121 bool AddNextPendingFrame(); | 136 bool AddNextPendingFrame(); |
122 | 137 |
123 bool AddFrame(const QuicFrame& frame); | 138 bool AddFrame(const QuicFrame& frame); |
| 139 |
124 void SerializeAndSendPacket(); | 140 void SerializeAndSendPacket(); |
125 | 141 |
126 DelegateInterface* delegate_; | 142 DelegateInterface* delegate_; |
127 DebugDelegateInterface* debug_delegate_; | 143 DebugDelegateInterface* debug_delegate_; |
128 | 144 |
129 QuicPacketCreator* packet_creator_; | 145 QuicPacketCreator* packet_creator_; |
130 QuicFrames queued_control_frames_; | 146 QuicFrames queued_control_frames_; |
131 | 147 |
132 // True if batch mode is currently enabled. | 148 // True if batch mode is currently enabled. |
133 bool batch_mode_; | 149 bool batch_mode_; |
134 | 150 |
135 // Flags to indicate the need for just-in-time construction of a frame. | 151 // Flags to indicate the need for just-in-time construction of a frame. |
136 bool should_send_ack_; | 152 bool should_send_ack_; |
137 bool should_send_feedback_; | 153 bool should_send_feedback_; |
138 // If we put a non-retransmittable frame (namley ack or feedback frame) in | 154 // If we put a non-retransmittable frame (namley ack or feedback frame) in |
139 // this packet, then we have to hold a reference to it until we flush (and | 155 // this packet, then we have to hold a reference to it until we flush (and |
140 // serialize it). Retransmittable frames are referenced elsewhere so that they | 156 // serialize it). Retransmittable frames are referenced elsewhere so that they |
141 // can later be (optionally) retransmitted. | 157 // can later be (optionally) retransmitted. |
142 scoped_ptr<QuicAckFrame> pending_ack_frame_; | 158 scoped_ptr<QuicAckFrame> pending_ack_frame_; |
143 scoped_ptr<QuicCongestionFeedbackFrame> pending_feedback_frame_; | 159 scoped_ptr<QuicCongestionFeedbackFrame> pending_feedback_frame_; |
144 | 160 |
145 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); | 161 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); |
146 }; | 162 }; |
147 | 163 |
148 } // namespace net | 164 } // namespace net |
149 | 165 |
150 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ | 166 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
OLD | NEW |