Send a response to the client as a separate header and message body. This approach means a cost of two partial IP packets instead of one, but it saves having to concatenate the two chains which is a heavy copying operation. Note that this function should always be called by applications rather than writing to the client socket directly as this ensures proper multiplexing between clients.

Return TypeFunction nameArguments
hzEcodehzIpConnex::SendData(hzChain&,hzChain&,)

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

Function Logic:

0:START 1:unknown 2:items 3:Return E_NODATA 4:unknown 5:items items Hdr 6:m_nTotalOut m_nsSendBeg epEventNew EPOLLOUT EPOLLIN epEventNew 7:unknown 8:items 9:unknown 10:items 11:Return E_OK

Function body:

hzEcode hzIpConnex::SendData (hzChain& Hdr)hzChain& Body, 
{
   //  Send a response to the client as a separate header and message body. This approach means a cost of two partial IP packets instead of one, but
   //  it saves having to concatenate the two chains which is a heavy copying operation.
   //  
   //  Note that this function should always be called by applications rather than writing to the client socket directly as this ensures proper multiplexing
   //  between clients.
   //  
   //  Arguments: 1) Hdr  Header of outgoing response
   //     2) Body Body of outgoing response
   //  
   //  Returns: E_OK if hzChain is accepted for the response,
   //     False otherwise.
   _hzfunc("hzIpConnex::SendData(1)") ;
   struct epoll_event  epEventNew ;        //  Epoll event for new connections
   if (!Hdr.Size() && !Body.Size())
   {
       m_pLog->Log("No data queued for output\n") ;
       return E_NODATA ;
   }
   if (Hdr.Size() && Body.Size())
   {
       m_Outgoing.Push(Hdr) ;
       m_Outgoing.Push(Body) ;
   }
   m_nTotalOut = Hdr.Size() + Body.Size() ;
   m_nsSendBeg = RealtimeNano() ;
   epEventNew.data.fd = m_nSock ;
   epEventNew.events = EPOLLIN | EPOLLOUT | EPOLLET ;
   if (epoll_ctl(s_pTheOneAndOnlyServer->s_epollSocket, EPOLL_CTL_MOD, m_nSock, &epEventNew) < 0)
   {
       m_pLog->Log("EPOLL ERROR: Could not add client connection write handler on sock %d/%d. Error=%s\n", m_nSock, m_nPort, strerror(errno)) ;
       if (close(m_nSock) < 0)
           m_pLog->Log("NOTE: Could not close socket %d after epoll error. errno=%d\n", m_nSock, errno) ;
   }
   return E_OK ;
}