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