OLD | NEW |
| (Empty) |
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 #ifndef JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_ | |
6 #define JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/threading/non_thread_safe.h" | |
13 #include "net/log/net_log.h" | |
14 #include "net/socket/stream_socket.h" | |
15 #include "third_party/webrtc/p2p/base/pseudotcp.h" | |
16 | |
17 namespace jingle_glue { | |
18 | |
19 // PseudoTcpAdapter adapts a connectionless net::Socket to a connection- | |
20 // oriented net::StreamSocket using PseudoTcp. Because net::StreamSockets | |
21 // can be deleted during callbacks, while PseudoTcp cannot, the core of the | |
22 // PseudoTcpAdapter is reference counted, with a reference held by the | |
23 // adapter, and an additional reference held on the stack during callbacks. | |
24 class PseudoTcpAdapter : public net::StreamSocket, base::NonThreadSafe { | |
25 public: | |
26 // Creates an adapter for the supplied Socket. |socket| should already | |
27 // be ready for use, and ownership of it will be assumed by the adapter. | |
28 explicit PseudoTcpAdapter(net::Socket* socket); | |
29 ~PseudoTcpAdapter() override; | |
30 | |
31 // net::Socket implementation. | |
32 int Read(net::IOBuffer* buffer, | |
33 int buffer_size, | |
34 const net::CompletionCallback& callback) override; | |
35 int Write(net::IOBuffer* buffer, | |
36 int buffer_size, | |
37 const net::CompletionCallback& callback) override; | |
38 int SetReceiveBufferSize(int32 size) override; | |
39 int SetSendBufferSize(int32 size) override; | |
40 | |
41 // net::StreamSocket implementation. | |
42 int Connect(const net::CompletionCallback& callback) override; | |
43 void Disconnect() override; | |
44 bool IsConnected() const override; | |
45 bool IsConnectedAndIdle() const override; | |
46 int GetPeerAddress(net::IPEndPoint* address) const override; | |
47 int GetLocalAddress(net::IPEndPoint* address) const override; | |
48 const net::BoundNetLog& NetLog() const override; | |
49 void SetSubresourceSpeculation() override; | |
50 void SetOmniboxSpeculation() override; | |
51 bool WasEverUsed() const override; | |
52 bool UsingTCPFastOpen() const override; | |
53 bool WasNpnNegotiated() const override; | |
54 net::NextProto GetNegotiatedProtocol() const override; | |
55 bool GetSSLInfo(net::SSLInfo* ssl_info) override; | |
56 void GetConnectionAttempts(net::ConnectionAttempts* out) const override; | |
57 void ClearConnectionAttempts() override {} | |
58 void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override { | |
59 } | |
60 | |
61 // Set the delay for sending ACK. | |
62 void SetAckDelay(int delay_ms); | |
63 | |
64 // Set whether Nagle's algorithm is enabled. | |
65 void SetNoDelay(bool no_delay); | |
66 | |
67 // When write_waits_for_send flag is set to true the Write() method | |
68 // will wait until the data is sent to the remote end before the | |
69 // write completes (it still doesn't wait until the data is received | |
70 // and acknowledged by the remote end). Otherwise write completes | |
71 // after the data has been copied to the send buffer. | |
72 // | |
73 // This flag is useful in cases when the sender needs to get | |
74 // feedback from the connection when it is congested. E.g. remoting | |
75 // host uses this feature to adjust screen capturing rate according | |
76 // to the available bandwidth. In the same time it may negatively | |
77 // impact performance in some cases. E.g. when the sender writes one | |
78 // byte at a time then each byte will always be sent in a separate | |
79 // packet. | |
80 // | |
81 // TODO(sergeyu): Remove this flag once remoting has a better | |
82 // flow-control solution. | |
83 void SetWriteWaitsForSend(bool write_waits_for_send); | |
84 | |
85 private: | |
86 class Core; | |
87 | |
88 scoped_refptr<Core> core_; | |
89 | |
90 net::BoundNetLog net_log_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(PseudoTcpAdapter); | |
93 }; | |
94 | |
95 } // namespace jingle_glue | |
96 | |
97 #endif // JINGLE_GLUE_PSEUDOTCP_ADAPTER_H_ | |
OLD | NEW |