15 #include <event2/listener.h>
54 virtual void Close(
void)
override;
96 static void Callback(evconnlistener * a_Listener, evutil_socket_t a_Socket, sockaddr * a_Addr,
int a_Len,
void * a_Self);
std::shared_ptr< cTCPLinkImpl > cTCPLinkImplPtr
std::vector< cServerHandleImplPtr > cServerHandleImplPtrs
std::vector< cTCPLinkImplPtr > cTCPLinkImplPtrs
std::shared_ptr< cServerHandleImpl > cServerHandleImplPtr
Interface that provides the methods available on a listening server socket.
std::shared_ptr< cListenCallbacks > cListenCallbacksPtr
cServerHandleImpl(cNetwork::cListenCallbacksPtr a_ListenCallbacks)
Creates a new instance with the specified callbacks.
evconnlistener * m_ConnListener
The LibEvent handle representing the main listening socket.
static void Callback(evconnlistener *a_Listener, evutil_socket_t a_Socket, sockaddr *a_Addr, int a_Len, void *a_Self)
The callback called by LibEvent upon incoming connection.
evconnlistener * m_SecondaryConnListener
The LibEvent handle representing the secondary listening socket (only when side-by-side listening is ...
AString m_ErrorMsg
Contains the error message for the failure to listen.
cServerHandleImplPtr m_SelfPtr
The SharedPtr to self, so that it can be passed to created links.
virtual bool IsListening(void) const override
Returns true if the server has been started correctly and is currently listening for incoming connect...
cTCPLinkImplPtrs m_Connections
Container for all currently active connections on this server.
cCriticalSection m_CS
Mutex protecting m_Connections againt multithreaded access.
virtual void Close(void) override
Stops the server, no more incoming connections will be accepted.
static cServerHandleImplPtr Listen(UInt16 a_Port, cNetwork::cListenCallbacksPtr a_ListenCallbacks)
Creates a new server instance listening on the specified port.
virtual ~cServerHandleImpl() override
Closes the server, dropping all the connections.
bool m_IsListening
Set to true when the server is initialized successfully and is listening for incoming connections.
int m_ErrorCode
Contains the error code for the failure to listen.
cNetwork::cListenCallbacksPtr m_ListenCallbacks
The callbacks used to notify about incoming connections.
void RemoveLink(const cTCPLinkImpl *a_Link)
Removes the specified link from m_Connections.