Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / remoting / protocol / pseudotcp_adapter.h
bloba297dd7cfe81adde30679026b7f4895d6d042800
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_PSEUDOTCP_ADAPTER_H_
6 #define REMOTING_PROTOCOL_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 "net/log/net_log.h"
14 #include "remoting/protocol/p2p_stream_socket.h"
15 #include "third_party/webrtc/p2p/base/pseudotcp.h"
17 namespace remoting {
18 namespace protocol {
20 class P2PDatagramSocket;
22 // PseudoTcpAdapter adapts a P2PDatagramSocket to P2PStreamSocket using
23 // PseudoTcp. Because P2PStreamSockets can be deleted during callbacks,
24 // while PseudoTcp cannot, the core of the PseudoTcpAdapter is reference
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 {
28 public:
29 explicit PseudoTcpAdapter(scoped_ptr<P2PDatagramSocket> socket);
30 ~PseudoTcpAdapter() override;
32 // P2PStreamSocket implementation.
33 int Read(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size,
34 const net::CompletionCallback& callback) override;
35 int Write(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size,
36 const net::CompletionCallback& callback) override;
38 int Connect(const net::CompletionCallback& callback);
40 // Set receive and send buffer sizes.
41 int SetReceiveBufferSize(int32 size);
42 int SetSendBufferSize(int32 size);
44 // Set the delay for sending ACK.
45 void SetAckDelay(int delay_ms);
47 // Set whether Nagle's algorithm is enabled.
48 void SetNoDelay(bool no_delay);
50 // When write_waits_for_send flag is set to true the Write() method
51 // will wait until the data is sent to the remote end before the
52 // write completes (it still doesn't wait until the data is received
53 // and acknowledged by the remote end). Otherwise write completes
54 // after the data has been copied to the send buffer.
56 // This flag is useful in cases when the sender needs to get
57 // feedback from the connection when it is congested. E.g. remoting
58 // host uses this feature to adjust screen capturing rate according
59 // to the available bandwidth. In the same time it may negatively
60 // impact performance in some cases. E.g. when the sender writes one
61 // byte at a time then each byte will always be sent in a separate
62 // packet.
64 // TODO(sergeyu): Remove this flag once remoting has a better
65 // flow-control solution.
66 void SetWriteWaitsForSend(bool write_waits_for_send);
68 private:
69 class Core;
71 scoped_refptr<Core> core_;
73 net::BoundNetLog net_log_;
75 DISALLOW_COPY_AND_ASSIGN(PseudoTcpAdapter);
78 } // namespace protocol
79 } // namespace remoting
81 #endif // REMOTING_PROTOCOL_PSEUDOTCP_ADAPTER_H_