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.

Return TypeFunction nameArguments
hzEcodehzIpServer::AddPortUDP(hzTcpCode(*)(hzChain&,hzIpConnex*),hzTcpCode(*)(hzIpConnex*),hzTcpCode(*)(hzIpConnex*),uint32_t,uint32_t,uint32_t,bool,)

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

Function Logic:

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

Function body:

hzEcode hzIpServer::AddPortUDP (hzTcpCode(*)(hzChain&,hzIpConnex*) OnIngress)hzTcpCode(*)(hzIpConnex*) OnConnect, hzTcpCode(*)(hzIpConnex*) OnDisconn, uint32_t nTimeout, uint32_t nPort, uint32_t nMaxClients, bool bSecure, 
{
   //  Category: Internet Server
   //  
   //  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.
   //  
   //  Arguments: 1) OnIngress  Application Specific 'Do Something' function to be called each time data has come in from a connected client.
   //     2) OnConnect  Application Specific 'Server Hello' function - only required if the protocol used dictates that the server
   //          speaks first.
   //     3) nTimeout  Timeout for connections to the port in seconds
   //     4) nPort   Listening port number
   //     5) nMaxClients  Max number of connections on the port (before server blocks listening socket)
   //     6) bSecure   Flag to indicate SSL
   //  
   //  Returns: E_ARGUMENT If the 'OnIngress' 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::AddUdpPort") ;
   if (!OnIngress)
       return hzerr(E_ARGUMENT, "Each listening port must have a 'OnIngress' handler") ;
   if (nPort < 1|| nPort > 65535)
   {
       hzerr(E_RANGE, "Port %d out of range", nPort) ;
       return E_RANGE ;
   }
   //  Check that we are not already using port
   hzList<hzIpListen*>::Iter   I ;     //  Listening socket iterator
   hzIpListen* pLS ;           //  Listening socket
   uint32_t    opflags ;       //  Operational flags
   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)))
       hzexit(E_MEMORY, "SERIOUS ERROR - Could not allocate an LS for server") ;
   opflags = HZ_LISTEN_UDP ;
   if (bSecure)
       opflags |= HZ_LISTEN_SECURE ;
   if (pLS->InitINET(this, OnIngress, OnConnect, OnDisconn, nTimeout, nPort, nMaxClients, opflags) != E_OK)
       return hzerr(E_INITFAIL, "SERIOUS ERROR - Could not initialize an LS for server") ;
   if (m_LS.Add(pLS) != E_OK)
       return hzerr(E_INITFAIL, "SERIOUS ERROR - Could not insert an LS for server") ;
   return E_OK ;
}