Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: net/quic/quic_frame_list.h

Issue 1414573004: Introduces QuicStreamSequencerBufferInterface with one implementation. Refactor, no behavior change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the build file (previously missing a comma) Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
9 #include "net/quic/quic_protocol.h" 8 #include "net/quic/quic_protocol.h"
9 #include "net/quic/quic_stream_sequencer_buffer_interface.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 QuicStreamSequencerBufferInterface {
22 public: 23 public:
23 // A contiguous segment received by a QUIC stream. 24 // A contiguous segment received by a QUIC stream.
24 struct FrameData { 25 struct FrameData {
25 FrameData(QuicStreamOffset offset, 26 FrameData(QuicStreamOffset offset,
26 string segment, 27 string segment,
27 const QuicTime timestamp); 28 const QuicTime timestamp);
28 29
29 const QuicStreamOffset offset; 30 const QuicStreamOffset offset;
30 string segment; 31 string segment;
31 const QuicTime timestamp; 32 const QuicTime timestamp;
32 }; 33 };
33 34
34 explicit QuicFrameList(); 35 explicit QuicFrameList();
35 36
36 ~QuicFrameList(); 37 ~QuicFrameList() override;
37 38
38 // Clear the buffer such that it is in its initial, newly constructed state. 39 // QuicStreamSequencerBufferInterface implementation
39 void Clear() { frame_list_.clear(); } 40 void Clear() override;
40 41 bool Empty() const override;
41 // Returns true if there is nothing to read in this buffer. 42 QuicErrorCode OnStreamData(QuicStreamOffset offset,
42 bool Empty() const { return frame_list_.empty(); } 43 StringPiece data,
43 44 QuicTime timestamp,
44 // Write the supplied data to this buffer. |timestamp| is used for 45 size_t* bytes_buffered) override;
45 // measuring head of line (HOL) blocking. If the write was 46 size_t Readv(const struct iovec* iov, size_t iov_len) override;
46 // successful, return the number of bytes written in 47 int GetReadableRegions(struct iovec* iov, int iov_len) const override;
47 // |bytes_written|. Return QUIC_INVALID_STREAM_DATA if |data| 48 bool GetReadableRegion(iovec* iov, QuicTime* timestamp) const override;
48 // overlaps with existing data. No data will be written. Return 49 bool MarkConsumed(size_t bytes_used) override;
49 // QUIC_NO_ERROR, if |data| is duplicated with data written 50 size_t FlushBufferedFrames() override;
50 // previously, and |bytes_written| = 0 51 bool HasBytesToRead() const override;
51 QuicErrorCode WriteAtOffset(QuicStreamOffset offset, 52 QuicStreamOffset BytesConsumed() const override;
52 StringPiece data, 53 size_t BytesBuffered() const override;
53 QuicTime timestamp,
54 size_t* bytes_written);
55
56 // Read from this buffer into given iovec array, upto number of iov_len iovec
57 // objects.
58 // Returns the number of bytes read into iov.
59 size_t ReadvAndInvalidate(const struct iovec* iov, size_t iov_len);
60
61 // Invalidate all currently readable bytes.
62 // Returns the number of bytes invalidated.
63 size_t FlushBufferedFrames();
64
65 // Returns the readable region of valid data in iovec format. The readable
66 // region is the buffer region where there is valid data not yet read by
67 // client. ReadAndInvalidate() and WriteAtOffset() change the readable region.
68 // The return value of this function is the number of iovec entries
69 // filled into in iov. If the region is empty, one iovec entry with 0 length
70 // is returned, and the function returns 0. If there are more readable
71 // regions than iov_size, the function only processes the first
72 // iov_size of them.
73 int GetReadableRegions(struct iovec* iov, int iov_len) const;
74
75 // Fills in one iovec with the next readable region. |timestamp| is
76 // data arrived at the sequencer, and is used for measuring head of
77 // line blocking (HOL). Returns false if there is no readable
78 // region available.
79 bool GetReadableRegion(iovec* iov, QuicTime* timestamp) const;
80
81 // Called after GetReadableRegions() to accumulate total_bytes_read_ and free
82 // up block when all data in it have been read out.
83 // Pre-requisite: bytes_used <= ReadableBytes()
84 bool IncreaseTotalReadAndInvalidate(size_t bytes_used);
85
86 // Whether there are bytes can be read out (offset == total_bytes_read_)
87 bool HasBytesToRead() const;
88
89 size_t size() const { return frame_list_.size(); }
90
91 QuicStreamOffset total_bytes_read() const { return total_bytes_read_; }
92 54
93 private: 55 private:
94 friend class test::QuicStreamSequencerPeer; 56 friend class test::QuicStreamSequencerPeer;
95 57
96 list<FrameData>::iterator FindInsertionPoint(QuicStreamOffset offset, 58 list<FrameData>::iterator FindInsertionPoint(QuicStreamOffset offset,
97 size_t len); 59 size_t len);
98 60
99 bool FrameOverlapsBufferedData( 61 bool FrameOverlapsBufferedData(
100 QuicStreamOffset offset, 62 QuicStreamOffset offset,
101 size_t data_len, 63 size_t data_len,
102 list<FrameData>::const_iterator insertion_point) const; 64 list<FrameData>::const_iterator insertion_point) const;
103 65
104 bool IsDuplicate(QuicStreamOffset offset, 66 bool IsDuplicate(QuicStreamOffset offset,
105 size_t data_len, 67 size_t data_len,
106 list<FrameData>::const_iterator insertion_point) const; 68 list<FrameData>::const_iterator insertion_point) const;
107 69
108 list<FrameData> frame_list_; 70 list<FrameData> frame_list_;
71
72 // Number of bytes in buffer.
73 size_t num_bytes_buffered_ = 0;
74
109 QuicStreamOffset total_bytes_read_ = 0; 75 QuicStreamOffset total_bytes_read_ = 0;
110 }; 76 };
111 77
112 } // namespace net_quic 78 } // namespace net
113 79
114 #endif // NET_QUIC_QUIC_FRAME_LIST_H_ 80 #endif // NET_QUIC_QUIC_FRAME_LIST_H_
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | net/quic/quic_frame_list.cc » ('j') | net/quic/quic_stream_sequencer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698