Home | History | Annotate | Download | only in quic
      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 // NOTE: This code is not shared between Google and Chrome.
      6 
      7 #ifndef NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_
      8 #define NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_
      9 
     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"
     16 
     17 namespace net {
     18 
     19 class QuicClientSession;
     20 
     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 {
     24  public:
     25   // Delegate handles protocol specific behavior of a quic stream.
     26   class NET_EXPORT_PRIVATE Delegate {
     27    public:
     28     Delegate() {}
     29 
     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;
     34 
     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;
     40 
     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;
     44 
     45     // Called when the stream is closed by the peer.
     46     virtual void OnClose(QuicErrorCode error) = 0;
     47 
     48     // Called when the stream is closed because of an error.
     49     virtual void OnError(int error) = 0;
     50 
     51    protected:
     52     virtual ~Delegate() {}
     53 
     54    private:
     55     DISALLOW_COPY_AND_ASSIGN(Delegate);
     56   };
     57 
     58   QuicReliableClientStream(QuicStreamId id,
     59                            QuicSession* session,
     60                            const BoundNetLog& net_log);
     61 
     62   virtual ~QuicReliableClientStream();
     63 
     64   // ReliableQuicStream
     65   virtual uint32 ProcessData(const char* data, uint32 data_len) OVERRIDE;
     66   virtual void TerminateFromPeer(bool half_close) OVERRIDE;
     67   using ReliableQuicStream::WriteData;
     68 
     69   // Set new |delegate|. |delegate| must not be NULL.
     70   // If this stream has already received data, OnDataReceived() will be
     71   // called on the delegate.
     72   void SetDelegate(Delegate* delegate);
     73   Delegate* GetDelegate() { return delegate_; }
     74   void OnError(int error);
     75 
     76   const BoundNetLog& net_log() const { return net_log_; }
     77 
     78  private:
     79   BoundNetLog net_log_;
     80   Delegate* delegate_;
     81 
     82   DISALLOW_COPY_AND_ASSIGN(QuicReliableClientStream);
     83 };
     84 
     85 }  // namespace net
     86 
     87 #endif  // NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_
     88