Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: remoting/protocol/pseudotcp_channel_factory.cc

Issue 551173004: Move PseudoTCP and channel auth out of LibjingleTransportFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clean_dgrams
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/protocol/pseudotcp_channel_factory.h"
6
7 #include "base/bind.h"
8 #include "jingle/glue/pseudotcp_adapter.h"
9 #include "net/base/net_errors.h"
10 #include "net/socket/stream_socket.h"
11 #include "remoting/base/constants.h"
12 #include "remoting/protocol/datagram_channel_factory.h"
13
14 namespace remoting {
15 namespace protocol {
16
17 namespace {
18
19 // Value is chosen to balance the extra latency against the reduced
20 // load due to ACK traffic.
21 const int kTcpAckDelayMilliseconds = 10;
22
23 // Values for the TCP send and receive buffer size. This should be tuned to
24 // accommodate high latency network but not backlog the decoding pipeline.
25 const int kTcpReceiveBufferSize = 256 * 1024;
26 const int kTcpSendBufferSize = kTcpReceiveBufferSize + 30 * 1024;
27
28 } // namespace
29
30 PseudoTcpChannelFactory::PseudoTcpChannelFactory(
31 DatagramChannelFactory* datagram_channel_factory)
32 : datagram_channel_factory_(datagram_channel_factory) {
33 }
34
35 PseudoTcpChannelFactory::~PseudoTcpChannelFactory() {
36 DCHECK(pending_sockets_.empty());
37 }
38
39 void PseudoTcpChannelFactory::CreateChannel(
40 const std::string& name,
41 const ChannelCreatedCallback& callback) {
42 datagram_channel_factory_->CreateChannel(
43 name,
44 base::Bind(&PseudoTcpChannelFactory::OnDatagramChannelCreated,
45 base::Unretained(this), name, callback));
46 }
47
48 void PseudoTcpChannelFactory::CancelChannelCreation(const std::string& name) {
49 PendingSocketsMap::iterator it = pending_sockets_.find(name);
50 if (it == pending_sockets_.end()) {
51 datagram_channel_factory_->CancelChannelCreation(name);
52 } else {
53 delete it->second;
54 pending_sockets_.erase(it);
55 }
56 }
57
58 void PseudoTcpChannelFactory::OnDatagramChannelCreated(
59 const std::string& name,
60 const ChannelCreatedCallback& callback,
61 scoped_ptr<net::Socket> datagram_socket) {
62 jingle_glue::PseudoTcpAdapter* adapter =
63 new jingle_glue::PseudoTcpAdapter(datagram_socket.release());
64 pending_sockets_[name] = adapter;
65
66 adapter->SetSendBufferSize(kTcpSendBufferSize);
67 adapter->SetReceiveBufferSize(kTcpReceiveBufferSize);
68 adapter->SetNoDelay(true);
69 adapter->SetAckDelay(kTcpAckDelayMilliseconds);
70
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.
73 if (name == kVideoChannelName)
74 adapter->SetWriteWaitsForSend(true);
75
76 int result = adapter->Connect(
77 base::Bind(&PseudoTcpChannelFactory::OnPseudoTcpConnected,
78 base::Unretained(this), name, callback));
79 if (result != net::ERR_IO_PENDING)
80 OnPseudoTcpConnected(name, callback, result);
81 }
82
83 void PseudoTcpChannelFactory::OnPseudoTcpConnected(
84 const std::string& name,
85 const ChannelCreatedCallback& callback,
86 int result) {
87 PendingSocketsMap::iterator it = pending_sockets_.find(name);
88 DCHECK(it != pending_sockets_.end());
89 scoped_ptr<net::StreamSocket> socket(it->second);
90 pending_sockets_.erase(it);
91
92 if (result != net::OK)
93 socket.reset();
94
95 callback.Run(socket.Pass());
96 }
97
98 } // namespace protocol
99 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698