OLD | NEW |
(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 <map> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "net/quic/quic_protocol.h" |
| 13 |
| 14 using std::map; |
| 15 using std::string; |
| 16 |
| 17 namespace net { |
| 18 |
| 19 class QuicSession; |
| 20 class ReliableQuicStream; |
| 21 |
| 22 // Buffers frames until we have something which can be passed |
| 23 // up to the next layer. |
| 24 // TOOD(alyssar) add some checks for overflow attempts [1, 256,] [2, 256] |
| 25 class NET_EXPORT_PRIVATE QuicStreamSequencer { |
| 26 public: |
| 27 static size_t kMaxUdpPacketSize; |
| 28 |
| 29 explicit QuicStreamSequencer(ReliableQuicStream* quic_stream); |
| 30 QuicStreamSequencer(size_t max_frame_memory, |
| 31 ReliableQuicStream* quic_stream); |
| 32 |
| 33 virtual ~QuicStreamSequencer(); |
| 34 |
| 35 // Returns the expected value of OnStreamFrame for this frame. |
| 36 bool WillAcceptStreamFrame(const QuicStreamFrame& frame) const; |
| 37 |
| 38 // If the frame is the next one we need in order to process in-order data, |
| 39 // ProcessData will be immediately called on the stream until all buffered |
| 40 // data is processed or the stream fails to consume data. Any unconsumed |
| 41 // data will be buffered. |
| 42 // |
| 43 // If the frame is not the next in line, it will either be buffered, and |
| 44 // this will return true, or it will be rejected and this will return false. |
| 45 bool OnStreamFrame(const QuicStreamFrame& frame); |
| 46 |
| 47 // Wait until we've seen 'offset' bytes, and then terminate the stream. |
| 48 void CloseStreamAtOffset(QuicStreamOffset offset, bool half_close); |
| 49 |
| 50 // Once data is buffered, it's up to the stream to read it when the stream |
| 51 // can handle more data. The following three functions make that possible. |
| 52 |
| 53 // Advances the readable pointer num_bytes bytes, releasing any buffered data |
| 54 // which is no longer in uses |
| 55 void AdvanceReadablePtr(size_t num_bytes); |
| 56 |
| 57 // Returns true if the sequncer has bytes available for reading. |
| 58 bool HasBytesToRead(); |
| 59 |
| 60 // Returns true if the sequencer has delivered a half close. |
| 61 bool IsHalfClosed(); |
| 62 |
| 63 // Returns true if the sequencer has delivered a full close. |
| 64 bool IsClosed(); |
| 65 |
| 66 private: |
| 67 bool MaybeCloseStream(); |
| 68 |
| 69 friend class QuicStreamSequencerPeer; |
| 70 // TODO(alyssar) use something better than strings. |
| 71 typedef map<QuicStreamOffset, string> FrameMap; |
| 72 |
| 73 void FlushBufferedFrames(); |
| 74 |
| 75 ReliableQuicStream* stream_; // The stream which owns this sequencer. |
| 76 QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream |
| 77 FrameMap frames_; // sequence number -> frame |
| 78 size_t max_frame_memory_; // the maximum memory the sequencer can buffer. |
| 79 // The offset, if any, we got a stream cancelation for. When this many bytes |
| 80 // have been processed, the stream will be half or full closed depending on |
| 81 // the half_close_ bool. |
| 82 QuicStreamOffset close_offset_; |
| 83 // Only valid if close_offset_ is set. Indicates if it's a half or a full |
| 84 // close. |
| 85 bool half_close_; |
| 86 }; |
| 87 |
| 88 } // namespace net |
| 89 |
| 90 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
OLD | NEW |