| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "net/base/iovec.h" |
| 12 #include "net/quic/quic_protocol.h" | 13 #include "net/quic/quic_protocol.h" |
| 13 | 14 |
| 14 using std::map; | 15 using std::map; |
| 15 using std::string; | 16 using std::string; |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 namespace test { | 20 namespace test { |
| 20 class QuicStreamSequencerPeer; | 21 class QuicStreamSequencerPeer; |
| 21 } // namespace test | 22 } // namespace test |
| (...skipping 27 matching lines...) Expand all Loading... |
| 49 bool OnStreamFrame(const QuicStreamFrame& frame); | 50 bool OnStreamFrame(const QuicStreamFrame& frame); |
| 50 | 51 |
| 51 // 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. |
| 52 // TODO(ianswett): Simplify this method by removing half_close, now that | 53 // TODO(ianswett): Simplify this method by removing half_close, now that |
| 53 // the sequencer is bypassed for stream resets and half_close is always true. | 54 // the sequencer is bypassed for stream resets and half_close is always true. |
| 54 void CloseStreamAtOffset(QuicStreamOffset offset, bool half_close); | 55 void CloseStreamAtOffset(QuicStreamOffset offset, bool half_close); |
| 55 | 56 |
| 56 // Once data is buffered, it's up to the stream to read it when the stream | 57 // Once data is buffered, it's up to the stream to read it when the stream |
| 57 // can handle more data. The following three functions make that possible. | 58 // can handle more data. The following three functions make that possible. |
| 58 | 59 |
| 60 // 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. |
| 62 int GetReadableRegions(iovec* iov, int iov_len); |
| 63 |
| 64 // 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. |
| 66 int Readv(const struct iovec* iov, int iov_len); |
| 67 |
| 68 // Consumes |num_bytes| data. Used in conjunction with |GetReadableRegions| |
| 69 // to do zero-copy reads. |
| 70 void MarkConsumed(size_t num_bytes); |
| 71 |
| 59 // Returns true if the sequncer has bytes available for reading. | 72 // Returns true if the sequncer has bytes available for reading. |
| 60 bool HasBytesToRead() const; | 73 bool HasBytesToRead() const; |
| 61 | 74 |
| 62 // Returns true if the sequencer has delivered a half close. | 75 // Returns true if the sequencer has delivered a half close. |
| 63 bool IsHalfClosed() const; | 76 bool IsHalfClosed() const; |
| 64 | 77 |
| 65 // Returns true if the sequencer has delivered a full close. | 78 // Returns true if the sequencer has delivered a full close. |
| 66 bool IsClosed() const; | 79 bool IsClosed() const; |
| 67 | 80 |
| 68 // Returns true if the sequencer has received this frame before. | 81 // Returns true if the sequencer has received this frame before. |
| 69 bool IsDuplicate(const QuicStreamFrame& frame) const; | 82 bool IsDuplicate(const QuicStreamFrame& frame) const; |
| 70 | 83 |
| 84 // Calls |ProcessRawData| on |stream_| for each buffered frame that may |
| 85 // be processed. |
| 86 void FlushBufferedFrames(); |
| 87 |
| 71 private: | 88 private: |
| 72 friend class test::QuicStreamSequencerPeer; | 89 friend class test::QuicStreamSequencerPeer; |
| 73 | 90 |
| 74 // TODO(alyssar) use something better than strings. | 91 // TODO(alyssar) use something better than strings. |
| 75 typedef map<QuicStreamOffset, string> FrameMap; | 92 typedef map<QuicStreamOffset, string> FrameMap; |
| 76 | 93 |
| 77 void FlushBufferedFrames(); | |
| 78 | |
| 79 bool MaybeCloseStream(); | 94 bool MaybeCloseStream(); |
| 80 | 95 |
| 81 ReliableQuicStream* stream_; // The stream which owns this sequencer. | 96 ReliableQuicStream* stream_; // The stream which owns this sequencer. |
| 82 QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream | 97 QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream |
| 83 FrameMap frames_; // sequence number -> frame | 98 FrameMap frames_; // sequence number -> frame |
| 84 size_t max_frame_memory_; // the maximum memory the sequencer can buffer. | 99 size_t max_frame_memory_; // the maximum memory the sequencer can buffer. |
| 85 // The offset, if any, we got a stream cancelation for. When this many bytes | 100 // The offset, if any, we got a stream cancelation for. When this many bytes |
| 86 // have been processed, the stream will be half or full closed depending on | 101 // have been processed, the stream will be half or full closed depending on |
| 87 // the half_close_ bool. | 102 // the half_close_ bool. |
| 88 QuicStreamOffset close_offset_; | 103 QuicStreamOffset close_offset_; |
| 89 // Only valid if close_offset_ is set. Indicates if it's a half or a full | 104 // Only valid if close_offset_ is set. Indicates if it's a half or a full |
| 90 // close. | 105 // close. |
| 91 bool half_close_; | 106 bool half_close_; |
| 92 }; | 107 }; |
| 93 | 108 |
| 94 } // namespace net | 109 } // namespace net |
| 95 | 110 |
| 96 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ | 111 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
| OLD | NEW |