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, | |
21 net::NetLog* net_log) | 20 net::NetLog* net_log) |
22 : address_(address), | 21 : address_(address), net_log_(net_log) {} |
23 blimp_connection_statistics_(statistics), | |
24 net_log_(net_log) { | |
25 DCHECK(blimp_connection_statistics_); | |
26 } | |
27 | 22 |
28 TCPEngineTransport::~TCPEngineTransport() {} | 23 TCPEngineTransport::~TCPEngineTransport() {} |
29 | 24 |
30 void TCPEngineTransport::Connect(const net::CompletionCallback& callback) { | 25 void TCPEngineTransport::Connect(const net::CompletionCallback& callback) { |
31 DCHECK(!accepted_socket_); | 26 DCHECK(!accepted_socket_); |
32 DCHECK(!callback.is_null()); | 27 DCHECK(!callback.is_null()); |
33 | 28 |
34 if (!server_socket_) { | 29 if (!server_socket_) { |
35 server_socket_.reset( | 30 server_socket_.reset( |
36 new net::TCPServerSocket(net_log_, net::NetLog::Source())); | 31 new net::TCPServerSocket(net_log_, net::NetLog::Source())); |
(...skipping 20 matching lines...) Expand all Loading... |
57 server_socket_.reset(); | 52 server_socket_.reset(); |
58 } | 53 } |
59 | 54 |
60 base::MessageLoop::current()->PostTask(FROM_HERE, | 55 base::MessageLoop::current()->PostTask(FROM_HERE, |
61 base::Bind(callback, result)); | 56 base::Bind(callback, result)); |
62 } | 57 } |
63 | 58 |
64 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { | 59 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { |
65 DCHECK(connect_callback_.is_null()); | 60 DCHECK(connect_callback_.is_null()); |
66 DCHECK(accepted_socket_); | 61 DCHECK(accepted_socket_); |
67 return base::WrapUnique(new StreamSocketConnection( | 62 return base::WrapUnique( |
68 std::move(accepted_socket_), blimp_connection_statistics_)); | 63 new StreamSocketConnection(std::move(accepted_socket_))); |
69 } | 64 } |
70 | 65 |
71 const char* TCPEngineTransport::GetName() const { | 66 const char* TCPEngineTransport::GetName() const { |
72 return "TCP"; | 67 return "TCP"; |
73 } | 68 } |
74 | 69 |
75 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { | 70 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { |
76 DCHECK(server_socket_); | 71 DCHECK(server_socket_); |
77 return server_socket_->GetLocalAddress(address); | 72 return server_socket_->GetLocalAddress(address); |
78 } | 73 } |
79 | 74 |
80 void TCPEngineTransport::OnTCPConnectAccepted(int result) { | 75 void TCPEngineTransport::OnTCPConnectAccepted(int result) { |
81 DCHECK_NE(net::ERR_IO_PENDING, result); | 76 DCHECK_NE(net::ERR_IO_PENDING, result); |
82 DCHECK(accepted_socket_); | 77 DCHECK(accepted_socket_); |
83 if (result != net::OK) { | 78 if (result != net::OK) { |
84 accepted_socket_.reset(); | 79 accepted_socket_.reset(); |
85 } | 80 } |
86 base::ResetAndReturn(&connect_callback_).Run(result); | 81 base::ResetAndReturn(&connect_callback_).Run(result); |
87 } | 82 } |
88 | 83 |
89 } // namespace blimp | 84 } // namespace blimp |
OLD | NEW |