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 "mojo/services/network/tcp_bound_socket_impl.h" | 5 #include "mojo/services/network/tcp_bound_socket_impl.h" |
6 | 6 |
7 #include "mojo/services/network/net_adapters.h" | 7 #include "mojo/services/network/net_adapters.h" |
8 #include "mojo/services/network/net_address_type_converters.h" | 8 #include "mojo/services/network/net_address_type_converters.h" |
9 #include "mojo/services/network/tcp_connected_socket_impl.h" | 9 #include "mojo/services/network/tcp_connected_socket_impl.h" |
10 #include "mojo/services/network/tcp_server_socket_impl.h" | 10 #include "mojo/services/network/tcp_server_socket_impl.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 | 14 |
15 TCPBoundSocketImpl::TCPBoundSocketImpl() { | 15 TCPBoundSocketImpl::TCPBoundSocketImpl(InterfaceRequest<TCPBoundSocket> request) |
| 16 : binding_(this, request.Pass()) { |
16 } | 17 } |
17 | 18 |
18 TCPBoundSocketImpl::~TCPBoundSocketImpl() { | 19 TCPBoundSocketImpl::~TCPBoundSocketImpl() { |
19 } | 20 } |
20 | 21 |
21 int TCPBoundSocketImpl::Bind(NetAddressPtr local_address) { | 22 int TCPBoundSocketImpl::Bind(NetAddressPtr local_address) { |
22 net::IPEndPoint end_point = local_address.To<net::IPEndPoint>(); | 23 net::IPEndPoint end_point = local_address.To<net::IPEndPoint>(); |
23 | 24 |
24 socket_.reset(new net::TCPSocket(NULL, net::NetLog::Source())); | 25 socket_.reset(new net::TCPSocket(NULL, net::NetLog::Source())); |
25 int result = socket_->Open(end_point.GetFamily()); | 26 int result = socket_->Open(end_point.GetFamily()); |
(...skipping 30 matching lines...) Expand all Loading... |
56 } | 57 } |
57 | 58 |
58 // TODO(brettw) set the backlog properly. | 59 // TODO(brettw) set the backlog properly. |
59 int result = socket_->Listen(4); | 60 int result = socket_->Listen(4); |
60 if (result != net::OK) { | 61 if (result != net::OK) { |
61 callback.Run(MakeNetworkError(result)); | 62 callback.Run(MakeNetworkError(result)); |
62 return; | 63 return; |
63 } | 64 } |
64 | 65 |
65 // The server socket object takes ownership of the socket. | 66 // The server socket object takes ownership of the socket. |
66 BindToRequest(new TCPServerSocketImpl(socket_.Pass()), &server); | 67 new TCPServerSocketImpl(server.Pass(), socket_.Pass()); |
67 callback.Run(MakeNetworkError(net::OK)); | 68 callback.Run(MakeNetworkError(net::OK)); |
68 } | 69 } |
69 | 70 |
70 void TCPBoundSocketImpl::Connect( | 71 void TCPBoundSocketImpl::Connect( |
71 NetAddressPtr remote_address, | 72 NetAddressPtr remote_address, |
72 ScopedDataPipeConsumerHandle send_stream, | 73 ScopedDataPipeConsumerHandle send_stream, |
73 ScopedDataPipeProducerHandle receive_stream, | 74 ScopedDataPipeProducerHandle receive_stream, |
74 InterfaceRequest<TCPConnectedSocket> client_socket, | 75 InterfaceRequest<TCPConnectedSocket> client_socket, |
75 const Callback<void(NetworkErrorPtr)>& callback) { | 76 const Callback<void(NetworkErrorPtr)>& callback) { |
76 if (!socket_ || pending_connect_socket_.is_pending()) { | 77 if (!socket_ || pending_connect_socket_.is_pending()) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } else { | 111 } else { |
111 pending_connect_send_stream_.reset(); | 112 pending_connect_send_stream_.reset(); |
112 pending_connect_receive_stream_.reset(); | 113 pending_connect_receive_stream_.reset(); |
113 pending_connect_socket_ = InterfaceRequest<TCPConnectedSocket>(); | 114 pending_connect_socket_ = InterfaceRequest<TCPConnectedSocket>(); |
114 } | 115 } |
115 pending_connect_callback_.Run(MakeNetworkError(result)); | 116 pending_connect_callback_.Run(MakeNetworkError(result)); |
116 pending_connect_callback_ = Callback<void(NetworkErrorPtr)>(); | 117 pending_connect_callback_ = Callback<void(NetworkErrorPtr)>(); |
117 } | 118 } |
118 | 119 |
119 } // namespace mojo | 120 } // namespace mojo |
OLD | NEW |