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.
5 // NOTE: This code is not shared between Google and Chrome.
7 #ifndef NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_
8 #define NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/upload_data_stream.h"
12 #include "net/http/http_request_info.h"
13 #include "net/http/http_response_info.h"
14 #include "net/http/http_stream.h"
15 #include "net/quic/reliable_quic_stream.h"
19 class QuicClientSession
;
21 // A client-initiated ReliableQuicStream. Instances of this class
22 // are owned by the QuicClientSession which created them.
23 class NET_EXPORT_PRIVATE QuicReliableClientStream
: public ReliableQuicStream
{
25 // Delegate handles protocol specific behavior of a quic stream.
26 class NET_EXPORT_PRIVATE Delegate
{
30 // Called when stream is ready to send data.
31 // Returns network error code. OK when it successfully sent data.
32 // ERR_IO_PENDING when performing operation asynchronously.
33 virtual int OnSendData() = 0;
35 // Called when data has been sent. |status| indicates network error
36 // or number of bytes that has been sent. On return, |eof| is set to true
37 // if no more data is available to send.
38 // Returns network error code. OK when it successfully sent data.
39 virtual int OnSendDataComplete(int status
, bool* eof
) = 0;
41 // Called when data is received.
42 // Returns network error code. OK when it successfully receives data.
43 virtual int OnDataReceived(const char* data
, int length
) = 0;
45 // Called when the stream is closed by the peer.
46 virtual void OnClose(QuicErrorCode error
) = 0;
48 // Called when the stream is closed because of an error.
49 virtual void OnError(int error
) = 0;
51 // Returns true if sending of headers has completed.
52 virtual bool HasSendHeadersComplete() = 0;
55 virtual ~Delegate() {}
58 DISALLOW_COPY_AND_ASSIGN(Delegate
);
61 QuicReliableClientStream(QuicStreamId id
,
63 const BoundNetLog
& net_log
);
65 virtual ~QuicReliableClientStream();
68 virtual uint32
ProcessData(const char* data
, uint32 data_len
) OVERRIDE
;
69 virtual void TerminateFromPeer(bool half_close
) OVERRIDE
;
70 virtual void OnCanWrite() OVERRIDE
;
71 virtual QuicPriority
EffectivePriority() const OVERRIDE
;
73 // While the server's set_priority shouldn't be called externally, the creator
74 // of client-side streams should be able to set the priority.
75 using ReliableQuicStream::set_priority
;
77 int WriteStreamData(base::StringPiece data
,
79 const CompletionCallback
& callback
);
80 // Set new |delegate|. |delegate| must not be NULL.
81 // If this stream has already received data, OnDataReceived() will be
82 // called on the delegate.
83 void SetDelegate(Delegate
* delegate
);
84 Delegate
* GetDelegate() { return delegate_
; }
85 void OnError(int error
);
87 const BoundNetLog
& net_log() const { return net_log_
; }
93 CompletionCallback callback_
;
95 DISALLOW_COPY_AND_ASSIGN(QuicReliableClientStream
);
100 #endif // NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_