Index: net/web2socket_proxy/web2socket_serv.h |
diff --git a/net/web2socket_proxy/web2socket_serv.h b/net/web2socket_proxy/web2socket_serv.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2a58dc5724f985351138167b9830e7241d9a46bb |
--- /dev/null |
+++ b/net/web2socket_proxy/web2socket_serv.h |
@@ -0,0 +1,73 @@ |
+// Copyright (c) 2010 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 NET_WEB2SOCKET_PROXY_WEB2SOCKET_SERV_H_ |
+#define NET_WEB2SOCKET_PROXY_WEB2SOCKET_SERV_H_ |
+ |
+#include <stdint.h> |
+ |
+#include <list> |
+#include <map> |
+ |
+#include "base/basictypes.h" |
+#include "net/web2socket_proxy/web2socket.h" |
+ |
+struct sockaddr; |
+ |
+class Web2SocketServ { |
+ public: |
+ static const size_t kReadBufferLimit = 120 * 1024; |
+ |
+ // Limits number of simultaneously open connections. |
+ static const size_t kConnPoolLimit = 2000; |
+ |
+ Web2SocketServ(const std::string& origin, |
+ struct sockaddr* addr, |
+ int addr_len); |
+ ~Web2SocketServ(); |
+ |
+ void Run(); |
+ |
+ void ZapConn(struct Conn*); |
+ void MarkConnImportance(struct Conn*, bool important); |
+ struct Conn* GetFreshConn(); |
+ bool IsConnSane(struct Conn*); |
+ |
+ static void OnConnect(int listening_sock, short event, void*); |
+ |
+ // Return true on success. |
+ static bool SetNonBlock(int fd); |
+ static bool IgnoreSigPipe(void); |
+ |
+ const std::string& origin() const { return origin_; } |
+ struct event_base* evbase() { return evbase_; } |
+ |
+ private: |
+ // Checked against value of Origin field specified |
+ // in a client websocket handshake. |
+ std::string origin_; |
+ |
+ // Address to listen incoming websocket connections. |
+ struct sockaddr* addr_; |
+ int addr_len_; |
+ |
+ // Libevent base. |
+ struct event_base* evbase_; |
+ |
+ // Socket to listen incoming websocket connections. |
+ int listening_sock_; |
+ |
+ // List of pending connections; We are trying to keep size of this list |
+ // below kConnPoolLimit in LRU fashion. |
+ typedef std::list<struct Conn*> ConnPool; |
+ ConnPool conn_pool_; |
+ |
+ // Reverse map to look up a connection in a conn_pool. |
+ typedef std::map<struct Conn*, ConnPool::iterator> RevMap; |
+ RevMap rev_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Web2SocketServ); |
+}; |
+ |
+#endif // NET_WEB2SOCKET_PROXY_WEB2SOCKET_SERV_H_ |