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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: net/quic/quic_stream_sequencer.h
diff --git a/net/quic/quic_stream_sequencer.h b/net/quic/quic_stream_sequencer.h
new file mode 100644
index 0000000000000000000000000000000000000000..d8d99eb020ef6c205b4b9450329d13fd3b3591a0
--- /dev/null
+++ b/net/quic/quic_stream_sequencer.h
@@ -0,0 +1,100 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_QUIC_QUIC_STREAM_SEQUENCER_H_
+#define NET_QUIC_QUIC_STREAM_SEQUENCER_H_
+
+#include <sys/uio.h>
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/quic/quic_protocol.h"
+
+using std::map;
+using std::string;
+
+namespace net {
+
+class QuicSession;
+class ReliableQuicStream;
+
+// Buffers frames until we have something which can be passed
+// up to the next layer.
+// TOOD(alyssar) add some checks for overflow attempts [1, 256,] [2, 256]
+class QuicStreamSequencer {
+ public:
+ static size_t kMaxUdpPacketSize;
+
+ explicit QuicStreamSequencer(ReliableQuicStream* quic_stream);
+ QuicStreamSequencer(size_t max_frame_memory,
+ ReliableQuicStream* quic_stream);
+
+ virtual ~QuicStreamSequencer();
+
+ // Returns the expected value of OnStreamFrame for this frame.
+ bool WillAcceptStreamFrame(const QuicStreamFrame& frame) const;
+
+ // If the frame is the next one we need in order to process in-order data,
+ // ProcessData will be immediately called on the stream until all buffered
+ // data is processed or the stream fails to consume data. Any unconsumed
+ // data will be buffered.
+ //
+ // If the frame is not the next in line, it will either be buffered, and
+ // this will return true, or it will be rejected and this will return false.
+ bool OnStreamFrame(const QuicStreamFrame& frame);
+
+ // Wait until we've seen 'offset' bytes, and then terminate the stream.
+ void CloseStreamAtOffset(QuicStreamOffset offset, bool half_close);
+
+ // Once data is buffered, it's up to the stream to read it when the stream
+ // can handle more data. The following three functions make that possible.
+
+ // Fills in up to iov_len iovecs with the next readable regions. Returns the
+ // number of iovs used. Non-destructive of the underlying data.
+ size_t GetReadableRegions(iovec* iov, size_t iov_len);
+
+ // Advances the readable pointer num_bytes bytes, releasing any buffered data
+ // which is no longer in uses
+ void AdvanceReadablePtr(size_t num_bytes);
+
+ // Copies the data into the iov_len buffers provided. Returns the number of
+ // 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.
+ size_t Readv(const struct iovec* iov, size_t iov_len);
+
+ // Returns true if the sequncer has bytes available for reading.
+ bool HasBytesToRead();
+
+ // Returns true if the sequencer has delivered a half close.
+ bool IsHalfClosed();
+
+ // Returns true if the sequencer has delivered a full close.
+ bool IsClosed();
+
+ private:
+ 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.
+
+ friend class QuicStreamSequencerPeer;
+ // TODO(alyssar) use something better than strings.
+ typedef map<QuicStreamOffset, string> FrameMap;
+
+ void FlushBufferedFrames();
+
+ ReliableQuicStream* stream_; // The stream which owns this sequencer.
+ QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream
+ FrameMap frames_; // sequence number -> frame
+ size_t max_frame_memory_; // the maximum memory the sequencer can buffer.
+ // The offset, if any, we got a stream cancelation for. When this many bytes
+ // have been processed, the stream will be half or full closed depending on
+ // the half_close_ bool.
+ QuicStreamOffset close_offset_;
+ // Only valid if close_offset_ is set. Indicates if it's a half or a full
+ // close.
+ bool half_close_;
+};
+
+} // namespace net
+
+#endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_

Powered by Google App Engine
This is Rietveld 408576698