OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "remoting/protocol/pseudotcp_channel_factory.h" | 5 #include "remoting/protocol/pseudotcp_channel_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/socket/stream_socket.h" | |
10 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
11 #include "remoting/protocol/datagram_channel_factory.h" | 10 #include "remoting/protocol/datagram_channel_factory.h" |
| 11 #include "remoting/protocol/p2p_datagram_socket.h" |
12 #include "remoting/protocol/pseudotcp_adapter.h" | 12 #include "remoting/protocol/pseudotcp_adapter.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 namespace protocol { | 15 namespace protocol { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Value is chosen to balance the extra latency against the reduced | 19 // Value is chosen to balance the extra latency against the reduced |
20 // load due to ACK traffic. | 20 // load due to ACK traffic. |
21 const int kTcpAckDelayMilliseconds = 10; | 21 const int kTcpAckDelayMilliseconds = 10; |
(...skipping 30 matching lines...) Expand all Loading... |
52 datagram_channel_factory_->CancelChannelCreation(name); | 52 datagram_channel_factory_->CancelChannelCreation(name); |
53 } else { | 53 } else { |
54 delete it->second; | 54 delete it->second; |
55 pending_sockets_.erase(it); | 55 pending_sockets_.erase(it); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 void PseudoTcpChannelFactory::OnDatagramChannelCreated( | 59 void PseudoTcpChannelFactory::OnDatagramChannelCreated( |
60 const std::string& name, | 60 const std::string& name, |
61 const ChannelCreatedCallback& callback, | 61 const ChannelCreatedCallback& callback, |
62 scoped_ptr<net::Socket> datagram_socket) { | 62 scoped_ptr<P2PDatagramSocket> datagram_socket) { |
63 PseudoTcpAdapter* adapter = new PseudoTcpAdapter(datagram_socket.Pass()); | 63 PseudoTcpAdapter* adapter = new PseudoTcpAdapter(datagram_socket.Pass()); |
64 pending_sockets_[name] = adapter; | 64 pending_sockets_[name] = adapter; |
65 | 65 |
66 adapter->SetSendBufferSize(kTcpSendBufferSize); | 66 adapter->SetSendBufferSize(kTcpSendBufferSize); |
67 adapter->SetReceiveBufferSize(kTcpReceiveBufferSize); | 67 adapter->SetReceiveBufferSize(kTcpReceiveBufferSize); |
68 adapter->SetNoDelay(true); | 68 adapter->SetNoDelay(true); |
69 adapter->SetAckDelay(kTcpAckDelayMilliseconds); | 69 adapter->SetAckDelay(kTcpAckDelayMilliseconds); |
70 | 70 |
71 // TODO(sergeyu): This is a hack to improve latency of the video channel. | 71 // TODO(sergeyu): This is a hack to improve latency of the video channel. |
72 // Consider removing it once we have better flow control implemented. | 72 // Consider removing it once we have better flow control implemented. |
73 if (name == kVideoChannelName) | 73 if (name == kVideoChannelName) |
74 adapter->SetWriteWaitsForSend(true); | 74 adapter->SetWriteWaitsForSend(true); |
75 | 75 |
76 int result = adapter->Connect( | 76 int result = adapter->Connect( |
77 base::Bind(&PseudoTcpChannelFactory::OnPseudoTcpConnected, | 77 base::Bind(&PseudoTcpChannelFactory::OnPseudoTcpConnected, |
78 base::Unretained(this), name, callback)); | 78 base::Unretained(this), name, callback)); |
79 if (result != net::ERR_IO_PENDING) | 79 if (result != net::ERR_IO_PENDING) |
80 OnPseudoTcpConnected(name, callback, result); | 80 OnPseudoTcpConnected(name, callback, result); |
81 } | 81 } |
82 | 82 |
83 void PseudoTcpChannelFactory::OnPseudoTcpConnected( | 83 void PseudoTcpChannelFactory::OnPseudoTcpConnected( |
84 const std::string& name, | 84 const std::string& name, |
85 const ChannelCreatedCallback& callback, | 85 const ChannelCreatedCallback& callback, |
86 int result) { | 86 int result) { |
87 PendingSocketsMap::iterator it = pending_sockets_.find(name); | 87 PendingSocketsMap::iterator it = pending_sockets_.find(name); |
88 DCHECK(it != pending_sockets_.end()); | 88 DCHECK(it != pending_sockets_.end()); |
89 scoped_ptr<net::StreamSocket> socket(it->second); | 89 scoped_ptr<P2PStreamSocket> socket(it->second); |
90 pending_sockets_.erase(it); | 90 pending_sockets_.erase(it); |
91 | 91 |
92 if (result != net::OK) | 92 if (result != net::OK) |
93 socket.reset(); | 93 socket.reset(); |
94 | 94 |
95 callback.Run(socket.Pass()); | 95 callback.Run(socket.Pass()); |
96 } | 96 } |
97 | 97 |
98 } // namespace protocol | 98 } // namespace protocol |
99 } // namespace remoting | 99 } // namespace remoting |
OLD | NEW |