Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(834)

Unified Diff: remoting/host/websocket_listener.h

Issue 11358190: Add simple WebSocket server implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/websocket_listener.h
diff --git a/remoting/host/websocket_listener.h b/remoting/host/websocket_listener.h
new file mode 100644
index 0000000000000000000000000000000000000000..075192d6ada813d82ca1aa724d3030c3867cadfa
--- /dev/null
+++ b/remoting/host/websocket_listener.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_HOST_WEBSOCKET_LISTENER_H_
+#define REMOTING_HOST_WEBSOCKET_LISTENER_H_
+
+#include <set>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "net/socket/tcp_server_socket.h"
+
+namespace net {
+class IPEndPoint;
+class StreamSocket;
+} // namespace net
+
+namespace remoting {
+
+class WebsocketConnection;
+
+class WebsocketListener {
+ public:
+ typedef base::Callback<
+ void(scoped_ptr<WebsocketConnection> connection)> NewConnectionCallback;
+
+ WebsocketListener();
+ ~WebsocketListener();
+
+ // Starts listening on the specified address and returns net::Error code in
+ // case of a failure. When successful, the specified |callback| will be called
+ // for each incoming until the listener is destroyed.
Wez 2012/11/20 05:44:09 nit: "... each incoming connection until ..."
+ int Listen(const net::IPEndPoint& address,
+ const NewConnectionCallback& callback);
+
+ private:
+ // Calls ServerSocket::Accept() to accept new connections.
Wez 2012/11/20 05:44:09 nit: "... to accept the next connection."
+ void DoAccept();
+
+ // Callback for ServerSocket::Accept().
Wez 2012/11/20 05:44:09 nit: "Completion callback..."
+ void OnAccepted(int result);
+
+ // Handles Accept() result from DoAccept() or OnAccepted().
Wez 2012/11/20 05:44:09 nit: "... Accept() completion result from ..."
+ void HandleAcceptResult(int result);
+
+ // Callback for WebsocketConnection::Start().
+ void OnConnected(WebsocketConnection* connection_ptr, bool handshake_result);
+
+ scoped_ptr<net::TCPServerSocket> tcp_socket_;
Wez 2012/11/20 05:44:09 nit: Add a comment "TCP socket on which to receive
+ NewConnectionCallback new_connection_callback_;
+
+ // Object passed to Accept() when accepting incoming connections.
+ scoped_ptr<net::StreamSocket> accepted_socket_;
+
+ // Incoming connections that have been accepted, but for which we haven't
+ // received headers yet and haven't called |new_connection_callback_|. They
+ // 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,
+ std::set<WebsocketConnection*> pending_connections_;
+
+ base::WeakPtrFactory<WebsocketListener> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebsocketListener);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_WEBSOCKET_LISTENER_H_

Powered by Google App Engine
This is Rietveld 408576698