Defined in file: hzIpServer.h

General purpose server class.

Constructors/Detructors

hzIpServer*hzIpServer(void)
NULL-TYPEhzIpServer(void)Private Constructor
void~hzIpServer(void)

Public Methods:

hzEcodeActivate(void)Purpose: Activates all listening sockets added to the server by AddPort(). This must only be called once. Arguments: None
hzEcodeAddPortHTTP(hzTcpCode(*)(hzHttpEvent*) OnHttpReq)uint32_t nTimeout, uint32_t nPort, uint32_t nMaxClients, bool bSecure, Purpose: Add a listening port, customized for HTTP, to the singleton hzIpServer instance. This will allow the application to act as a web server.
hzEcodeAddPortTCP(hzTcpCode(*)(hzChain&,hzIpConnex*) OnIngress)hzTcpCode(*)(hzIpConnex*) OnConnect, hzTcpCode(*)(hzIpConnex*) OnDisconn, uint32_t nTimeout, uint32_t nPort, uint32_t nMaxClients, bool bSecure, This function adds a listening socket operating on the assigned port, to a server. The client connections (hzIpConnex instances) call an application specific function each time data comes in on the port. Nothing is assumed about the incoming data so it is nessesary that the application specific function determines if the data forms a complete message or not and acts accordingly.
hzEcodeAddPortUDP(hzTcpCode(*)(hzChain&,hzIpConnex*) OnIngress)hzTcpCode(*)(hzIpConnex*) OnConnect, hzTcpCode(*)(hzIpConnex*) OnDisconn, uint32_t nTimeout, uint32_t nPort, uint32_t nMaxClients, bool bSecure, This function adds a listening socket operating on the assigned port, to a server. The client connections (hzIpConnex instances) call an application specific function each time data comes in on the port. Nothing is assumed about the incoming data so it is nessesary that the application specific function determines if the data forms a complete message or not and acts accordingly.
hzEcodeAddPortUNIX(hzTcpCode(*)(hzChain&,hzIpConnex*) OnIngress)hzTcpCode(*)(hzIpConnex*) OnConnect, hzTcpCode(*)(hzIpConnex*) OnDisconn, const char* sockFile, uint32_t nTimeout, uint32_t nMaxConn, Adds a listening socket and application specific event handlers, for UNIX socket connections.
hzIpServer*GetInstance(hzLogger* pLogger)Purpose: Creates singleton hzIpServer instance Pointer to the hzIpServer instance. The same instance is returned however many times this function is called. NULL if no logger is provided
voidHalt(void)
hzEcodeProxyTo(hzIpConnex* pConn)uint32_t nPort, Set up a proxy connection to be associated with the supplied connection. The proxy connection is then placed in the epoll event queue. - The supplied connection must be valid - If the other connection does not exist it will be created Please note that connections have three possible types as follows:- Direct: The hzIpConnex is that of a direct client of this service, with no proxy. In this case the hzIpConnex m_Input member receives the client requests (populated by epoll read events). The m_Outgoing member is populated by processing the request (i.e. it is the response). The contents of m_Outgoing are written to the client socket by the _xmit function. Has Proxy: The hzIpConnex is that of a client of this service, but has a proxy hzIpConnex to another service. Once the proxy hzIpConnex is established, the epoll reads are redirected. Instead of populating the m_Input member of the client hzIpConnex instance, client requests arriving via epoll reads populate the m_Outgoing member of the proxy hzIpConnex instance. The _xmit function as applied to the proxy hzIpConnex instance, then transmits the request to the other service. Is Proxy: The hzIpConnex is the proxy, which is the mirror image of the has-proxy case. The input (the response from the other service), is redirected to populate the m_Outgoing member of the client hzIpConnex. The _xmit function as applied to the client hzIpConnex instance, then transmits the response to the client. This function creates the proxy hzIpConnex instance, forms the association with the client hzIpConnex, and copies across any data received so far.
voidServe(void)Epoll server in edge-triggered mode. In this mode, all client connections are non-blocking and notification that a socket has data available for reaading, is only given at the point the data arrives. Consequently, sockets must always be read until no more data is available. Arguments: None Returns: None Note: Call only once for all listening sockets! This function will not return until the server is shut down
voidServeRequests(void)Calculate number of request server thread as this will serve as the divisor Arguments: None Returns: None
voidServeResponses(void)
voidServeX(void)Act as server based on the epoll method. This function is strickly for use in multi threaded servers. In the epoll method, the epoll socket (the one which activates the polling) is allocated and used to set up the controlling array of sockets. This array includes listening sockets as well as the sockets of connected clients. Arguments: None Returns: None Note: Call only once for all listening sockets! This function will not return until the server is shut down
voidSetLogger(hzLogger* pLog)
voidSetStats(hzLogger* pStats)
voidSetTimeout(uint32_t Timeout)
hzEcode_nonblock(uint32_t nSock)Make the socket non-blocking (to be handled by epoll)

Member Variables:

hzMapS<uint32_t,hzIpConnex*>ConnInErrorMap of TCP clients in error
hzList<hzIpListen*>m_LSListening sockets
epoll_event*m_arEventsEpoll event array
boolm_bActiveSocket to start listening
boolm_bShutdownSocket to stop listening
uint32_tm_eErrorError code
hzMapS<uint32_t,hzIpListen*>m_mapLSListening sockets map
intm_nCliLenLength of client
uint32_tm_nCurrentClientsCurrent number of connected clients.
uint32_tm_nLoopNumber of time round epoll loop (run time total)
uint32_tm_nMaxClientsMaximum number of simultaneous connections.
uint32_tm_nMaxSocketHighest socket for the select function
uint32_tm_nTimeoutTimeout for select
hzLogger*m_pLogLog channel to use for events
hzLogger*m_pStatsLog channel to use for stats
int32_ts_epollSocketThe epoll 'master' socket
hzMapS<hzIpaddr,hzIpConnex*>udpClientsMap of UDP clients by IP address