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

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
« no previous file with comments | « remoting/host/websocket_connection_unittest.cc ('k') | remoting/host/websocket_listener.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..dd8436c84ee21c5cdd92f1ded639ef956180d00b
--- /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.
+ int Listen(const net::IPEndPoint& address,
+ const NewConnectionCallback& callback);
+
+ private:
+ // Calls ServerSocket::Accept() to accept new connections.
+ void DoAccept();
+
+ // Callback for ServerSocket::Accept().
+ void OnAccepted(int result);
+
+ // Handles Accept() result from DoAccept() or OnAccepted().
+ void HandleAcceptResult(int result);
+
+ // Callback for WebSocketConnection::Start().
+ void OnConnected(WebSocketConnection* connection_ptr, bool handshake_result);
+
+ scoped_ptr<net::TCPServerSocket> tcp_socket_;
+ 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.
+ std::set<WebSocketConnection*> pending_connections_;
+
+ base::WeakPtrFactory<WebSocketListener> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebSocketListener);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_WEBSOCKET_LISTENER_H_
« no previous file with comments | « remoting/host/websocket_connection_unittest.cc ('k') | remoting/host/websocket_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698