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_connected_socket_impl.h" | 5 #include "mojo/services/network/tcp_connected_socket_impl.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "mojo/services/network/net_adapters.h" | 8 #include "mojo/services/network/net_adapters.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 | 12 |
13 TCPConnectedSocketImpl::TCPConnectedSocketImpl( | 13 TCPConnectedSocketImpl::TCPConnectedSocketImpl( |
14 scoped_ptr<net::TCPSocket> socket, | 14 scoped_ptr<net::TCPSocket> socket, |
15 ScopedDataPipeConsumerHandle send_stream, | 15 ScopedDataPipeConsumerHandle send_stream, |
16 ScopedDataPipeProducerHandle receive_stream, | 16 ScopedDataPipeProducerHandle receive_stream, |
17 InterfaceRequest<TCPConnectedSocket> request) | 17 InterfaceRequest<TCPConnectedSocket> request) |
18 : socket_(socket.Pass()), | 18 : socket_(socket.Pass()), |
19 send_stream_(send_stream.Pass()), | 19 send_stream_(send_stream.Pass()), |
20 receive_stream_(receive_stream.Pass()), | 20 receive_stream_(receive_stream.Pass()), |
21 binding_(this, request.Pass()), | 21 binding_(this, request.Pass()), |
22 send_more_posted_(false), | 22 send_more_posted_(false), |
23 weak_ptr_factory_(this) { | 23 weak_ptr_factory_(this) { |
24 // Queue up async communication. | 24 // Queue up async communication. |
25 binding_.set_error_handler(this); | 25 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); |
26 ListenForReceivePeerClosed(); | 26 ListenForReceivePeerClosed(); |
27 ListenForSendPeerClosed(); | 27 ListenForSendPeerClosed(); |
28 ReceiveMore(); | 28 ReceiveMore(); |
29 SendMore(); | 29 SendMore(); |
30 } | 30 } |
31 | 31 |
32 TCPConnectedSocketImpl::~TCPConnectedSocketImpl() { | 32 TCPConnectedSocketImpl::~TCPConnectedSocketImpl() { |
33 } | 33 } |
34 | 34 |
35 void TCPConnectedSocketImpl::OnConnectionError() { | 35 void TCPConnectedSocketImpl::OnConnectionError() { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 256 } |
257 | 257 |
258 void TCPConnectedSocketImpl::DeleteIfNeeded() { | 258 void TCPConnectedSocketImpl::DeleteIfNeeded() { |
259 bool has_send = pending_send_ || send_stream_.is_valid(); | 259 bool has_send = pending_send_ || send_stream_.is_valid(); |
260 bool has_receive = pending_receive_ || receive_stream_.is_valid(); | 260 bool has_receive = pending_receive_ || receive_stream_.is_valid(); |
261 if (!binding_.is_bound() && !has_send && !has_receive) | 261 if (!binding_.is_bound() && !has_send && !has_receive) |
262 delete this; | 262 delete this; |
263 } | 263 } |
264 | 264 |
265 } // namespace mojo | 265 } // namespace mojo |
OLD | NEW |