Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
net_instaweb::TcpServerThreadForTesting Class Referenceabstract

#include "tcp_server_thread_for_testing.h"

Inheritance diagram for net_instaweb::TcpServerThreadForTesting:
net_instaweb::ThreadSystem::Thread

Public Member Functions

 TcpServerThreadForTesting (apr_port_t listen_port, StringPiece thread_name, ThreadSystem *thread_system)
 
void ShutDown ()
 
apr_port_t GetListeningPort ()
 
- Public Member Functions inherited from net_instaweb::ThreadSystem::Thread
 Thread (ThreadSystem *runtime, StringPiece name, ThreadFlags flags)
 
virtual ~Thread ()
 
bool Start ()
 
bool Started () const
 
void Join ()
 
GoogleString name () const
 

Static Public Member Functions

static void PickListenPortOnce (apr_port_t *port_number)
 

Protected Member Functions

apr_pool_t * pool ()
 

Detailed Description

Implementation of Thread that uses APR to listen on a TCP port and then delegates to a virtual function to handle single connection. This code is absolutely not suitable for use outside of tests. Please note that even though server stops after processing a single connection, several connections could be established depending on the way OS handles TCP backlog.

Constructor & Destructor Documentation

net_instaweb::TcpServerThreadForTesting::TcpServerThreadForTesting ( apr_port_t  listen_port,
StringPiece  thread_name,
ThreadSystem thread_system 
)

listen_port may be 0, in which case the system will pick the port. The socket isn't actually created until the thread is Start()ed.

Member Function Documentation

apr_port_t net_instaweb::TcpServerThreadForTesting::GetListeningPort ( )

Wait for thread to successfully start listening and then return the actual bound port number, which will be bound to IPv4 localhost.

static void net_instaweb::TcpServerThreadForTesting::PickListenPortOnce ( apr_port_t *  port_number)
static

Helper to deal with only allocating the listening port once. port_number must be a pointer to a static apr_port_t.

void net_instaweb::TcpServerThreadForTesting::ShutDown ( )

Blocks until the server thread has exited. If the server has not received a connection yet, aborts accept() call, causing the thread to terminate and log an error. This function should be called in subclass' destructor.

It cannot be called in ~TcpServerThreadForTesting() because that results in race over vptr between destructor (which modifies vptr to TcpServerThreadForTesting before executing body) and call to HandleClientConnection() in the server thread.


The documentation for this class was generated from the following file: