| 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_SERVER_SOCKET_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ |
| 6 #define MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ | 6 #define MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "mojo/public/cpp/bindings/strong_binding.h" | 9 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 10 #include "mojo/services/network/public/interfaces/tcp_server_socket.mojom.h" | 10 #include "mojo/services/network/public/interfaces/tcp_server_socket.mojom.h" |
| 11 #include "mojo/shell/public/cpp/shell.h" | 11 #include "mojo/shell/public/cpp/message_loop_ref.h" |
| 12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
| 13 #include "net/socket/tcp_socket.h" | 13 #include "net/socket/tcp_socket.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 | 16 |
| 17 class TCPServerSocketImpl : public TCPServerSocket { | 17 class TCPServerSocketImpl : public TCPServerSocket { |
| 18 public: | 18 public: |
| 19 typedef Callback<void(NetworkErrorPtr, NetAddressPtr)> AcceptCallback; | 19 typedef Callback<void(NetworkErrorPtr, NetAddressPtr)> AcceptCallback; |
| 20 | 20 |
| 21 // Passed ownership of a socket already in listening mode. | 21 // Passed ownership of a socket already in listening mode. |
| 22 TCPServerSocketImpl(scoped_ptr<net::TCPSocket> socket, | 22 TCPServerSocketImpl(scoped_ptr<net::TCPSocket> socket, |
| 23 scoped_ptr<mojo::AppRefCount> app_refcount, | 23 scoped_ptr<mojo::MessageLoopRef> app_refcount, |
| 24 InterfaceRequest<TCPServerSocket> request); | 24 InterfaceRequest<TCPServerSocket> request); |
| 25 ~TCPServerSocketImpl() override; | 25 ~TCPServerSocketImpl() override; |
| 26 | 26 |
| 27 // TCPServerSocket. | 27 // TCPServerSocket. |
| 28 void Accept(ScopedDataPipeConsumerHandle send_stream, | 28 void Accept(ScopedDataPipeConsumerHandle send_stream, |
| 29 ScopedDataPipeProducerHandle receive_stream, | 29 ScopedDataPipeProducerHandle receive_stream, |
| 30 InterfaceRequest<TCPConnectedSocket> client_socket, | 30 InterfaceRequest<TCPConnectedSocket> client_socket, |
| 31 const AcceptCallback& callback) override; | 31 const AcceptCallback& callback) override; |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 void OnAcceptCompleted(int result); | 34 void OnAcceptCompleted(int result); |
| 35 | 35 |
| 36 scoped_ptr<net::TCPSocket> socket_; | 36 scoped_ptr<net::TCPSocket> socket_; |
| 37 | 37 |
| 38 // Non-null when accept is pending. | 38 // Non-null when accept is pending. |
| 39 AcceptCallback pending_callback_; | 39 AcceptCallback pending_callback_; |
| 40 | 40 |
| 41 // The parameters associated with the pending Accept call. | 41 // The parameters associated with the pending Accept call. |
| 42 ScopedDataPipeConsumerHandle pending_send_stream_; | 42 ScopedDataPipeConsumerHandle pending_send_stream_; |
| 43 ScopedDataPipeProducerHandle pending_receive_stream_; | 43 ScopedDataPipeProducerHandle pending_receive_stream_; |
| 44 InterfaceRequest<TCPConnectedSocket> pending_client_socket_; | 44 InterfaceRequest<TCPConnectedSocket> pending_client_socket_; |
| 45 | 45 |
| 46 // These are written to by net::TCPSocket when Accept is completed. | 46 // These are written to by net::TCPSocket when Accept is completed. |
| 47 scoped_ptr<net::TCPSocket> accepted_socket_; | 47 scoped_ptr<net::TCPSocket> accepted_socket_; |
| 48 net::IPEndPoint accepted_address_; | 48 net::IPEndPoint accepted_address_; |
| 49 | 49 |
| 50 scoped_ptr<mojo::AppRefCount> app_refcount_; | 50 scoped_ptr<mojo::MessageLoopRef> app_refcount_; |
| 51 StrongBinding<TCPServerSocket> binding_; | 51 StrongBinding<TCPServerSocket> binding_; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 } // namespace mojo | 54 } // namespace mojo |
| 55 | 55 |
| 56 #endif // MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ | 56 #endif // MOJO_SERVICES_NETWORK_TCP_SERVER_SOCKET_H_ |
| OLD | NEW |