OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_STREAM_SEQUENCER_H_ | 5 #ifndef NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
6 #define NET_QUIC_QUIC_STREAM_SEQUENCER_H_ | 6 #define NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // If the frame is the next one we need in order to process in-order data, | 43 // If the frame is the next one we need in order to process in-order data, |
44 // ProcessData will be immediately called on the stream until all buffered | 44 // ProcessData will be immediately called on the stream until all buffered |
45 // data is processed or the stream fails to consume data. Any unconsumed | 45 // data is processed or the stream fails to consume data. Any unconsumed |
46 // data will be buffered. | 46 // data will be buffered. |
47 // | 47 // |
48 // If the frame is not the next in line, it will either be buffered, and | 48 // If the frame is not the next in line, it will either be buffered, and |
49 // this will return true, or it will be rejected and this will return false. | 49 // this will return true, or it will be rejected and this will return false. |
50 bool OnStreamFrame(const QuicStreamFrame& frame); | 50 bool OnStreamFrame(const QuicStreamFrame& frame); |
51 | 51 |
52 // Wait until we've seen 'offset' bytes, and then terminate the stream. | 52 // Wait until we've seen 'offset' bytes, and then terminate the stream. |
53 // TODO(ianswett): Simplify this method by removing half_close, now that | 53 void CloseStreamAtOffset(QuicStreamOffset offset); |
54 // the sequencer is bypassed for stream resets and half_close is always true. | |
55 void CloseStreamAtOffset(QuicStreamOffset offset, bool half_close); | |
56 | 54 |
57 // Once data is buffered, it's up to the stream to read it when the stream | 55 // Once data is buffered, it's up to the stream to read it when the stream |
58 // can handle more data. The following three functions make that possible. | 56 // can handle more data. The following three functions make that possible. |
59 | 57 |
60 // Fills in up to iov_len iovecs with the next readable regions. Returns the | 58 // Fills in up to iov_len iovecs with the next readable regions. Returns the |
61 // number of iovs used. Non-destructive of the underlying data. | 59 // number of iovs used. Non-destructive of the underlying data. |
62 int GetReadableRegions(iovec* iov, size_t iov_len); | 60 int GetReadableRegions(iovec* iov, size_t iov_len); |
63 | 61 |
64 // Copies the data into the iov_len buffers provided. Returns the number of | 62 // Copies the data into the iov_len buffers provided. Returns the number of |
65 // bytes read. Any buffered data no longer in use will be released. | 63 // bytes read. Any buffered data no longer in use will be released. |
66 int Readv(const struct iovec* iov, size_t iov_len); | 64 int Readv(const struct iovec* iov, size_t iov_len); |
67 | 65 |
68 // Consumes |num_bytes| data. Used in conjunction with |GetReadableRegions| | 66 // Consumes |num_bytes| data. Used in conjunction with |GetReadableRegions| |
69 // to do zero-copy reads. | 67 // to do zero-copy reads. |
70 void MarkConsumed(size_t num_bytes); | 68 void MarkConsumed(size_t num_bytes); |
71 | 69 |
72 // Returns true if the sequncer has bytes available for reading. | 70 // Returns true if the sequncer has bytes available for reading. |
73 bool HasBytesToRead() const; | 71 bool HasBytesToRead() const; |
74 | 72 |
75 // Returns true if the sequencer has delivered a half close. | 73 // Returns true if the sequencer has delivered a half close. |
76 bool IsHalfClosed() const; | 74 bool IsHalfClosed() const; |
77 | 75 |
78 // Returns true if the sequencer has delivered a full close. | |
79 bool IsClosed() const; | |
80 | |
81 // Returns true if the sequencer has received this frame before. | 76 // Returns true if the sequencer has received this frame before. |
82 bool IsDuplicate(const QuicStreamFrame& frame) const; | 77 bool IsDuplicate(const QuicStreamFrame& frame) const; |
83 | 78 |
84 // Calls |ProcessRawData| on |stream_| for each buffered frame that may | 79 // Calls |ProcessRawData| on |stream_| for each buffered frame that may |
85 // be processed. | 80 // be processed. |
86 void FlushBufferedFrames(); | 81 void FlushBufferedFrames(); |
87 | 82 |
88 private: | 83 private: |
89 friend class test::QuicStreamSequencerPeer; | 84 friend class test::QuicStreamSequencerPeer; |
90 | 85 |
91 // TODO(alyssar) use something better than strings. | 86 // TODO(alyssar) use something better than strings. |
92 typedef map<QuicStreamOffset, string> FrameMap; | 87 typedef map<QuicStreamOffset, string> FrameMap; |
93 | 88 |
94 bool MaybeCloseStream(); | 89 bool MaybeCloseStream(); |
95 | 90 |
96 ReliableQuicStream* stream_; // The stream which owns this sequencer. | 91 ReliableQuicStream* stream_; // The stream which owns this sequencer. |
97 QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream | 92 QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream |
98 FrameMap frames_; // sequence number -> frame | 93 FrameMap frames_; // sequence number -> frame |
99 size_t max_frame_memory_; // the maximum memory the sequencer can buffer. | 94 size_t max_frame_memory_; // the maximum memory the sequencer can buffer. |
100 // The offset, if any, we got a stream cancelation for. When this many bytes | 95 // The offset, if any, we got a stream termination for. When this many bytes |
101 // have been processed, the stream will be half or full closed depending on | 96 // have been processed, the stream will be half closed. |
102 // the half_close_ bool. | |
103 QuicStreamOffset close_offset_; | 97 QuicStreamOffset close_offset_; |
104 // Only valid if close_offset_ is set. Indicates if it's a half or a full | |
105 // close. | |
106 bool half_close_; | |
107 }; | 98 }; |
108 | 99 |
109 } // namespace net | 100 } // namespace net |
110 | 101 |
111 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ | 102 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
OLD | NEW |