36#ifndef _UTILS_SOCKET_LISTENER_HXX_
37#define _UTILS_SOCKET_LISTENER_HXX_
65 const char *thread_name =
"accept_thread");
This class provides a threading API.
OSThread accept_thread_
Thread handle / instance for running the listen/accept loop.
volatile unsigned startupComplete_
1 if we have completed bind.
std::function< void(int)> connection_callback_t
Callback type that will be called when a new incoming connection is established.
int port_
Port to listen on.
void shutdown()
Shuts down the socket listener.
connection_callback_t callback_
Callback to call with each incoming conneciton.
SocketListener(int port, connection_callback_t callback, const char *thread_name="accept_thread")
Constructor.
void AcceptThreadBody()
Implementation of the accept thread.
volatile unsigned shutdownRequested_
1 if shutting down.
volatile unsigned shutdownComplete_
1 if accept thread is exited.
int ConnectSocket(const char *host, int port)
Connects a tcp socket to the specified remote host:port.