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

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

Issue 11300020: Add QuicStream and friends to QUIC code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: License Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_QUIC_STREAM_SEQUENCER_H_
6 #define NET_QUIC_QUIC_STREAM_SEQUENCER_H_
7
8 #include <sys/uio.h>
9
10 #include <map>
11
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "net/quic/quic_protocol.h"
15
16 using std::map;
17 using std::string;
18
19 namespace net {
20
21 class QuicSession;
22 class ReliableQuicStream;
23
24 // Buffers frames until we have something which can be passed
25 // up to the next layer.
26 // TOOD(alyssar) add some checks for overflow attempts [1, 256,] [2, 256]
27 class QuicStreamSequencer {
28 public:
29 static size_t kMaxUdpPacketSize;
30
31 explicit QuicStreamSequencer(ReliableQuicStream* quic_stream);
32 QuicStreamSequencer(size_t max_frame_memory,
33 ReliableQuicStream* quic_stream);
34
35 virtual ~QuicStreamSequencer();
36
37 // Returns the expected value of OnStreamFrame for this frame.
38 bool WillAcceptStreamFrame(const QuicStreamFrame& frame) const;
39
40 // If the frame is the next one we need in order to process in-order data,
41 // ProcessData will be immediately called on the stream until all buffered
42 // data is processed or the stream fails to consume data. Any unconsumed
43 // data will be buffered.
44 //
45 // If the frame is not the next in line, it will either be buffered, and
46 // this will return true, or it will be rejected and this will return false.
47 bool OnStreamFrame(const QuicStreamFrame& frame);
48
49 // Wait until we've seen 'offset' bytes, and then terminate the stream.
50 void CloseStreamAtOffset(QuicStreamOffset offset, bool half_close);
51
52 // Once data is buffered, it's up to the stream to read it when the stream
53 // can handle more data. The following three functions make that possible.
54
55 // Fills in up to iov_len iovecs with the next readable regions. Returns the
56 // number of iovs used. Non-destructive of the underlying data.
57 size_t GetReadableRegions(iovec* iov, size_t iov_len);
58
59 // Advances the readable pointer num_bytes bytes, releasing any buffered data
60 // which is no longer in uses
61 void AdvanceReadablePtr(size_t num_bytes);
62
63 // Copies the data into the iov_len buffers provided. Returns the number of
64 // iovs used. Any buffered data no longer in use will be released.
jar (doing other things) 2012/10/31 22:37:37 Reading the code, it appears to return the number
Ryan Hamilton 2012/11/01 22:52:20 Fixed upstream.
65 size_t Readv(const struct iovec* iov, size_t iov_len);
66
67 // Returns true if the sequncer has bytes available for reading.
68 bool HasBytesToRead();
69
70 // Returns true if the sequencer has delivered a half close.
71 bool IsHalfClosed();
72
73 // Returns true if the sequencer has delivered a full close.
74 bool IsClosed();
75
76 private:
77 bool MaybeCloseStream();
jar (doing other things) 2012/10/31 22:37:37 nit: methods after typedefs etc.
Ryan Hamilton 2012/11/01 22:52:20 Fixed upstream.
78
79 friend class QuicStreamSequencerPeer;
80 // TODO(alyssar) use something better than strings.
81 typedef map<QuicStreamOffset, string> FrameMap;
82
83 void FlushBufferedFrames();
84
85 ReliableQuicStream* stream_; // The stream which owns this sequencer.
86 QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream
87 FrameMap frames_; // sequence number -> frame
88 size_t max_frame_memory_; // the maximum memory the sequencer can buffer.
89 // The offset, if any, we got a stream cancelation for. When this many bytes
90 // have been processed, the stream will be half or full closed depending on
91 // the half_close_ bool.
92 QuicStreamOffset close_offset_;
93 // Only valid if close_offset_ is set. Indicates if it's a half or a full
94 // close.
95 bool half_close_;
96 };
97
98 } // namespace net
99
100 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698