Purpose: Add a listening port, customized for HTTP, to the singleton hzIpServer instance. This will allow the application to act as a web server.

Return TypeFunction nameArguments
hzEcodehzIpServer::AddPortHTTP(hzTcpCode(*)(hzHttpEvent*),uint32_t,uint32_t,uint32_t,bool,)

Declared in file: hzIpServer.h
Defined in file : hzIpServer.cpp

Function Logic:

0:START 1:unknown 2:items 3:Return E_ARGUMENT 4:unknown 5:items 6:Return E_INITDUP 7:unknown 8:pLS 9:unknown 10:Return hzerr(E_INITDUP,Socket already initialized and listening on port %d\n,pLS->GetPort()) 11:unknown 12:Return hzerr(E_MEMORY,SERIOUS ERROR - Could not allocate an LS for server) 13:opflags 14:unknown 15:opflags 16:unknown 17:Return hzerr(E_INITFAIL,SERIOUS ERROR - Could not initialize an LS for server) 18:pLS 19:unknown 20:Return hzerr(E_INITFAIL,SERIOUS ERROR - Could not insert an LS for server) 21:Return E_OK

Function body:

hzEcode hzIpServer::AddPortHTTP (hzTcpCode(*)(hzHttpEvent*) OnHttpReq)uint32_t nTimeout, uint32_t nPort, uint32_t nMaxClients, bool bSecure, 
{
   //  Category: Internet Server
   //  
   //  Purpose: Add a listening port, customized for HTTP, to the singleton hzIpServer instance. This will allow the application
   //     to act as a web server.
   //  
   //  Arguments: 1) OnHttpReq  Application Specific 'Do Something' function called each time a complete HTTP request has come from a connected client. 
   //     2) nTimeout  Timeout in seconds.
   //     3) nPort   Port number
   //     4) nMaxClients  Max number of connections on the port (before server blocks listening socket)
   //     5) bSecure   Flag to indicate SSL
   //  
   //  Returns: E_ARGUMENT If the 'HandleHttpEvent' function pointer is null.
   //     E_RANGE  If the port number is out of range
   //     E_INITDUP If there is already a listening socket on the supplied port number
   //     E_MEMORY If the is insufficient memory to allocate the hzIpListen for the port
   //     E_INITFIAL If the hzIpListen could not be initialized
   //     E_OK  If the operation was successful.
   _hzfunc("hzIpServer::AddPortHTTP") ;
   if (!OnHttpReq)
   {
       hzerr(E_ARGUMENT, "Each listening HTTP port must have a 'HandleHttpEvent' handler") ;
       return E_ARGUMENT ;
   }
   if (nPort < 1|| nPort > 65535)
   {
       hzerr(E_RANGE, "Port %d out of range", nPort) ;
       return E_INITDUP ;
   }
   hzList<hzIpListen*>::Iter   I ;     //  Listening socket iterator
   hzIpListen* pLS ;           //  Listening socket
   uint32_t    opflags ;       //  Operational flags
   //  Check that we are not already using port
   for (I = m_LS ; I.Valid() ; I++)
   {
       pLS = I.Element() ;
       if (pLS->GetPort() == nPort)
           return hzerr(E_INITDUP, "Socket already initialized and listening on port %d\n", pLS->GetPort()) ;
   }
   if (!(pLS = new hzIpListen(m_pLog)))
       return hzerr(E_MEMORY, "SERIOUS ERROR - Could not allocate an LS for server") ;
   opflags = HZ_LISTEN_HTTP ;
   if (bSecure)
       opflags |= HZ_LISTEN_SECURE ;
   if (pLS->InitINET(this, HandleHttpMsg, 0,0,nTimeout, nPort, nMaxClients, opflags) != E_OK)
       return hzerr(E_INITFAIL, "SERIOUS ERROR - Could not initialize an LS for server") ;
   pLS->m_appFn = (void*) OnHttpReq ;
   if (m_LS.Add(pLS) != E_OK)
       return hzerr(E_INITFAIL, "SERIOUS ERROR - Could not insert an LS for server") ;
   return E_OK ;
}