OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "blimp/net/tcp_engine_transport.h" | 5 #include "blimp/net/tcp_engine_transport.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "blimp/net/stream_socket_connection.h" | 13 #include "blimp/net/stream_socket_connection.h" |
14 #include "net/socket/stream_socket.h" | 14 #include "net/socket/stream_socket.h" |
15 #include "net/socket/tcp_server_socket.h" | 15 #include "net/socket/tcp_server_socket.h" |
16 | 16 |
17 namespace blimp { | 17 namespace blimp { |
18 | 18 |
19 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, | 19 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, |
20 BlimpConnectionStatistics* statistics, | |
20 net::NetLog* net_log) | 21 net::NetLog* net_log) |
21 : address_(address), net_log_(net_log) {} | 22 : address_(address), |
23 blimp_connection_statistics_(statistics), | |
24 net_log_(net_log) {} | |
Kevin M
2016/05/24 22:56:40
DCHECK(statistics)
| |
22 | 25 |
23 TCPEngineTransport::~TCPEngineTransport() {} | 26 TCPEngineTransport::~TCPEngineTransport() {} |
24 | 27 |
25 void TCPEngineTransport::Connect(const net::CompletionCallback& callback) { | 28 void TCPEngineTransport::Connect(const net::CompletionCallback& callback) { |
26 DCHECK(!accepted_socket_); | 29 DCHECK(!accepted_socket_); |
27 DCHECK(!callback.is_null()); | 30 DCHECK(!callback.is_null()); |
28 | 31 |
29 if (!server_socket_) { | 32 if (!server_socket_) { |
30 server_socket_.reset( | 33 server_socket_.reset( |
31 new net::TCPServerSocket(net_log_, net::NetLog::Source())); | 34 new net::TCPServerSocket(net_log_, net::NetLog::Source())); |
(...skipping 20 matching lines...) Expand all Loading... | |
52 server_socket_.reset(); | 55 server_socket_.reset(); |
53 } | 56 } |
54 | 57 |
55 base::MessageLoop::current()->PostTask(FROM_HERE, | 58 base::MessageLoop::current()->PostTask(FROM_HERE, |
56 base::Bind(callback, result)); | 59 base::Bind(callback, result)); |
57 } | 60 } |
58 | 61 |
59 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { | 62 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { |
60 DCHECK(connect_callback_.is_null()); | 63 DCHECK(connect_callback_.is_null()); |
61 DCHECK(accepted_socket_); | 64 DCHECK(accepted_socket_); |
62 return base::WrapUnique( | 65 return base::WrapUnique(new StreamSocketConnection( |
63 new StreamSocketConnection(std::move(accepted_socket_))); | 66 std::move(accepted_socket_), blimp_connection_statistics_)); |
64 } | 67 } |
65 | 68 |
66 const char* TCPEngineTransport::GetName() const { | 69 const char* TCPEngineTransport::GetName() const { |
67 return "TCP"; | 70 return "TCP"; |
68 } | 71 } |
69 | 72 |
70 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { | 73 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { |
71 DCHECK(server_socket_); | 74 DCHECK(server_socket_); |
72 return server_socket_->GetLocalAddress(address); | 75 return server_socket_->GetLocalAddress(address); |
73 } | 76 } |
74 | 77 |
75 void TCPEngineTransport::OnTCPConnectAccepted(int result) { | 78 void TCPEngineTransport::OnTCPConnectAccepted(int result) { |
76 DCHECK_NE(net::ERR_IO_PENDING, result); | 79 DCHECK_NE(net::ERR_IO_PENDING, result); |
77 DCHECK(accepted_socket_); | 80 DCHECK(accepted_socket_); |
78 if (result != net::OK) { | 81 if (result != net::OK) { |
79 accepted_socket_.reset(); | 82 accepted_socket_.reset(); |
80 } | 83 } |
81 base::ResetAndReturn(&connect_callback_).Run(result); | 84 base::ResetAndReturn(&connect_callback_).Run(result); |
82 } | 85 } |
83 | 86 |
84 } // namespace blimp | 87 } // namespace blimp |
OLD | NEW |