| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_TOOLS_FLIP_SERVER_ACCEPTOR_THREAD_H_ | 5 #ifndef NET_TOOLS_FLIP_SERVER_ACCEPTOR_THREAD_H_ |
| 6 #define NET_TOOLS_FLIP_SERVER_ACCEPTOR_THREAD_H_ | 6 #define NET_TOOLS_FLIP_SERVER_ACCEPTOR_THREAD_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 class FlipAcceptor; | 22 class FlipAcceptor; |
| 23 class MemoryCache; | 23 class MemoryCache; |
| 24 class SMConnection; | 24 class SMConnection; |
| 25 struct SSLState; | 25 struct SSLState; |
| 26 | 26 |
| 27 // TODO(mbelshe): Get rid of this class; we don't need a lock just to set | 27 // TODO(mbelshe): Get rid of this class; we don't need a lock just to set |
| 28 // a bool cross threads - especially one which only is set once... | 28 // a bool cross threads - especially one which only is set once... |
| 29 class Notification { | 29 class Notification { |
| 30 public: | 30 public: |
| 31 explicit Notification(bool value) : value_(value) {} | 31 explicit Notification(bool value) : value_(value) {} |
| 32 | 32 |
| 33 void Notify() { | 33 void Notify() { |
| 34 base::AutoLock al(lock_); | 34 base::AutoLock al(lock_); |
| 35 value_ = true; | 35 value_ = true; |
| 36 } | 36 } |
| 37 bool HasBeenNotified() { | 37 bool HasBeenNotified() { |
| 38 base::AutoLock al(lock_); | 38 base::AutoLock al(lock_); |
| 39 return value_; | 39 return value_; |
| 40 } | 40 } |
| 41 bool value_; | 41 bool value_; |
| 42 base::Lock lock_; | 42 base::Lock lock_; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 class SMAcceptorThread : public base::SimpleThread, | 45 class SMAcceptorThread : public base::SimpleThread, |
| 46 public EpollCallbackInterface, | 46 public EpollCallbackInterface, |
| 47 public SMConnectionPoolInterface { | 47 public SMConnectionPoolInterface { |
| 48 public: | 48 public: |
| 49 SMAcceptorThread(FlipAcceptor *acceptor, MemoryCache* memory_cache); | 49 SMAcceptorThread(FlipAcceptor* acceptor, MemoryCache* memory_cache); |
| 50 virtual ~SMAcceptorThread(); | 50 virtual ~SMAcceptorThread(); |
| 51 | 51 |
| 52 // EpollCallbackInteface interface | 52 // EpollCallbackInteface interface |
| 53 virtual void OnRegistration(EpollServer* eps, | 53 virtual void OnRegistration(EpollServer* eps, |
| 54 int fd, | 54 int fd, |
| 55 int event_mask) OVERRIDE {} | 55 int event_mask) OVERRIDE {} |
| 56 virtual void OnModification(int fd, int event_mask) OVERRIDE {} | 56 virtual void OnModification(int fd, int event_mask) OVERRIDE {} |
| 57 virtual void OnEvent(int fd, EpollEvent* event) OVERRIDE; | 57 virtual void OnEvent(int fd, EpollEvent* event) OVERRIDE; |
| 58 virtual void OnUnregistration(int fd, bool replaced) OVERRIDE {} | 58 virtual void OnUnregistration(int fd, bool replaced) OVERRIDE {} |
| 59 virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {} | 59 virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {} |
| 60 | 60 |
| 61 // SMConnectionPool interface | 61 // SMConnectionPool interface |
| 62 virtual void SMConnectionDone(SMConnection* sc) OVERRIDE; | 62 virtual void SMConnectionDone(SMConnection* sc) OVERRIDE; |
| 63 | 63 |
| 64 // TODO(mbelshe): figure out if we can move these to private functions. | 64 // TODO(mbelshe): figure out if we can move these to private functions. |
| 65 SMConnection* NewConnection(); | 65 SMConnection* NewConnection(); |
| 66 SMConnection* FindOrMakeNewSMConnection(); | 66 SMConnection* FindOrMakeNewSMConnection(); |
| 67 void InitWorker(); | 67 void InitWorker(); |
| 68 void HandleConnection(int server_fd, struct sockaddr_in *remote_addr); | 68 void HandleConnection(int server_fd, struct sockaddr_in* remote_addr); |
| 69 void AcceptFromListenFD(); | 69 void AcceptFromListenFD(); |
| 70 | 70 |
| 71 // Notify the Accept thread that it is time to terminate. | 71 // Notify the Accept thread that it is time to terminate. |
| 72 void Quit() { quitting_.Notify(); } | 72 void Quit() { quitting_.Notify(); } |
| 73 | 73 |
| 74 // Iterates through a list of active connections expiring any that have been | 74 // Iterates through a list of active connections expiring any that have been |
| 75 // idle longer than the configured timeout. | 75 // idle longer than the configured timeout. |
| 76 void HandleConnectionIdleTimeout(); | 76 void HandleConnectionIdleTimeout(); |
| 77 | 77 |
| 78 virtual void Run() OVERRIDE; | 78 virtual void Run() OVERRIDE; |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 EpollServer epoll_server_; | 81 EpollServer epoll_server_; |
| 82 FlipAcceptor* acceptor_; | 82 FlipAcceptor* acceptor_; |
| 83 SSLState* ssl_state_; | 83 SSLState* ssl_state_; |
| 84 bool use_ssl_; | 84 bool use_ssl_; |
| 85 int idle_socket_timeout_s_; | 85 int idle_socket_timeout_s_; |
| 86 | 86 |
| 87 std::vector<SMConnection*> unused_server_connections_; | 87 std::vector<SMConnection*> unused_server_connections_; |
| 88 std::vector<SMConnection*> tmp_unused_server_connections_; | 88 std::vector<SMConnection*> tmp_unused_server_connections_; |
| 89 std::vector<SMConnection*> allocated_server_connections_; | 89 std::vector<SMConnection*> allocated_server_connections_; |
| 90 std::list<SMConnection*> active_server_connections_; | 90 std::list<SMConnection*> active_server_connections_; |
| 91 Notification quitting_; | 91 Notification quitting_; |
| 92 MemoryCache* memory_cache_; | 92 MemoryCache* memory_cache_; |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 } // namespace net | 95 } // namespace net |
| 96 | 96 |
| 97 #endif // NET_TOOLS_FLIP_SERVER_ACCEPTOR_THREAD_H_ | 97 #endif // NET_TOOLS_FLIP_SERVER_ACCEPTOR_THREAD_H_ |
| OLD | NEW |