reliable_quic_stream.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The base class for client/server reliable streams.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_QUIC_RELIABLE_QUIC_STREAM_H_
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_QUIC_RELIABLE_QUIC_STREAM_H_
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <sys/types.h>
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <list>
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
14b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "base/strings/string_piece.h"
15b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "net/base/iovec.h"
16b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "net/base/net_export.h"
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/quic/quic_ack_notifier.h"
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "net/quic/quic_spdy_compressor.h"
19b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "net/quic/quic_spdy_decompressor.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_stream_sequencer.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test {
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ReliableQuicStreamPeer;
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace test
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class IPEndPoint;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class QuicSession;
307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SSLInfo;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define ENDPOINT (is_server_ ? "Server: " : " Client: ")
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All this does right now is send data to subclasses via the sequencer.
35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class NET_EXPORT_PRIVATE ReliableQuicStream : public
36b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    QuicSpdyDecompressor::Visitor {
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Visitor receives callbacks from the stream.
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  class Visitor {
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   public:
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Visitor() {}
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Called when the stream is closed.
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    virtual void OnClose(ReliableQuicStream* stream) = 0;
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   protected:
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    virtual ~Visitor() {}
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   private:
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(Visitor);
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ReliableQuicStream(QuicStreamId id,
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     QuicSession* session);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ReliableQuicStream();
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool WillAcceptStreamFrame(const QuicStreamFrame& frame) const;
59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Called when a (potentially duplicate) stream frame has been received
61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // for this stream.  Returns false if this frame can not be accepted
62a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // because there is too much data already buffered.
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool OnStreamFrame(const QuicStreamFrame& frame);
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Called when the connection becomes writeable to allow the stream
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // to write any pending data.
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnCanWrite();
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Called by the session just before the stream is deleted.
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnClose();
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Called when we get a stream reset from the peer.
73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void OnStreamReset(QuicRstStreamErrorCode error);
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when we get or send a connection close, and should immediately
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // close the stream.  This is not passed through the sequencer,
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // but is handled immediately.
781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer);
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
80a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Called when the final data has been read.
81a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void OnFinRead();
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
83b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual uint32 ProcessRawData(const char* data, uint32 data_len);
84b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual uint32 ProcessData(const char* data, uint32 data_len) = 0;
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
87b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual bool OnDecompressedData(base::StringPiece data) OVERRIDE;
8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OnDecompressionError() OVERRIDE;
89b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
90a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Called to reset the stream from this end.
91a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void Reset(QuicRstStreamErrorCode error);
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Called to close the entire connection from this end.
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void CloseConnection(QuicErrorCode error);
951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void CloseConnectionWithDetails(QuicErrorCode error,
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                          const string& details);
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This block of functions wraps the sequencer's functions of the same
99b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // name.  These methods return uncompressed data until that has
100b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // been fully processed.  Then they simply delegate to the sequencer.
1015e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)  virtual size_t Readv(const struct iovec* iov, size_t iov_len);
102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual int GetReadableRegions(iovec* iov, size_t iov_len);
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Returns true when all data has been read from the peer, including the fin.
104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual bool IsDoneReading() const;
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HasBytesToRead() const;
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
107b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Called by the session when a decompression blocked stream
108b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // becomes unblocked.
109b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual void OnDecompressorAvailable();
110b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
111d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // By default, this is the same as priority(), however it allows streams
112d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // to temporarily alter effective priority.   For example if a SPDY stream has
113d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // compressed but not written headers it can write the headers with a higher
114d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // priority.
115d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual QuicPriority EffectivePriority() const;
116d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicStreamId id() const { return id_; }
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QuicRstStreamErrorCode stream_error() const { return stream_error_; }
120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QuicErrorCode connection_error() const { return connection_error_; }
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool read_side_closed() const { return read_side_closed_; }
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool write_side_closed() const { return write_side_closed_; }
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
125b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  uint64 stream_bytes_read() { return stream_bytes_read_; }
126b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  uint64 stream_bytes_written() { return stream_bytes_written_; }
127b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const IPEndPoint& GetPeerAddress() const;
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_visitor(Visitor* visitor) { visitor_ = visitor; }
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  QuicSpdyCompressor* compressor();
13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Gets the SSL connection information.
1357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool GetSSLInfo(SSLInfo* ssl_info);
1367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1372385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  bool headers_decompressed() const { return headers_decompressed_; }
1382385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns a pair with the number of bytes consumed from data, and a boolean
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // indicating if the fin bit was consumed.  This does not indicate the data
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // has been sent on the wire: it may have been turned into a packet and queued
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // if the socket was unexpectedly blocked.
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The default implementation always consumed all bytes and any fin, but
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // this behavior is not guaranteed for subclasses so callers should check the
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // return value.
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual QuicConsumedData WriteData(base::StringPiece data, bool fin);
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Close the read side of the socket.  Further frames will not be accepted.
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void CloseReadSide();
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Close the write side of the socket.  Further writes will fail.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CloseWriteSide();
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool HasBufferedData();
15758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
158b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  bool fin_buffered() { return fin_buffered_; }
159b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicSession* session() { return session_; }
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
162d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Sets priority_ to priority.  This should only be called before bytes are
163d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // written to the server.
164d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  void set_priority(QuicPriority priority);
165d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // This is protected because external classes should use EffectivePriority
166d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // instead.
167d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  QuicPriority priority() const { return priority_; }
168d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sends as much of 'data' to the connection as the connection will consume,
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // and then buffers any remaining data in queued_data_.
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns (data.size(), true) as it always consumed all data: it returns for
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // convenience to have the same return type as WriteDataInternal.
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicConsumedData WriteOrBuffer(base::StringPiece data, bool fin);
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sends as much of 'data' to the connection as the connection will consume.
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the number of bytes consumed by the connection.
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicConsumedData WriteDataInternal(base::StringPiece data, bool fin);
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
179d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Sends as many bytes in the first |count| buffers of |iov| to the connection
180d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // as the connection will consume.
181f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // If |ack_notifier_delegate| is provided, then it will be notified once all
182f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // the ACKs for this write have been received.
183d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns the number of bytes consumed by the connection.
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  QuicConsumedData WritevDataInternal(
185f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const struct iovec* iov,
186f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      int iov_count,
187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      bool fin,
188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      QuicAckNotifier::DelegateInterface* ack_notifier_delegate);
189d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class test::ReliableQuicStreamPeer;
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class QuicStreamUtils;
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
194a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  uint32 ProcessHeaderData();
195a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
196424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  uint32 StripPriorityAndHeaderId(const char* data, uint32 data_len);
197424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::list<string> queued_data_;
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicStreamSequencer sequencer_;
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicStreamId id_;
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicSession* session_;
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Optional visitor of this stream to be notified when the stream is closed.
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Visitor* visitor_;
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Bytes read and written refer to payload bytes only: they do not include
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // framing, encryption overhead etc.
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  uint64 stream_bytes_read_;
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  uint64 stream_bytes_written_;
209b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // True if the headers have been completely decompresssed.
210b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  bool headers_decompressed_;
211424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // The priority of the stream, once parsed.
212424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  QuicPriority priority_;
213b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // ID of the header block sent by the peer, once parsed.
214b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  QuicHeaderId headers_id_;
215424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Buffer into which we write bytes from priority_ and headers_id_
216424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // until each is fully parsed.
217424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  string headers_id_and_priority_buffer_;
218b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Contains a copy of the decompressed headers_ until they are consumed
219b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // via ProcessData or Readv.
220b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  string decompressed_headers_;
221558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // True if an error was encountered during decompression.
222558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  bool decompression_failed_;
223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
224c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Stream error code received from a RstStreamFrame or error code sent by the
225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // visitor or sequencer in the RstStreamFrame.
226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QuicRstStreamErrorCode stream_error_;
227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Connection error code due to which the stream was closed. |stream_error_|
228c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers
229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // should check |connection_error_|.
230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QuicErrorCode connection_error_;
231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // True if the read side is closed and further frames should be rejected.
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool read_side_closed_;
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // True if the write side is closed, and further writes should fail.
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool write_side_closed_;
2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
237424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // True if the priority has been read, false otherwise.
238424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  bool priority_parsed_;
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool fin_buffered_;
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool fin_sent_;
2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // True if the session this stream is running under is a server session.
2431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool is_server_;
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_QUIC_RELIABLE_QUIC_STREAM_H_
249