| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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 REMOTING_HOST_WEBSOCKET_LISTENER_H_ |
| 6 #define REMOTING_HOST_WEBSOCKET_LISTENER_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "net/socket/tcp_server_socket.h" |
| 14 |
| 15 namespace net { |
| 16 class IPEndPoint; |
| 17 class StreamSocket; |
| 18 } // namespace net |
| 19 |
| 20 namespace remoting { |
| 21 |
| 22 class WebSocketConnection; |
| 23 |
| 24 class WebSocketListener { |
| 25 public: |
| 26 typedef base::Callback< |
| 27 void(scoped_ptr<WebSocketConnection> connection)> NewConnectionCallback; |
| 28 |
| 29 WebSocketListener(); |
| 30 ~WebSocketListener(); |
| 31 |
| 32 // Starts listening on the specified address and returns net::Error code in |
| 33 // case of a failure. When successful, the specified |callback| will be called |
| 34 // for each incoming until the listener is destroyed. |
| 35 int Listen(const net::IPEndPoint& address, |
| 36 const NewConnectionCallback& callback); |
| 37 |
| 38 private: |
| 39 // Calls ServerSocket::Accept() to accept new connections. |
| 40 void DoAccept(); |
| 41 |
| 42 // Callback for ServerSocket::Accept(). |
| 43 void OnAccepted(int result); |
| 44 |
| 45 // Handles Accept() result from DoAccept() or OnAccepted(). |
| 46 void HandleAcceptResult(int result); |
| 47 |
| 48 // Callback for WebSocketConnection::Start(). |
| 49 void OnConnected(WebSocketConnection* connection_ptr, bool handshake_result); |
| 50 |
| 51 scoped_ptr<net::TCPServerSocket> tcp_socket_; |
| 52 NewConnectionCallback new_connection_callback_; |
| 53 |
| 54 // Object passed to Accept() when accepting incoming connections. |
| 55 scoped_ptr<net::StreamSocket> accepted_socket_; |
| 56 |
| 57 // Incoming connections that have been accepted, but for which we haven't |
| 58 // received headers yet and haven't called |new_connection_callback_|. They |
| 59 // are owned by the listener until we receive headers and call the callback. |
| 60 std::set<WebSocketConnection*> pending_connections_; |
| 61 |
| 62 base::WeakPtrFactory<WebSocketListener> weak_factory_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(WebSocketListener); |
| 65 }; |
| 66 |
| 67 } // namespace remoting |
| 68 |
| 69 #endif // REMOTING_HOST_WEBSOCKET_LISTENER_H_ |
| OLD | NEW |