| 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 // The base class for client/server reliable streams. | 5 // The base class for client/server reliable streams. |
| 6 | 6 |
| 7 #ifndef NET_QUIC_RELIABLE_QUIC_STREAM_H_ | 7 #ifndef NET_QUIC_RELIABLE_QUIC_STREAM_H_ |
| 8 #define NET_QUIC_RELIABLE_QUIC_STREAM_H_ | 8 #define NET_QUIC_RELIABLE_QUIC_STREAM_H_ |
| 9 | 9 |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| 11 | 11 |
| 12 #include <list> | 12 #include <list> |
| 13 | 13 |
| 14 #include "base/strings/string_piece.h" |
| 15 #include "net/base/iovec.h" |
| 16 #include "net/base/net_export.h" |
| 17 #include "net/quic/quic_spdy_decompressor.h" |
| 14 #include "net/quic/quic_stream_sequencer.h" | 18 #include "net/quic/quic_stream_sequencer.h" |
| 15 | 19 |
| 16 namespace net { | 20 namespace net { |
| 17 | 21 |
| 18 namespace test { | 22 namespace test { |
| 19 class ReliableQuicStreamPeer; | 23 class ReliableQuicStreamPeer; |
| 20 } // namespace test | 24 } // namespace test |
| 21 | 25 |
| 22 class IPEndPoint; | 26 class IPEndPoint; |
| 23 class QuicSession; | 27 class QuicSession; |
| 24 | 28 |
| 25 // All this does right now is send data to subclasses via the sequencer. | 29 // All this does right now is send data to subclasses via the sequencer. |
| 26 class NET_EXPORT_PRIVATE ReliableQuicStream { | 30 class NET_EXPORT_PRIVATE ReliableQuicStream : public |
| 31 QuicSpdyDecompressor::Visitor { |
| 27 public: | 32 public: |
| 28 // Visitor receives callbacks from the stream. | 33 // Visitor receives callbacks from the stream. |
| 29 class Visitor { | 34 class Visitor { |
| 30 public: | 35 public: |
| 31 Visitor() {} | 36 Visitor() {} |
| 32 | 37 |
| 33 // Called when the stream is closed. | 38 // Called when the stream is closed. |
| 34 virtual void OnClose(ReliableQuicStream* stream) = 0; | 39 virtual void OnClose(ReliableQuicStream* stream) = 0; |
| 35 | 40 |
| 36 protected: | 41 protected: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 58 | 63 |
| 59 // Called when we get or send a connection close, and should immediately | 64 // Called when we get or send a connection close, and should immediately |
| 60 // close the stream. This is not passed through the sequencer, | 65 // close the stream. This is not passed through the sequencer, |
| 61 // but is handled immediately. | 66 // but is handled immediately. |
| 62 virtual void ConnectionClose(QuicErrorCode error, bool from_peer); | 67 virtual void ConnectionClose(QuicErrorCode error, bool from_peer); |
| 63 | 68 |
| 64 // Called by the sequencer, when we should process a stream termination or | 69 // Called by the sequencer, when we should process a stream termination or |
| 65 // stream close from the peer. | 70 // stream close from the peer. |
| 66 virtual void TerminateFromPeer(bool half_close); | 71 virtual void TerminateFromPeer(bool half_close); |
| 67 | 72 |
| 73 virtual uint32 ProcessRawData(const char* data, uint32 data_len); |
| 74 virtual uint32 ProcessHeaderData(); |
| 75 |
| 68 virtual uint32 ProcessData(const char* data, uint32 data_len) = 0; | 76 virtual uint32 ProcessData(const char* data, uint32 data_len) = 0; |
| 69 | 77 |
| 78 virtual bool OnDecompressedData(base::StringPiece data) OVERRIDE; |
| 79 |
| 70 // Called to close the stream from this end. | 80 // Called to close the stream from this end. |
| 71 virtual void Close(QuicRstStreamErrorCode error); | 81 virtual void Close(QuicRstStreamErrorCode error); |
| 72 | 82 |
| 73 // This block of functions wraps the sequencer's functions of the same | 83 // This block of functions wraps the sequencer's functions of the same |
| 74 // name. | 84 // name. These methods return uncompressed data until that has |
| 85 // been fully processed. Then they simply delegate to the sequencer. |
| 86 virtual int Readv(const struct iovec* iov, int iov_len); |
| 87 virtual int GetReadableRegions(iovec* iov, int iov_len); |
| 75 virtual bool IsHalfClosed() const; | 88 virtual bool IsHalfClosed() const; |
| 76 virtual bool IsClosed() const; | 89 virtual bool IsClosed() const; |
| 77 virtual bool HasBytesToRead() const; | 90 virtual bool HasBytesToRead() const; |
| 78 | 91 |
| 92 // Called by the session when a decompression blocked stream |
| 93 // becomes unblocked. |
| 94 virtual void OnDecompressorAvailable(); |
| 95 |
| 79 QuicStreamId id() const { return id_; } | 96 QuicStreamId id() const { return id_; } |
| 80 | 97 |
| 81 QuicRstStreamErrorCode stream_error() const { return stream_error_; } | 98 QuicRstStreamErrorCode stream_error() const { return stream_error_; } |
| 82 QuicErrorCode connection_error() const { return connection_error_; } | 99 QuicErrorCode connection_error() const { return connection_error_; } |
| 83 | 100 |
| 84 bool read_side_closed() const { return read_side_closed_; } | 101 bool read_side_closed() const { return read_side_closed_; } |
| 85 bool write_side_closed() const { return write_side_closed_; } | 102 bool write_side_closed() const { return write_side_closed_; } |
| 86 | 103 |
| 104 uint64 stream_bytes_read() { return stream_bytes_read_; } |
| 105 uint64 stream_bytes_written() { return stream_bytes_written_; } |
| 106 |
| 87 const IPEndPoint& GetPeerAddress() const; | 107 const IPEndPoint& GetPeerAddress() const; |
| 88 | 108 |
| 89 Visitor* visitor() { return visitor_; } | 109 Visitor* visitor() { return visitor_; } |
| 90 void set_visitor(Visitor* visitor) { visitor_ = visitor; } | 110 void set_visitor(Visitor* visitor) { visitor_ = visitor; } |
| 91 | 111 |
| 92 uint64 stream_bytes_read() const { return stream_bytes_read_; } | |
| 93 uint64 stream_bytes_written() const { return stream_bytes_written_; } | |
| 94 | |
| 95 protected: | 112 protected: |
| 96 // Returns a pair with the number of bytes consumed from data, and a boolean | 113 // Returns a pair with the number of bytes consumed from data, and a boolean |
| 97 // indicating if the fin bit was consumed. This does not indicate the data | 114 // indicating if the fin bit was consumed. This does not indicate the data |
| 98 // has been sent on the wire: it may have been turned into a packet and queued | 115 // has been sent on the wire: it may have been turned into a packet and queued |
| 99 // if the socket was unexpectedly blocked. | 116 // if the socket was unexpectedly blocked. |
| 100 // | 117 // |
| 101 // The default implementation always consumed all bytes and any fin, but | 118 // The default implementation always consumed all bytes and any fin, but |
| 102 // this behavior is not guaranteed for subclasses so callers should check the | 119 // this behavior is not guaranteed for subclasses so callers should check the |
| 103 // return value. | 120 // return value. |
| 104 virtual QuicConsumedData WriteData(base::StringPiece data, bool fin); | 121 virtual QuicConsumedData WriteData(base::StringPiece data, bool fin); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 129 | 146 |
| 130 QuicStreamSequencer sequencer_; | 147 QuicStreamSequencer sequencer_; |
| 131 QuicStreamId id_; | 148 QuicStreamId id_; |
| 132 QuicSession* session_; | 149 QuicSession* session_; |
| 133 // Optional visitor of this stream to be notified when the stream is closed. | 150 // Optional visitor of this stream to be notified when the stream is closed. |
| 134 Visitor* visitor_; | 151 Visitor* visitor_; |
| 135 // Bytes read and written refer to payload bytes only: they do not include | 152 // Bytes read and written refer to payload bytes only: they do not include |
| 136 // framing, encryption overhead etc. | 153 // framing, encryption overhead etc. |
| 137 uint64 stream_bytes_read_; | 154 uint64 stream_bytes_read_; |
| 138 uint64 stream_bytes_written_; | 155 uint64 stream_bytes_written_; |
| 156 // True if the headers have been completely decompresssed. |
| 157 bool headers_complete_; |
| 158 // ID of the header block sent by the peer, once parsed. |
| 159 QuicHeaderId headers_id_; |
| 160 // Buffer into which we write bytes from the headers_id_ |
| 161 // until it is fully parsed. |
| 162 string headers_id_buffer_; |
| 163 // Contains a copy of the decompressed headers_ until they are consumed |
| 164 // via ProcessData or Readv. |
| 165 string decompressed_headers_; |
| 139 | 166 |
| 140 // Stream error code received from a RstStreamFrame or error code sent by the | 167 // Stream error code received from a RstStreamFrame or error code sent by the |
| 141 // visitor or sequencer in the RstStreamFrame. | 168 // visitor or sequencer in the RstStreamFrame. |
| 142 QuicRstStreamErrorCode stream_error_; | 169 QuicRstStreamErrorCode stream_error_; |
| 143 // Connection error code due to which the stream was closed. |stream_error_| | 170 // Connection error code due to which the stream was closed. |stream_error_| |
| 144 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers | 171 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers |
| 145 // should check |connection_error_|. | 172 // should check |connection_error_|. |
| 146 QuicErrorCode connection_error_; | 173 QuicErrorCode connection_error_; |
| 147 | 174 |
| 148 // True if the read side is closed and further frames should be rejected. | 175 // True if the read side is closed and further frames should be rejected. |
| 149 bool read_side_closed_; | 176 bool read_side_closed_; |
| 150 // True if the write side is closed, and further writes should fail. | 177 // True if the write side is closed, and further writes should fail. |
| 151 bool write_side_closed_; | 178 bool write_side_closed_; |
| 152 | 179 |
| 153 bool fin_buffered_; | 180 bool fin_buffered_; |
| 154 bool fin_sent_; | 181 bool fin_sent_; |
| 155 }; | 182 }; |
| 156 | 183 |
| 157 } // namespace net | 184 } // namespace net |
| 158 | 185 |
| 159 #endif // NET_QUIC_RELIABLE_QUIC_STREAM_H_ | 186 #endif // NET_QUIC_RELIABLE_QUIC_STREAM_H_ |
| OLD | NEW |