OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_QUIC_QUIC_FRAME_LIST_H_ |
| 6 #define NET_QUIC_QUIC_FRAME_LIST_H_ |
| 7 |
| 8 #include "net/quic/quic_frame_list.h" |
| 9 #include "net/quic/quic_protocol.h" |
| 10 |
| 11 using base::StringPiece; |
| 12 using std::string; |
| 13 using std::list; |
| 14 |
| 15 namespace net { |
| 16 |
| 17 namespace test { |
| 18 class QuicStreamSequencerPeer; |
| 19 } |
| 20 |
| 21 class NET_EXPORT_PRIVATE QuicFrameList { |
| 22 public: |
| 23 // A contiguous segment received by a QUIC stream. |
| 24 struct FrameData { |
| 25 FrameData(QuicStreamOffset offset, string segment); |
| 26 |
| 27 const QuicStreamOffset offset; |
| 28 string segment; |
| 29 }; |
| 30 |
| 31 explicit QuicFrameList(); |
| 32 |
| 33 ~QuicFrameList(); |
| 34 |
| 35 // Clear the buffer such that it is in its initial, newly constructed state. |
| 36 void Clear() { frame_list_.clear(); } |
| 37 |
| 38 // Returns true if there is nothing to read in this buffer. |
| 39 bool Empty() const { return frame_list_.empty(); } |
| 40 |
| 41 // Write the supplied data to this buffer. If the write was successful, |
| 42 // return the number of bytes written in |bytes_written|. |
| 43 // Return QUIC_INVALID_STREAM_DATA if |data| overlaps with existing data. |
| 44 // No data will be written. |
| 45 // Return QUIC_NO_ERROR, if |data| is duplicated with data written previously, |
| 46 // and |bytes_written| = 0 |
| 47 QuicErrorCode WriteAtOffset(QuicStreamOffset offset, |
| 48 StringPiece data, |
| 49 size_t* bytes_written); |
| 50 |
| 51 // Read from this buffer into given iovec array, upto number of iov_len iovec |
| 52 // objects. |
| 53 // Returns the number of bytes read into iov. |
| 54 size_t ReadvAndInvalidate(const struct iovec* iov, size_t iov_len); |
| 55 |
| 56 // 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 |
| 58 // client. ReadAndInvalidate() and WriteAtOffset() change the readable region. |
| 59 // 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 |
| 61 // is returned, and the function returns 0. If there are more readable |
| 62 // regions than iov_size, the function only processes the first |
| 63 // iov_size of them. |
| 64 int GetReadableRegions(struct iovec* iov, int iov_len) const; |
| 65 |
| 66 // Called after GetReadableRegions() to accumulate total_bytes_read_ and free |
| 67 // up block when all data in it have been read out. |
| 68 // Pre-requisite: bytes_used <= ReadableBytes() |
| 69 bool IncreaseTotalReadAndInvalidate(size_t bytes_used); |
| 70 |
| 71 // Whether there are bytes can be read out (offset == total_bytes_read_) |
| 72 bool HasBytesToRead() const; |
| 73 |
| 74 size_t size() const { return frame_list_.size(); } |
| 75 |
| 76 QuicStreamOffset total_bytes_read() const { return total_bytes_read_; } |
| 77 |
| 78 private: |
| 79 friend class test::QuicStreamSequencerPeer; |
| 80 |
| 81 list<FrameData>::iterator FindInsertionPoint(QuicStreamOffset offset, |
| 82 size_t len); |
| 83 |
| 84 bool FrameOverlapsBufferedData( |
| 85 QuicStreamOffset offset, |
| 86 size_t data_len, |
| 87 list<FrameData>::const_iterator insertion_point) const; |
| 88 |
| 89 bool IsDuplicate(QuicStreamOffset offset, |
| 90 size_t data_len, |
| 91 list<FrameData>::const_iterator insertion_point) const; |
| 92 |
| 93 list<FrameData> frame_list_; |
| 94 QuicStreamOffset total_bytes_read_ = 0; |
| 95 }; |
| 96 |
| 97 } // namespace net_quic |
| 98 |
| 99 #endif // NET_QUIC_QUIC_FRAME_LIST_H_ |
OLD | NEW |