OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_PROTOCOL_PSEUDOTCP_ADAPTER_H_ | 5 #ifndef REMOTING_PROTOCOL_PSEUDOTCP_ADAPTER_H_ |
6 #define REMOTING_PROTOCOL_PSEUDOTCP_ADAPTER_H_ | 6 #define REMOTING_PROTOCOL_PSEUDOTCP_ADAPTER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
13 #include "net/log/net_log.h" | 13 #include "net/log/net_log.h" |
14 #include "net/socket/stream_socket.h" | 14 #include "remoting/protocol/p2p_stream_socket.h" |
15 #include "third_party/webrtc/p2p/base/pseudotcp.h" | 15 #include "third_party/webrtc/p2p/base/pseudotcp.h" |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 namespace protocol { | 18 namespace protocol { |
19 | 19 |
20 // PseudoTcpAdapter adapts a connectionless net::Socket to a connection- | 20 class P2PDatagramSocket; |
21 // oriented net::StreamSocket using PseudoTcp. Because net::StreamSockets | 21 |
22 // can be deleted during callbacks, while PseudoTcp cannot, the core of the | 22 // PseudoTcpAdapter adapts a P2PDatagramSocket to P2PStreamSocket using |
23 // PseudoTcpAdapter is reference counted, with a reference held by the | 23 // PseudoTcp. Because P2PStreamSockets can be deleted during callbacks, |
24 // adapter, and an additional reference held on the stack during callbacks. | 24 // while PseudoTcp cannot, the core of the PseudoTcpAdapter is reference |
25 class PseudoTcpAdapter : public net::StreamSocket, base::NonThreadSafe { | 25 // counted, with a reference held by the adapter, and an additional reference |
| 26 // held on the stack during callbacks. |
| 27 class PseudoTcpAdapter : public P2PStreamSocket, base::NonThreadSafe { |
26 public: | 28 public: |
27 explicit PseudoTcpAdapter(scoped_ptr<net::Socket> socket); | 29 explicit PseudoTcpAdapter(scoped_ptr<P2PDatagramSocket> socket); |
28 ~PseudoTcpAdapter() override; | 30 ~PseudoTcpAdapter() override; |
29 | 31 |
30 // net::Socket implementation. | 32 // P2PStreamSocket implementation. |
31 int Read(net::IOBuffer* buffer, | 33 int Read(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size, |
32 int buffer_size, | |
33 const net::CompletionCallback& callback) override; | 34 const net::CompletionCallback& callback) override; |
34 int Write(net::IOBuffer* buffer, | 35 int Write(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size, |
35 int buffer_size, | |
36 const net::CompletionCallback& callback) override; | 36 const net::CompletionCallback& callback) override; |
37 int SetReceiveBufferSize(int32 size) override; | |
38 int SetSendBufferSize(int32 size) override; | |
39 | 37 |
40 // net::StreamSocket implementation. | 38 int Connect(const net::CompletionCallback& callback); |
41 int Connect(const net::CompletionCallback& callback) override; | 39 |
42 void Disconnect() override; | 40 // Set receive and send buffer sizes. |
43 bool IsConnected() const override; | 41 int SetReceiveBufferSize(int32 size); |
44 bool IsConnectedAndIdle() const override; | 42 int SetSendBufferSize(int32 size); |
45 int GetPeerAddress(net::IPEndPoint* address) const override; | |
46 int GetLocalAddress(net::IPEndPoint* address) const override; | |
47 const net::BoundNetLog& NetLog() const override; | |
48 void SetSubresourceSpeculation() override; | |
49 void SetOmniboxSpeculation() override; | |
50 bool WasEverUsed() const override; | |
51 bool UsingTCPFastOpen() const override; | |
52 bool WasNpnNegotiated() const override; | |
53 net::NextProto GetNegotiatedProtocol() const override; | |
54 bool GetSSLInfo(net::SSLInfo* ssl_info) override; | |
55 void GetConnectionAttempts(net::ConnectionAttempts* out) const override; | |
56 void ClearConnectionAttempts() override {} | |
57 void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override { | |
58 } | |
59 | 43 |
60 // Set the delay for sending ACK. | 44 // Set the delay for sending ACK. |
61 void SetAckDelay(int delay_ms); | 45 void SetAckDelay(int delay_ms); |
62 | 46 |
63 // Set whether Nagle's algorithm is enabled. | 47 // Set whether Nagle's algorithm is enabled. |
64 void SetNoDelay(bool no_delay); | 48 void SetNoDelay(bool no_delay); |
65 | 49 |
66 // When write_waits_for_send flag is set to true the Write() method | 50 // When write_waits_for_send flag is set to true the Write() method |
67 // will wait until the data is sent to the remote end before the | 51 // will wait until the data is sent to the remote end before the |
68 // write completes (it still doesn't wait until the data is received | 52 // write completes (it still doesn't wait until the data is received |
(...skipping 19 matching lines...) Expand all Loading... |
88 | 72 |
89 net::BoundNetLog net_log_; | 73 net::BoundNetLog net_log_; |
90 | 74 |
91 DISALLOW_COPY_AND_ASSIGN(PseudoTcpAdapter); | 75 DISALLOW_COPY_AND_ASSIGN(PseudoTcpAdapter); |
92 }; | 76 }; |
93 | 77 |
94 } // namespace protocol | 78 } // namespace protocol |
95 } // namespace remoting | 79 } // namespace remoting |
96 | 80 |
97 #endif // REMOTING_PROTOCOL_PSEUDOTCP_ADAPTER_H_ | 81 #endif // REMOTING_PROTOCOL_PSEUDOTCP_ADAPTER_H_ |
OLD | NEW |