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