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