1 // Copyright 2015 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 #ifndef REMOTING_PROTOCOL_QUIC_CHANNEL_H_
6 #define REMOTING_PROTOCOL_QUIC_CHANNEL_H_
8 #include "net/quic/p2p/quic_p2p_stream.h"
9 #include "remoting/base/compound_buffer.h"
10 #include "remoting/protocol/p2p_stream_socket.h"
13 class DrainableIOBuffer
;
19 // QuicChannel implements P2PStreamSocket interface for a QuicP2PStream.
20 class QuicChannel
: public net::QuicP2PStream::Delegate
,
21 public P2PStreamSocket
{
23 QuicChannel(net::QuicP2PStream
* stream
,
24 const base::Closure
& on_destroyed_callback
);
25 ~QuicChannel() override
;
27 const std::string
& name() { return name_
; }
29 // P2PStreamSocket interface.
30 int Read(const scoped_refptr
<net::IOBuffer
>& buffer
,
32 const net::CompletionCallback
& callback
) override
;
33 int Write(const scoped_refptr
<net::IOBuffer
>& buffer
,
35 const net::CompletionCallback
& callback
) override
;
38 void SetName(const std::string
& name
);
40 // Owned by QuicSession.
41 net::QuicP2PStream
* stream_
;
44 // net::QuicP2PStream::Delegate interface.
45 void OnDataReceived(const char* data
, int length
) override
;
46 void OnClose(net::QuicErrorCode error
) override
;
48 base::Closure on_destroyed_callback_
;
52 CompoundBuffer data_received_
;
54 net::CompletionCallback read_callback_
;
55 scoped_refptr
<net::IOBuffer
> read_buffer_
;
56 int read_buffer_size_
= 0;
60 DISALLOW_COPY_AND_ASSIGN(QuicChannel
);
63 // Client side of a channel. Sends the |name| specified in the constructor to
65 class QuicClientChannel
: public QuicChannel
{
67 QuicClientChannel(net::QuicP2PStream
* stream
,
68 const base::Closure
& on_destroyed_callback
,
69 const std::string
& name
);
70 ~QuicClientChannel() override
;
73 DISALLOW_COPY_AND_ASSIGN(QuicClientChannel
);
76 // Host side of a channel. Receives name from the peer after ReceiveName is
77 // called. Read() can be called only after the name is received.
78 class QuicServerChannel
: public QuicChannel
{
80 QuicServerChannel(net::QuicP2PStream
* stream
,
81 const base::Closure
& on_destroyed_callback
);
82 ~QuicServerChannel() override
;
84 // Must be called after the constructor to receive channel name.
85 // |name_received_callback| must use QuicChannel::name() to get the name.
86 // Empty name() indicates failure to receive it.
87 void ReceiveName(const base::Closure
& name_received_callback
);
90 void OnNameSizeReadResult(int result
);
91 void ReadNameLoop(int result
);
92 void OnNameReadResult(int result
);
94 base::Closure name_received_callback_
;
95 uint8_t name_length_
= 0;
96 scoped_refptr
<net::DrainableIOBuffer
> name_read_buffer_
;
98 DISALLOW_COPY_AND_ASSIGN(QuicServerChannel
);
101 } // namespace protocol
102 } // namespace remoting
104 #endif // REMOTING_PROTOCOL_QUIC_CHANNEL_H_