rAc - revert invalid suggestions to edit mode
[chromium-blink-merge.git] / net / quic / reliable_quic_stream.h
blob42848f843fb36cb504c6c948576fc30c3ae178d0
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
3 // found in the LICENSE file.
4 //
5 // The base class for client/server reliable streams.
7 #ifndef NET_QUIC_RELIABLE_QUIC_STREAM_H_
8 #define NET_QUIC_RELIABLE_QUIC_STREAM_H_
10 #include <sys/types.h>
12 #include <list>
14 #include "base/basictypes.h"
15 #include "base/strings/string_piece.h"
16 #include "net/base/iovec.h"
17 #include "net/base/net_export.h"
18 #include "net/quic/quic_ack_notifier.h"
19 #include "net/quic/quic_protocol.h"
20 #include "net/quic/quic_stream_sequencer.h"
22 namespace net {
24 namespace test {
25 class ReliableQuicStreamPeer;
26 } // namespace test
28 class IPEndPoint;
29 class QuicSession;
30 class SSLInfo;
32 class NET_EXPORT_PRIVATE ReliableQuicStream {
33 public:
34 ReliableQuicStream(QuicStreamId id,
35 QuicSession* session);
37 virtual ~ReliableQuicStream();
39 bool WillAcceptStreamFrame(const QuicStreamFrame& frame) const;
41 // Called when a (potentially duplicate) stream frame has been received
42 // for this stream. Returns false if this frame can not be accepted
43 // because there is too much data already buffered.
44 virtual bool OnStreamFrame(const QuicStreamFrame& frame);
46 // Called when the connection becomes writeable to allow the stream
47 // to write any pending data.
48 virtual void OnCanWrite();
50 // Called by the session just before the stream is deleted.
51 virtual void OnClose();
53 // Called when we get a stream reset from the peer.
54 virtual void OnStreamReset(const QuicRstStreamFrame& frame);
56 // Called when we get or send a connection close, and should immediately
57 // close the stream. This is not passed through the sequencer,
58 // but is handled immediately.
59 virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer);
61 // Called when the final data has been read.
62 virtual void OnFinRead();
64 virtual uint32 ProcessRawData(const char* data, uint32 data_len) = 0;
66 // Called to reset the stream from this end.
67 virtual void Reset(QuicRstStreamErrorCode error);
69 // Called to close the entire connection from this end.
70 virtual void CloseConnection(QuicErrorCode error);
71 virtual void CloseConnectionWithDetails(QuicErrorCode error,
72 const string& details);
74 // Returns the effective priority for the stream. This value may change
75 // during the life of the stream.
76 virtual QuicPriority EffectivePriority() const = 0;
78 QuicStreamId id() const { return id_; }
80 QuicRstStreamErrorCode stream_error() const { return stream_error_; }
81 QuicErrorCode connection_error() const { return connection_error_; }
83 bool read_side_closed() const { return read_side_closed_; }
84 bool write_side_closed() const { return write_side_closed_; }
86 uint64 stream_bytes_read() const { return stream_bytes_read_; }
87 uint64 stream_bytes_written() const { return stream_bytes_written_; }
89 QuicVersion version() const;
91 void set_fin_sent(bool fin_sent) { fin_sent_ = fin_sent; }
92 void set_rst_sent(bool rst_sent) { rst_sent_ = rst_sent; }
94 protected:
95 // Sends as much of 'data' to the connection as the connection will consume,
96 // and then buffers any remaining data in queued_data_.
97 void WriteOrBufferData(base::StringPiece data, bool fin);
99 // Sends as many bytes in the first |count| buffers of |iov| to the connection
100 // as the connection will consume.
101 // If |ack_notifier_delegate| is provided, then it will be notified once all
102 // the ACKs for this write have been received.
103 // Returns the number of bytes consumed by the connection.
104 QuicConsumedData WritevData(
105 const struct iovec* iov,
106 int iov_count,
107 bool fin,
108 QuicAckNotifier::DelegateInterface* ack_notifier_delegate);
110 // Close the read side of the socket. Further frames will not be accepted.
111 virtual void CloseReadSide();
113 // Close the write side of the socket. Further writes will fail.
114 void CloseWriteSide();
116 bool HasBufferedData();
118 bool fin_buffered() { return fin_buffered_; }
120 const QuicSession* session() const { return session_; }
121 QuicSession* session() { return session_; }
123 const QuicStreamSequencer* sequencer() const { return &sequencer_; }
124 QuicStreamSequencer* sequencer() { return &sequencer_; }
126 private:
127 friend class test::ReliableQuicStreamPeer;
128 friend class QuicStreamUtils;
130 std::list<string> queued_data_;
132 QuicStreamSequencer sequencer_;
133 QuicStreamId id_;
134 QuicSession* session_;
135 // Bytes read and written refer to payload bytes only: they do not include
136 // framing, encryption overhead etc.
137 uint64 stream_bytes_read_;
138 uint64 stream_bytes_written_;
140 // Stream error code received from a RstStreamFrame or error code sent by the
141 // visitor or sequencer in the RstStreamFrame.
142 QuicRstStreamErrorCode stream_error_;
143 // 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
145 // should check |connection_error_|.
146 QuicErrorCode connection_error_;
148 // True if the read side is closed and further frames should be rejected.
149 bool read_side_closed_;
150 // True if the write side is closed, and further writes should fail.
151 bool write_side_closed_;
153 bool fin_buffered_;
154 bool fin_sent_;
156 // In combination with fin_sent_, used to ensure that a FIN and/or a RST is
157 // always sent before stream termination.
158 bool rst_sent_;
160 // True if the session this stream is running under is a server session.
161 bool is_server_;
163 DISALLOW_COPY_AND_ASSIGN(ReliableQuicStream);
166 } // namespace net
168 #endif // NET_QUIC_RELIABLE_QUIC_STREAM_H_