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

Side by Side Diff: net/quic/core/quic_stream_sequencer_buffer.h

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 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
« no previous file with comments | « net/quic/core/quic_stream_sequencer.cc ('k') | net/quic/core/quic_stream_sequencer_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_ 5 #ifndef NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_
6 #define NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_ 6 #define NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_
7 7
8 // QuicStreamSequencerBuffer is a circular stream buffer with random write and 8 // QuicStreamSequencerBuffer is a circular stream buffer with random write and
9 // in-sequence read. It consists of a vector of pointers pointing 9 // in-sequence read. It consists of a vector of pointers pointing
10 // to memory blocks created as needed and a list of Gaps to indicate 10 // to memory blocks created as needed and a list of Gaps to indicate
(...skipping 10 matching lines...) Expand all
21 // 21 //
22 // QuicStreamSequencerBuffer maintains a concept of the readable region, which 22 // QuicStreamSequencerBuffer maintains a concept of the readable region, which
23 // contains all written data that has not been read. 23 // contains all written data that has not been read.
24 // It promises stability of the underlying memory addresses in the readable 24 // It promises stability of the underlying memory addresses in the readable
25 // region, so pointers into it can be maintained, and the offset of a pointer 25 // region, so pointers into it can be maintained, and the offset of a pointer
26 // from the start of the read region can be calculated. 26 // from the start of the read region can be calculated.
27 // 27 //
28 // Expected Use: 28 // Expected Use:
29 // QuicStreamSequencerBuffer buffer(2.5 * 8 * 1024); 29 // QuicStreamSequencerBuffer buffer(2.5 * 8 * 1024);
30 // std::string source(1024, 'a'); 30 // std::string source(1024, 'a');
31 // base::StringPiece std::string_piece(source.data(), source.size()); 31 // QuicStringPiece std::string_piece(source.data(), source.size());
32 // size_t written = 0; 32 // size_t written = 0;
33 // buffer.OnStreamData(800, std::string_piece, GetEpollClockNow(), &written); 33 // buffer.OnStreamData(800, std::string_piece, GetEpollClockNow(), &written);
34 // source = std::string{800, 'b'}; 34 // source = std::string{800, 'b'};
35 // base::StringPiece std::string_piece1(source.data(), 800); 35 // QuicStringPiece std::string_piece1(source.data(), 800);
36 // // Try to write to [1, 801), but should fail due to overlapping, 36 // // Try to write to [1, 801), but should fail due to overlapping,
37 // // res should be QUIC_INVALID_STREAM_DATA 37 // // res should be QUIC_INVALID_STREAM_DATA
38 // auto res = buffer.OnStreamData(1, std::string_piece1, &written)); 38 // auto res = buffer.OnStreamData(1, std::string_piece1, &written));
39 // // write to [0, 800), res should be QUIC_NO_ERROR 39 // // write to [0, 800), res should be QUIC_NO_ERROR
40 // auto res = buffer.OnStreamData(0, std::string_piece1, GetEpollClockNow(), 40 // auto res = buffer.OnStreamData(0, std::string_piece1, GetEpollClockNow(),
41 // &written); 41 // &written);
42 // 42 //
43 // // Read into a iovec array with total capacity of 120 bytes. 43 // // Read into a iovec array with total capacity of 120 bytes.
44 // char dest[120]; 44 // char dest[120];
45 // iovec iovecs[3]{iovec{dest, 40}, iovec{dest + 40, 40}, 45 // iovec iovecs[3]{iovec{dest, 40}, iovec{dest + 40, 40},
(...skipping 14 matching lines...) Expand all
60 // buffer.MarkConsumed(consumed); 60 // buffer.MarkConsumed(consumed);
61 61
62 #include <cstddef> 62 #include <cstddef>
63 #include <functional> 63 #include <functional>
64 #include <list> 64 #include <list>
65 #include <memory> 65 #include <memory>
66 66
67 #include "base/macros.h" 67 #include "base/macros.h"
68 #include "net/quic/core/quic_packets.h" 68 #include "net/quic/core/quic_packets.h"
69 #include "net/quic/platform/api/quic_export.h" 69 #include "net/quic/platform/api/quic_export.h"
70 #include "net/quic/platform/api/quic_string_piece.h"
70 71
71 namespace net { 72 namespace net {
72 73
73 namespace test { 74 namespace test {
74 class QuicStreamSequencerBufferPeer; 75 class QuicStreamSequencerBufferPeer;
75 } // namespace test 76 } // namespace test
76 77
77 class QUIC_EXPORT_PRIVATE QuicStreamSequencerBuffer { 78 class QUIC_EXPORT_PRIVATE QuicStreamSequencerBuffer {
78 public: 79 public:
79 // A Gap indicates a missing chunk of bytes between 80 // A Gap indicates a missing chunk of bytes between
(...skipping 30 matching lines...) Expand all
110 void Clear(); 111 void Clear();
111 112
112 // Returns true if there is nothing to read in this buffer. 113 // Returns true if there is nothing to read in this buffer.
113 bool Empty() const; 114 bool Empty() const;
114 115
115 // Called to buffer new data received for this stream. If the data was 116 // Called to buffer new data received for this stream. If the data was
116 // successfully buffered, returns QUIC_NO_ERROR and stores the number of 117 // successfully buffered, returns QUIC_NO_ERROR and stores the number of
117 // bytes buffered in |bytes_buffered|. Returns an error otherwise. 118 // bytes buffered in |bytes_buffered|. Returns an error otherwise.
118 // |timestamp| is the time the data arrived. 119 // |timestamp| is the time the data arrived.
119 QuicErrorCode OnStreamData(QuicStreamOffset offset, 120 QuicErrorCode OnStreamData(QuicStreamOffset offset,
120 base::StringPiece data, 121 QuicStringPiece data,
121 QuicTime timestamp, 122 QuicTime timestamp,
122 size_t* bytes_buffered, 123 size_t* bytes_buffered,
123 std::string* error_details); 124 std::string* error_details);
124 125
125 // Reads from this buffer into given iovec array, up to number of iov_len 126 // Reads from this buffer into given iovec array, up to number of iov_len
126 // iovec objects and returns the number of bytes read. 127 // iovec objects and returns the number of bytes read.
127 QuicErrorCode Readv(const struct iovec* dest_iov, 128 QuicErrorCode Readv(const struct iovec* dest_iov,
128 size_t dest_count, 129 size_t dest_count,
129 size_t* bytes_read, 130 size_t* bytes_read,
130 std::string* error_details); 131 std::string* error_details);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // For debugging use after free, assigned to 123456 in constructor and 654321 248 // For debugging use after free, assigned to 123456 in constructor and 654321
248 // in destructor. As long as it's not 123456, this means either use after free 249 // in destructor. As long as it's not 123456, this means either use after free
249 // or memory corruption. 250 // or memory corruption.
250 int32_t destruction_indicator_; 251 int32_t destruction_indicator_;
251 252
252 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencerBuffer); 253 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencerBuffer);
253 }; 254 };
254 } // namespace net 255 } // namespace net
255 256
256 #endif // NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_ 257 #endif // NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_
OLDNEW
« no previous file with comments | « net/quic/core/quic_stream_sequencer.cc ('k') | net/quic/core/quic_stream_sequencer_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698