| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // Responsible for generating packets on behalf of a QuicConnection. |
| 6 // Packets are serialized just-in-time. Control frame are queued. |
| 7 // Ack and Feedback frames will requested from the Connection |
| 8 // just-in-time. When a packet needs to be sent, the Generator |
| 9 // wills serialized a packet pass it to QuicConnection::SendOrQueuePacket() |
| 10 // |
| 11 // The Generator's mode of operation is controlled by two conditions: |
| 12 // |
| 13 // 1) Is the Delegate writable? |
| 14 // |
| 15 // If the Delegate is not writable, then no operations will cause |
| 16 // a packet to be serialized. In particular: |
| 17 // * SetShouldSendAck will simply record that an ack is to be send. |
| 18 // * AddControlFram will enqueue the control frame. |
| 19 // * ConsumeData will do nothing. |
| 20 // |
| 21 // If the Delegate is writable, then the behavior depends on the second |
| 22 // condition: |
| 23 // |
| 24 // 2) Is the Generator in batch mode? |
| 25 // |
| 26 // If the Generator is NOT in batch mode, then each call to a write |
| 27 // operation will serialize one or more packets. The contents will |
| 28 // include any previous queued frames. If an ack should be sent |
| 29 // but has not been sent, then the Delegate will be asked to create |
| 30 // an Ack frame which will then be included in the packet. When |
| 31 // the write call completes, the current packet will be serialized |
| 32 // and sent to the Delegate, even if it is not full. |
| 33 // |
| 34 // If the Generator is in batch mode, then each write operation will |
| 35 // add data to the "current" packet. When the current packet becomes |
| 36 // full, it will be serialized and sent to the packet. When batch |
| 37 // mode is ended via |FinishBatchOperations|, the current packet |
| 38 // will be serialzied, even if it is not full. |
| 39 // |
| 40 // FEC behavior also depends on batch mode. In batch mode, FEC packets |
| 41 // will be sent after |max_packets_per_group| have been sent, as well |
| 42 // as after batch operations are complete. When not in batch mode, |
| 43 // an FEC packet will be sent after each write call completes. |
| 44 // |
| 45 // TODO(rch): This behavior should probably be tuned. When not in batch |
| 46 // mode we, should probably set a timer so that several independent |
| 47 // operations can be grouped into the same FEC group. |
| 48 // |
| 49 // When an FEC packet is generate, it will be send to the Delegate, |
| 50 // even if the Delegate has become unwritable after handling the |
| 51 // data packet immediately proceeding the FEC packet. |
| 52 |
| 53 #ifndef NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
| 54 #define NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
| 55 |
| 56 #include "net/quic/quic_packet_creator.h" |
| 57 |
| 58 namespace net { |
| 59 |
| 60 class NET_EXPORT_PRIVATE QuicPacketGenerator { |
| 61 public: |
| 62 class NET_EXPORT_PRIVATE DelegateInterface { |
| 63 public: |
| 64 virtual ~DelegateInterface() {} |
| 65 virtual bool CanWrite(bool is_retransmission) = 0; |
| 66 virtual QuicAckFrame* CreateAckFrame() = 0; |
| 67 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() = 0; |
| 68 // Takes ownership of |packet.packet| and |packet.retransmittable_frames|. |
| 69 virtual bool OnSerializedPacket(const SerializedPacket& packet) = 0; |
| 70 }; |
| 71 |
| 72 QuicPacketGenerator(DelegateInterface* delegate, |
| 73 QuicPacketCreator* creator); |
| 74 |
| 75 virtual ~QuicPacketGenerator(); |
| 76 |
| 77 void SetShouldSendAck(bool also_send_feedback); |
| 78 void AddControlFrame(const QuicFrame& frame); |
| 79 QuicConsumedData ConsumeData(QuicStreamId id, |
| 80 base::StringPiece data, |
| 81 QuicStreamOffset offset, |
| 82 bool fin); |
| 83 |
| 84 // Disables flushing. |
| 85 void StartBatchOperations(); |
| 86 // Enables flushing and flushes queued data. |
| 87 void FinishBatchOperations(); |
| 88 |
| 89 bool HasQueuedData() const; |
| 90 |
| 91 private: |
| 92 // Must be called when the connection is writable |
| 93 // and not blocked by the congestion manager. |
| 94 void SendQueuedData(); |
| 95 |
| 96 bool HasPendingData() const; |
| 97 bool AddNextPendingFrame(); |
| 98 void SerializeAndSendPacket(); |
| 99 |
| 100 DelegateInterface* delegate_; |
| 101 |
| 102 QuicPacketCreator* packet_creator_; |
| 103 QuicFrames queued_control_frames_; |
| 104 bool should_flush_; |
| 105 bool should_send_ack_; |
| 106 scoped_ptr<QuicAckFrame> pending_ack_frame_; |
| 107 scoped_ptr<QuicCongestionFeedbackFrame> pending_feedback_frame_; |
| 108 bool should_send_feedback_; |
| 109 }; |
| 110 |
| 111 } // namespace net |
| 112 |
| 113 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
| OLD | NEW |