OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 NET_WEB2SOCKET_PROXY_WEB2SOCKET_SERV_H_ |
| 6 #define NET_WEB2SOCKET_PROXY_WEB2SOCKET_SERV_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <list> |
| 11 #include <map> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "net/web2socket_proxy/web2socket.h" |
| 15 |
| 16 struct sockaddr; |
| 17 |
| 18 class Web2SocketServ { |
| 19 public: |
| 20 static const size_t kReadBufferLimit = 120 * 1024; |
| 21 |
| 22 // Limits number of simultaneously open connections. |
| 23 static const size_t kConnPoolLimit = 2000; |
| 24 |
| 25 Web2SocketServ(const std::string& origin, |
| 26 struct sockaddr* addr, |
| 27 int addr_len); |
| 28 ~Web2SocketServ(); |
| 29 |
| 30 void Run(); |
| 31 |
| 32 void ZapConn(struct Conn*); |
| 33 void MarkConnImportance(struct Conn*, bool important); |
| 34 struct Conn* GetFreshConn(); |
| 35 bool IsConnSane(struct Conn*); |
| 36 |
| 37 static void OnConnect(int listening_sock, short event, void*); |
| 38 |
| 39 // Return true on success. |
| 40 static bool SetNonBlock(int fd); |
| 41 static bool IgnoreSigPipe(void); |
| 42 |
| 43 const std::string& origin() const { return origin_; } |
| 44 struct event_base* evbase() { return evbase_; } |
| 45 |
| 46 private: |
| 47 // Checked against value of Origin field specified |
| 48 // in a client websocket handshake. |
| 49 std::string origin_; |
| 50 |
| 51 // Address to listen incoming websocket connections. |
| 52 struct sockaddr* addr_; |
| 53 int addr_len_; |
| 54 |
| 55 // Libevent base. |
| 56 struct event_base* evbase_; |
| 57 |
| 58 // Socket to listen incoming websocket connections. |
| 59 int listening_sock_; |
| 60 |
| 61 // List of pending connections; We are trying to keep size of this list |
| 62 // below kConnPoolLimit in LRU fashion. |
| 63 typedef std::list<struct Conn*> ConnPool; |
| 64 ConnPool conn_pool_; |
| 65 |
| 66 // Reverse map to look up a connection in a conn_pool. |
| 67 typedef std::map<struct Conn*, ConnPool::iterator> RevMap; |
| 68 RevMap rev_map_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(Web2SocketServ); |
| 71 }; |
| 72 |
| 73 #endif // NET_WEB2SOCKET_PROXY_WEB2SOCKET_SERV_H_ |
OLD | NEW |