Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tcp_server_thread_for_testing.h
Go to the documentation of this file.
1 // Copyright 2016 Google Inc.
16 
17 #ifndef PAGESPEED_KERNEL_BASE_TCP_SERVER_THREAD_FOR_TESTING_H_
18 #define PAGESPEED_KERNEL_BASE_TCP_SERVER_THREAD_FOR_TESTING_H_
19 
20 #include "apr_pools.h"
21 #include "apr_network_io.h"
26 #include "pagespeed/kernel/base/thread_annotations.h"
28 
29 namespace net_instaweb {
30 
37 
39  public:
42  TcpServerThreadForTesting(apr_port_t listen_port, StringPiece thread_name,
43  ThreadSystem* thread_system);
44 
53  void ShutDown();
54 
55  virtual ~TcpServerThreadForTesting();
56 
59  apr_port_t GetListeningPort();
60 
63  static void PickListenPortOnce(apr_port_t* port_number);
64 
65  protected:
66  apr_pool_t* pool() { return pool_; }
67 
68  private:
72  virtual void HandleClientConnection(apr_socket_t* sock) = 0;
73 
76  apr_socket_t* CreateAndBindSocket() EXCLUSIVE_LOCKS_REQUIRED(mutex_);
77 
79  static void CreateAndBindSocket(apr_pool_t* apr_pool, apr_socket_t** socket,
80  apr_port_t* port);
81 
83  void Run() override;
84 
86  scoped_ptr<ThreadSystem::Condvar> ready_notify_ GUARDED_BY(mutex_);
87  apr_pool_t* pool_;
88  const apr_port_t requested_listen_port_;
89  apr_port_t actual_listening_port_ GUARDED_BY(mutex_);
90  apr_socket_t* listen_sock_ GUARDED_BY(mutex_);
91  bool terminating_ GUARDED_BY(mutex_);
92  bool is_shut_down_;
93 };
94 
95 }
96 
97 #endif
TcpServerThreadForTesting(apr_port_t listen_port, StringPiece thread_name, ThreadSystem *thread_system)
static void PickListenPortOnce(apr_port_t *port_number)
Definition: scoped_ptr.h:30
Definition: tcp_server_thread_for_testing.h:38
Definition: thread_system.h:40
Base class for client thread code.
Definition: thread.h:34