Page Speed Optimization Libraries
1.13.35.1
|
#include "tcp_server_thread_for_testing.h"
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 () |
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.
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.
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 |
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.