| 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 // Accumulates frames for the next packet until more frames no longer fit or | 5 // Accumulates frames for the next packet until more frames no longer fit or |
| 6 // it's time to create a packet from them. Also provides packet creation of | 6 // it's time to create a packet from them. Also provides packet creation of |
| 7 // FEC packets based on previously created packets. | 7 // FEC packets based on previously created packets. |
| 8 | 8 |
| 9 #ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_ | 9 #ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_ |
| 10 #define NET_QUIC_QUIC_PACKET_CREATOR_H_ | 10 #define NET_QUIC_QUIC_PACKET_CREATOR_H_ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 QuicPacketCount max_packets_in_flight); | 67 QuicPacketCount max_packets_in_flight); |
| 68 | 68 |
| 69 // The overhead the framing will add for a packet with one frame. | 69 // The overhead the framing will add for a packet with one frame. |
| 70 static size_t StreamFramePacketOverhead( | 70 static size_t StreamFramePacketOverhead( |
| 71 QuicConnectionIdLength connection_id_length, | 71 QuicConnectionIdLength connection_id_length, |
| 72 bool include_version, | 72 bool include_version, |
| 73 QuicPacketNumberLength packet_number_length, | 73 QuicPacketNumberLength packet_number_length, |
| 74 QuicStreamOffset offset, | 74 QuicStreamOffset offset, |
| 75 InFecGroup is_in_fec_group); | 75 InFecGroup is_in_fec_group); |
| 76 | 76 |
| 77 // Converts a raw payload to a stream frame (which fits into the currently |
| 78 // open packet) and adds the frame to the packet. The payload begins at |
| 79 // |iov_offset| into the |iov|. |
| 80 // Creates |frame| and returns true if succeeds, false otherwise. |
| 81 bool ConsumeData(QuicStreamId id, |
| 82 QuicIOVector iov, |
| 83 size_t iov_offset, |
| 84 QuicStreamOffset offset, |
| 85 bool fin, |
| 86 bool needs_padding, |
| 87 QuicFrame* frame); |
| 88 |
| 89 // Returns true if currently open packet can accommodate more stream frames of |
| 90 // stream |id| at |offset|, false otherwise. |
| 77 bool HasRoomForStreamFrame(QuicStreamId id, QuicStreamOffset offset) const; | 91 bool HasRoomForStreamFrame(QuicStreamId id, QuicStreamOffset offset) const; |
| 78 | 92 |
| 79 // Converts a raw payload to a frame which fits into the currently open | |
| 80 // packet. The payload begins at |iov_offset| into the |iov|. | |
| 81 // Returns the number of bytes consumed from data. | |
| 82 // If data is empty and fin is true, the expected behavior is to consume the | |
| 83 // fin but return 0. If any data is consumed, it will be copied into a | |
| 84 // new buffer that |frame| will point to and will be stored in |buffer|. | |
| 85 size_t CreateStreamFrame(QuicStreamId id, | |
| 86 QuicIOVector iov, | |
| 87 size_t iov_offset, | |
| 88 QuicStreamOffset offset, | |
| 89 bool fin, | |
| 90 QuicFrame* frame, | |
| 91 UniqueStreamBuffer* buffer); | |
| 92 | |
| 93 // Serializes all frames into a single packet. All frames must fit into a | 93 // Serializes all frames into a single packet. All frames must fit into a |
| 94 // single packet. Also, sets the entropy hash of the serialized packet to a | 94 // single packet. Also, sets the entropy hash of the serialized packet to a |
| 95 // random bool and returns that value as a member of SerializedPacket. | 95 // random bool and returns that value as a member of SerializedPacket. |
| 96 // Never returns a RetransmittableFrames in SerializedPacket. | 96 // Never returns a RetransmittableFrames in SerializedPacket. |
| 97 SerializedPacket SerializeAllFrames(const QuicFrames& frames, | 97 SerializedPacket SerializeAllFrames(const QuicFrames& frames, |
| 98 char* buffer, | 98 char* buffer, |
| 99 size_t buffer_len); | 99 size_t buffer_len); |
| 100 | 100 |
| 101 // Re-serializes frames with the original packet's packet number length. | 101 // Re-serializes frames with the original packet's packet number length. |
| 102 // Used for retransmitting packets to ensure they aren't too long. | 102 // Used for retransmitting packets to ensure they aren't too long. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 // Returns the currently open FEC group's number. Returns 0 when FEC is | 229 // Returns the currently open FEC group's number. Returns 0 when FEC is |
| 230 // disabled or no FEC group is open. | 230 // disabled or no FEC group is open. |
| 231 QuicFecGroupNumber fec_group_number(); | 231 QuicFecGroupNumber fec_group_number(); |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 friend class test::QuicPacketCreatorPeer; | 234 friend class test::QuicPacketCreatorPeer; |
| 235 | 235 |
| 236 static bool ShouldRetransmit(const QuicFrame& frame); | 236 static bool ShouldRetransmit(const QuicFrame& frame); |
| 237 | 237 |
| 238 // Converts a raw payload to a frame which fits into the currently open |
| 239 // packet. The payload begins at |iov_offset| into the |iov|. |
| 240 // Returns the number of bytes consumed from data. |
| 241 // If data is empty and fin is true, the expected behavior is to consume the |
| 242 // fin but return 0. If any data is consumed, it will be copied into a |
| 243 // new buffer that |frame| will point to and will be stored in |buffer|. |
| 244 size_t CreateStreamFrame(QuicStreamId id, |
| 245 QuicIOVector iov, |
| 246 size_t iov_offset, |
| 247 QuicStreamOffset offset, |
| 248 bool fin, |
| 249 QuicFrame* frame, |
| 250 UniqueStreamBuffer* buffer); |
| 251 |
| 238 // Copies |length| bytes from iov starting at offset |iov_offset| into buffer. | 252 // Copies |length| bytes from iov starting at offset |iov_offset| into buffer. |
| 239 // |iov| must be at least iov_offset+length total length and buffer must be | 253 // |iov| must be at least iov_offset+length total length and buffer must be |
| 240 // at least |length| long. | 254 // at least |length| long. |
| 241 static void CopyToBuffer(QuicIOVector iov, | 255 static void CopyToBuffer(QuicIOVector iov, |
| 242 size_t iov_offset, | 256 size_t iov_offset, |
| 243 size_t length, | 257 size_t length, |
| 244 char* buffer); | 258 char* buffer); |
| 245 | 259 |
| 246 // Updates lengths and also starts an FEC group if FEC protection is on and | 260 // Updates lengths and also starts an FEC group if FEC protection is on and |
| 247 // there is not already an FEC group open. | 261 // there is not already an FEC group open. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_; | 316 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_; |
| 303 // If true, the packet will be padded up to |max_packet_length_|. | 317 // If true, the packet will be padded up to |max_packet_length_|. |
| 304 bool needs_padding_; | 318 bool needs_padding_; |
| 305 | 319 |
| 306 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); | 320 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); |
| 307 }; | 321 }; |
| 308 | 322 |
| 309 } // namespace net | 323 } // namespace net |
| 310 | 324 |
| 311 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ | 325 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ |
| OLD | NEW |