OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef REMOTING_PROTOCOL_QUIC_CHANNEL_H_ | |
6 #define REMOTING_PROTOCOL_QUIC_CHANNEL_H_ | |
7 | |
8 #include "net/quic/p2p/quic_p2p_stream.h" | |
9 #include "remoting/base/compound_buffer.h" | |
10 #include "remoting/protocol/p2p_stream_socket.h" | |
11 | |
12 namespace net { | |
13 class DrainableIOBuffer; | |
14 } // namespace net | |
15 | |
16 namespace remoting { | |
17 namespace protocol { | |
18 | |
19 // QuicChannel implements P2PStreamSocket interface for a QuicP2PStream. | |
20 class QuicChannel : public net::QuicP2PStream::Delegate, | |
21 public P2PStreamSocket { | |
22 public: | |
23 QuicChannel(net::QuicP2PStream* stream, | |
24 const base::Closure& on_destroyed_callback); | |
25 ~QuicChannel() override; | |
26 | |
27 const std::string& name() { return name_; } | |
28 | |
29 // P2PStreamSocket interface. | |
30 int Read(const scoped_refptr<net::IOBuffer>& buffer, | |
31 int buffer_len, | |
32 const net::CompletionCallback& callback) override; | |
33 int Write(const scoped_refptr<net::IOBuffer>& buffer, | |
34 int buffer_len, | |
35 const net::CompletionCallback& callback) override; | |
36 | |
37 protected: | |
38 void SetName(const std::string& name); | |
39 | |
40 // Owned by QuicSession. | |
41 net::QuicP2PStream* stream_; | |
42 | |
43 private: | |
44 // net::QuicP2PStream::Delegate interface. | |
45 void OnDataReceived(const char* data, int length) override; | |
46 void OnClose(net::QuicErrorCode error) override; | |
47 | |
48 base::Closure on_destroyed_callback_; | |
49 | |
50 std::string name_; | |
51 | |
52 CompoundBuffer data_received_; | |
53 | |
54 net::CompletionCallback read_callback_; | |
55 scoped_refptr<net::IOBuffer> read_buffer_; | |
56 int read_buffer_size_ = 0; | |
57 | |
58 int error_ = 0; | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(QuicChannel); | |
61 }; | |
62 | |
63 // Client side of a channel. Sends the |name| specified in the constructor to | |
64 // the peer. | |
65 class QuicClientChannel : public QuicChannel { | |
66 public: | |
67 QuicClientChannel(net::QuicP2PStream* stream, | |
68 const base::Closure& on_destroyed_callback, | |
69 const std::string& name); | |
70 ~QuicClientChannel() override; | |
71 | |
72 private: | |
73 DISALLOW_COPY_AND_ASSIGN(QuicClientChannel); | |
74 }; | |
75 | |
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 { | |
79 public: | |
80 QuicServerChannel(net::QuicP2PStream* stream, | |
81 const base::Closure& on_destroyed_callback); | |
82 ~QuicServerChannel() override; | |
83 | |
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); | |
88 | |
89 private: | |
90 void OnNameSizeReadResult(int result); | |
91 void ReadNameLoop(int result); | |
92 void OnNameReadResult(int result); | |
93 | |
94 base::Closure name_received_callback_; | |
95 uint8_t name_length_ = 0; | |
96 scoped_refptr<net::DrainableIOBuffer> name_read_buffer_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(QuicServerChannel); | |
99 }; | |
100 | |
101 } // namespace protocol | |
102 } // namespace remoting | |
103 | |
104 #endif // REMOTING_PROTOCOL_QUIC_CHANNEL_H_ | |
OLD | NEW |