James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ |
| 6 | #define MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ |
| 7 | |
| 8 | #include "base/memory/scoped_ptr.h" |
| 9 | #include "mojo/public/cpp/bindings/interface_impl.h" |
Colin Blundell | b470fa1 | 2014-12-10 16:28:40 +0100 | [diff] [blame] | 10 | #include "mojo/services/network/public/interfaces/tcp_server_socket.mojom.h" |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 11 | #include "net/base/ip_endpoint.h" |
| 12 | #include "net/socket/tcp_socket.h" |
| 13 | |
| 14 | namespace mojo { |
| 15 | |
| 16 | class TCPServerSocketImpl : public InterfaceImpl<TCPServerSocket> { |
| 17 | public: |
| 18 | typedef Callback<void(NetworkErrorPtr, NetAddressPtr)> AcceptCallback; |
| 19 | |
| 20 | // Passed ownership of a socket already in listening mode. |
| 21 | explicit TCPServerSocketImpl(scoped_ptr<net::TCPSocket> socket); |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 22 | ~TCPServerSocketImpl() override; |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 23 | |
| 24 | // TCPServerSocket. |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 25 | void Accept(ScopedDataPipeConsumerHandle send_stream, |
| 26 | ScopedDataPipeProducerHandle receive_stream, |
| 27 | InterfaceRequest<TCPConnectedSocket> client_socket, |
| 28 | const AcceptCallback& callback) override; |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 29 | |
| 30 | private: |
| 31 | void OnAcceptCompleted(int result); |
| 32 | |
| 33 | scoped_ptr<net::TCPSocket> socket_; |
| 34 | |
| 35 | // Non-null when accept is pending. |
| 36 | AcceptCallback pending_callback_; |
| 37 | |
| 38 | // The parameters associated with the pending Accept call. |
| 39 | ScopedDataPipeConsumerHandle pending_send_stream_; |
| 40 | ScopedDataPipeProducerHandle pending_receive_stream_; |
| 41 | InterfaceRequest<TCPConnectedSocket> pending_client_socket_; |
| 42 | |
| 43 | // These are written to by net::TCPSocket when Accept is completed. |
| 44 | scoped_ptr<net::TCPSocket> accepted_socket_; |
| 45 | net::IPEndPoint accepted_address_; |
| 46 | }; |
| 47 | |
| 48 | } // namespace mojo |
| 49 | |
| 50 | #endif // MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ |