Chromium Code Reviews| 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. | |
|
Wez
2012/11/20 05:44:09
nit: "... each incoming connection until ..."
| |
| 35 int Listen(const net::IPEndPoint& address, | |
| 36 const NewConnectionCallback& callback); | |
| 37 | |
| 38 private: | |
| 39 // Calls ServerSocket::Accept() to accept new connections. | |
|
Wez
2012/11/20 05:44:09
nit: "... to accept the next connection."
| |
| 40 void DoAccept(); | |
| 41 | |
| 42 // Callback for ServerSocket::Accept(). | |
|
Wez
2012/11/20 05:44:09
nit: "Completion callback..."
| |
| 43 void OnAccepted(int result); | |
| 44 | |
| 45 // Handles Accept() result from DoAccept() or OnAccepted(). | |
|
Wez
2012/11/20 05:44:09
nit: "... Accept() completion result from ..."
| |
| 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_; | |
|
Wez
2012/11/20 05:44:09
nit: Add a comment "TCP socket on which to receive
| |
| 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. | |
|
Wez
2012/11/20 05:44:09
We should limit the number of pending connections,
| |
| 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 |