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