OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 #ifndef NET_QUIC_QUIC_FRAME_LIST_H_ | 5 #ifndef NET_QUIC_QUIC_FRAME_LIST_H_ |
6 #define NET_QUIC_QUIC_FRAME_LIST_H_ | 6 #define NET_QUIC_QUIC_FRAME_LIST_H_ |
7 | 7 |
8 #include "net/quic/quic_frame_list.h" | 8 #include "net/quic/quic_frame_list.h" |
9 #include "net/quic/quic_protocol.h" | 9 #include "net/quic/quic_protocol.h" |
10 | 10 |
11 using base::StringPiece; | 11 using base::StringPiece; |
12 using std::string; | 12 using std::string; |
13 using std::list; | 13 using std::list; |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 namespace test { | 17 namespace test { |
18 class QuicStreamSequencerPeer; | 18 class QuicStreamSequencerPeer; |
19 } | 19 } |
20 | 20 |
21 class NET_EXPORT_PRIVATE QuicFrameList { | 21 class NET_EXPORT_PRIVATE QuicFrameList { |
22 public: | 22 public: |
23 // A contiguous segment received by a QUIC stream. | 23 // A contiguous segment received by a QUIC stream. |
24 struct FrameData { | 24 struct FrameData { |
25 FrameData(QuicStreamOffset offset, string segment); | 25 FrameData(QuicStreamOffset offset, |
| 26 string segment, |
| 27 const QuicTime timestamp); |
26 | 28 |
27 const QuicStreamOffset offset; | 29 const QuicStreamOffset offset; |
28 string segment; | 30 string segment; |
| 31 const QuicTime timestamp; |
29 }; | 32 }; |
30 | 33 |
31 explicit QuicFrameList(); | 34 explicit QuicFrameList(); |
32 | 35 |
33 ~QuicFrameList(); | 36 ~QuicFrameList(); |
34 | 37 |
35 // Clear the buffer such that it is in its initial, newly constructed state. | 38 // Clear the buffer such that it is in its initial, newly constructed state. |
36 void Clear() { frame_list_.clear(); } | 39 void Clear() { frame_list_.clear(); } |
37 | 40 |
38 // Returns true if there is nothing to read in this buffer. | 41 // Returns true if there is nothing to read in this buffer. |
39 bool Empty() const { return frame_list_.empty(); } | 42 bool Empty() const { return frame_list_.empty(); } |
40 | 43 |
41 // Write the supplied data to this buffer. If the write was successful, | 44 // Write the supplied data to this buffer. |timestamp| is used for |
42 // return the number of bytes written in |bytes_written|. | 45 // measuring head of line (HOL) blocking. If the write was |
43 // Return QUIC_INVALID_STREAM_DATA if |data| overlaps with existing data. | 46 // successful, return the number of bytes written in |
44 // No data will be written. | 47 // |bytes_written|. Return QUIC_INVALID_STREAM_DATA if |data| |
45 // Return QUIC_NO_ERROR, if |data| is duplicated with data written previously, | 48 // overlaps with existing data. No data will be written. Return |
46 // and |bytes_written| = 0 | 49 // QUIC_NO_ERROR, if |data| is duplicated with data written |
| 50 // previously, and |bytes_written| = 0 |
47 QuicErrorCode WriteAtOffset(QuicStreamOffset offset, | 51 QuicErrorCode WriteAtOffset(QuicStreamOffset offset, |
48 StringPiece data, | 52 StringPiece data, |
| 53 QuicTime timestamp, |
49 size_t* bytes_written); | 54 size_t* bytes_written); |
50 | 55 |
51 // Read from this buffer into given iovec array, upto number of iov_len iovec | 56 // Read from this buffer into given iovec array, upto number of iov_len iovec |
52 // objects. | 57 // objects. |
53 // Returns the number of bytes read into iov. | 58 // Returns the number of bytes read into iov. |
54 size_t ReadvAndInvalidate(const struct iovec* iov, size_t iov_len); | 59 size_t ReadvAndInvalidate(const struct iovec* iov, size_t iov_len); |
55 | 60 |
56 // Returns the readable region of valid data in iovec format. The readable | 61 // Returns the readable region of valid data in iovec format. The readable |
57 // region is the buffer region where there is valid data not yet read by | 62 // region is the buffer region where there is valid data not yet read by |
58 // client. ReadAndInvalidate() and WriteAtOffset() change the readable region. | 63 // client. ReadAndInvalidate() and WriteAtOffset() change the readable region. |
59 // The return value of this function is the number of iovec entries | 64 // The return value of this function is the number of iovec entries |
60 // filled into in iov. If the region is empty, one iovec entry with 0 length | 65 // filled into in iov. If the region is empty, one iovec entry with 0 length |
61 // is returned, and the function returns 0. If there are more readable | 66 // is returned, and the function returns 0. If there are more readable |
62 // regions than iov_size, the function only processes the first | 67 // regions than iov_size, the function only processes the first |
63 // iov_size of them. | 68 // iov_size of them. |
64 int GetReadableRegions(struct iovec* iov, int iov_len) const; | 69 int GetReadableRegions(struct iovec* iov, int iov_len) const; |
65 | 70 |
| 71 // Fills in one iovec with the next readable region. |timestamp| is |
| 72 // data arrived at the sequencer, and is used for measuring head of |
| 73 // line blocking (HOL). Returns false if there is no readable |
| 74 // region available. |
| 75 bool GetReadableRegion(iovec* iov, QuicTime* timestamp) const; |
| 76 |
66 // Called after GetReadableRegions() to accumulate total_bytes_read_ and free | 77 // Called after GetReadableRegions() to accumulate total_bytes_read_ and free |
67 // up block when all data in it have been read out. | 78 // up block when all data in it have been read out. |
68 // Pre-requisite: bytes_used <= ReadableBytes() | 79 // Pre-requisite: bytes_used <= ReadableBytes() |
69 bool IncreaseTotalReadAndInvalidate(size_t bytes_used); | 80 bool IncreaseTotalReadAndInvalidate(size_t bytes_used); |
70 | 81 |
71 // Whether there are bytes can be read out (offset == total_bytes_read_) | 82 // Whether there are bytes can be read out (offset == total_bytes_read_) |
72 bool HasBytesToRead() const; | 83 bool HasBytesToRead() const; |
73 | 84 |
74 size_t size() const { return frame_list_.size(); } | 85 size_t size() const { return frame_list_.size(); } |
75 | 86 |
(...skipping 14 matching lines...) Expand all Loading... |
90 size_t data_len, | 101 size_t data_len, |
91 list<FrameData>::const_iterator insertion_point) const; | 102 list<FrameData>::const_iterator insertion_point) const; |
92 | 103 |
93 list<FrameData> frame_list_; | 104 list<FrameData> frame_list_; |
94 QuicStreamOffset total_bytes_read_ = 0; | 105 QuicStreamOffset total_bytes_read_ = 0; |
95 }; | 106 }; |
96 | 107 |
97 } // namespace net_quic | 108 } // namespace net_quic |
98 | 109 |
99 #endif // NET_QUIC_QUIC_FRAME_LIST_H_ | 110 #endif // NET_QUIC_QUIC_FRAME_LIST_H_ |
OLD | NEW |