Write supplied chain content to a socket

Return TypeFunction nameArguments
hzEcodehzUdpClient::SendChain(hzChain&,)

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

Function Logic:

0:START 1:unknown 2:Return E_NOSOCKET 3:unknown 4:Return E_NODATA 5:ci nSofar 6:unknown 7:nSofar 8:unknown 9:items m_nSock items 10:Return E_SENDFAIL 11:unknown 12:unknown 13:nSofar 14:unknown 15:unknown 16:items m_nSock items 17:Return E_SENDFAIL 18:Return E_OK

Function body:

hzEcode hzUdpClient::SendChain (hzChain& C)
{
   //  Write supplied chain content to a socket
   //  
   //  Arguments: 1) C The chain to send. No size indicator is needed as whole chain is sent.
   //  
   //  Returns: E_NOSOCKET If the connection is not open
   //     E_NODATA If the supplied chain contains no data
   //     E_SENDFAIL If the send operation fails. In this event the connection is closed.
   //     E_OK  If the operation is successfull.
   _hzfunc("hzUdpClient::Send(hzChain&)") ;
   chIter      ci ;        //  To iterate input chain
   char*       i ;         //  To populate buffer
   uint32_t    nSend ;     //  Bytes in buffer to send
   uint32_t    nSofar ;    //  Bytes sent so far
   if (m_nSock == 0)
       return E_NOSOCKET ;
   if (!C.Size())
       return E_NODATA ;
   //  Init
   ci = C ;
   nSofar = 0;
   //  Read from chain to populate rest of buffer with start of message
   for (nSend = 0,i = m_pack.m_data ; !ci.eof() && nSend < HZ_MAXPACKET ; *i = *ci, i++, nSend++, ci++) ;
   nSofar = nSend ;
   //  Send buffer content to socket
   if (sendto(m_nSock, m_pack.m_data, nSend, 0,(struct sockaddr*) &m_SvrAddr, m_SvrLen) < 0)
   {
       close(m_nSock) ;
       m_nSock = 0;
       hzerr(E_SENDFAIL, "Could not send to host (%s) on port %d", *m_Hostname, m_nPort) ;
       return E_SENDFAIL ;
   }
   //  Repeat read and send steps for rest of message
   for (; nSofar < C.Size() ;)
   {
       for (nSend = 0,i = m_pack.m_data ; !ci.eof() && nSend < HZ_MAXPACKET ; *i = *ci, nSend++, i++, ci++) ;
       nSofar += nSend ;
       if (!nSend)
           break ;
       if (sendto(m_nSock, m_pack.m_data, nSend, 0,(struct sockaddr*) &m_SvrAddr, m_SvrLen) < 0)
       {
           close(m_nSock) ;
           m_nSock = 0;
           hzerr(E_SENDFAIL, "Could not send to host (%s) on port %d", *m_Hostname, m_nPort) ;
           return E_SENDFAIL ;
       }
   }
   return E_OK ;
}