summaryrefslogtreecommitdiff
path: root/chromium/net/quic/quartc/quartc_stream_interface.h
blob: 831abb5432ab83b4deb2238ec8a25115cc542186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_QUIC_QUARTC_QUARTC_STREAM_INTERFACE_H_
#define NET_QUIC_QUARTC_QUARTC_STREAM_INTERFACE_H_

#include <stddef.h>
#include <stdint.h>

#include "net/quic/platform/api/quic_export.h"

namespace net {

// Sends and receives data with a particular QUIC stream ID, reliably and
// in-order. To send/receive data out of order, use separate streams. To
// send/receive unreliably, close a stream after reliability is no longer
// needed.
class QUIC_EXPORT_PRIVATE QuartcStreamInterface {
 public:
  virtual ~QuartcStreamInterface() {}

  // The QUIC stream ID.
  virtual uint32_t stream_id() = 0;

  // The amount of data buffered by the QuicConnection.
  virtual uint64_t buffered_amount() = 0;

  // Return true if the FIN has been sent. Used by the outgoing streams to
  // determine if all the data has been sent
  virtual bool fin_sent() = 0;

  struct WriteParameters {
    WriteParameters() : fin(false) {}
    // |fin| is set to be true when there is no more data need to be send
    // through a particular stream. The receiving side will used it to determine
    // if the sender finish sending data.
    bool fin;
  };

  // Sends data reliably and in-order, buffering if necessary until Close() is
  // called.
  virtual void Write(const char* data,
                     size_t size,
                     const WriteParameters& param) = 0;

  // Once Close is called, no more data can be sent, all buffered data will be
  // dropped and no data will be retransmitted.
  virtual void Close() = 0;

  // Implemented by the user of the QuartcStreamInterface to receive incoming
  // data and be notified of state changes.
  class Delegate {
   public:
    virtual ~Delegate() {}

    // Called when the stream receives the date.
    virtual void OnReceived(QuartcStreamInterface* stream,
                            const char* data,
                            size_t size) = 0;

    // Called when the stream is closed, either locally or by the remote
    // endpoint.
    // TODO(zhihuang) Creates a map from the integer error_code to WebRTC native
    // error code.
    virtual void OnClose(QuartcStreamInterface* stream, int error_code) = 0;

    // Called when buffered_amount() decreases.
    virtual void OnBufferedAmountDecrease(QuartcStreamInterface* stream) = 0;
  };

  // The |delegate| is not owned by QuartcStream.
  virtual void SetDelegate(Delegate* delegate) = 0;
};

}  // namespace net

#endif  // NET_QUIC_QUARTC_QUARTC_STREAM_INTERFACE_H_