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 #ifndef MOJO_SERVICES_NETWORK_TCP_BOUND_SOCKET_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_TCP_BOUND_SOCKET_H_ |
6 #define MOJO_SERVICES_NETWORK_TCP_BOUND_SOCKET_H_ | 6 #define MOJO_SERVICES_NETWORK_TCP_BOUND_SOCKET_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "mojo/public/cpp/bindings/interface_impl.h" | 9 #include "mojo/public/cpp/bindings/interface_impl.h" |
10 #include "mojo/services/public/interfaces/network/tcp_bound_socket.mojom.h" | 10 #include "mojo/services/public/interfaces/network/tcp_bound_socket.mojom.h" |
11 #include "net/socket/tcp_socket.h" | 11 #include "net/socket/tcp_socket.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 | 14 |
15 class TCPBoundSocketImpl : public InterfaceImpl<TCPBoundSocket> { | 15 class TCPBoundSocketImpl : public InterfaceImpl<TCPBoundSocket> { |
16 public: | 16 public: |
17 TCPBoundSocketImpl(); | 17 TCPBoundSocketImpl(); |
18 virtual ~TCPBoundSocketImpl(); | 18 virtual ~TCPBoundSocketImpl(); |
19 | 19 |
| 20 // Does the actual binding. Returns a net error code. On net::OK, the bound |
| 21 // socket will be ready to use and send back to the client. On failure, this |
| 22 // object should be destroyed and no longer used. |
20 int Bind(NetAddressPtr local_address); | 23 int Bind(NetAddressPtr local_address); |
21 | 24 |
22 // Returns the local address associated with this socket. This should only | 25 // Returns the local address associated with this socket. This should only |
23 // be called after Bind has succeeded. | 26 // be called after Bind has succeeded. |
24 NetAddressPtr GetLocalAddress() const; | 27 NetAddressPtr GetLocalAddress() const; |
25 | 28 |
26 // TCPBoundSocket. | 29 // TCPBoundSocket. |
27 virtual void StartListening( | 30 virtual void StartListening( |
28 InterfaceRequest<TCPServerSocket> server, | 31 InterfaceRequest<TCPServerSocket> server, |
29 const Callback<void(NetworkErrorPtr)>& callback) override; | 32 const Callback<void(NetworkErrorPtr)>& callback) override; |
30 virtual void Connect( | 33 virtual void Connect( |
31 NetAddressPtr remote_address, | 34 NetAddressPtr remote_address, |
32 ScopedDataPipeConsumerHandle send_stream, | 35 ScopedDataPipeConsumerHandle send_stream, |
33 ScopedDataPipeProducerHandle receive_stream, | 36 ScopedDataPipeProducerHandle receive_stream, |
34 InterfaceRequest<TCPConnectedSocket> client_socket, | 37 InterfaceRequest<TCPConnectedSocket> client_socket, |
35 const Callback<void(NetworkErrorPtr)>& callback) override; | 38 const Callback<void(NetworkErrorPtr)>& callback) override; |
36 | 39 |
37 private: | 40 private: |
| 41 void OnConnected(int result); |
| 42 |
38 scoped_ptr<net::TCPSocket> socket_; | 43 scoped_ptr<net::TCPSocket> socket_; |
| 44 |
| 45 // Valid when waiting for a connect callback. |
| 46 ScopedDataPipeConsumerHandle pending_connect_send_stream_; |
| 47 ScopedDataPipeProducerHandle pending_connect_receive_stream_; |
| 48 InterfaceRequest<TCPConnectedSocket> pending_connect_socket_; |
| 49 Callback<void(NetworkErrorPtr)> pending_connect_callback_; |
39 }; | 50 }; |
40 | 51 |
41 } // namespace mojo | 52 } // namespace mojo |
42 | 53 |
43 #endif // MOJO_SERVICES_NETWORK_TCP_BOUND_SOCKET_H_ | 54 #endif // MOJO_SERVICES_NETWORK_TCP_BOUND_SOCKET_H_ |
OLD | NEW |