Purpose: Write buffer content to a socket

Return TypeFunction nameArguments
hzEcodehzTcpClient::Send(const void*,uint32_t,)

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

Function Logic:

0:START 1:unknown 2:Return E_NOSOCKET 3:unknown 4:Return E_OK 5:unknown 6:nSent 7:nSent 8:unknown 9:items 10:Return E_TIMEOUT 11:unknown 12:items items 13:Return E_WRITEFAIL 14:Return E_OK

Function body:

hzEcode hzTcpClient::Send (const void* pIn)uint32_t nLen, 
{
   //  Purpose: Write buffer content to a socket
   //  
   //  Arguments: 1) pIn  The buffer (void*)
   //     2) nLen Number of bytes to send
   //  
   //  Returns: E_NOSOCKET If the connection is not open
   //     E_WRITEFAIL If the number of bytes written falls short of the intended number. In this event the connection is closed.
   //     E_OK  If the operation is successfull.
   _hzfunc("hzTcpClient::Send(void*,uint32_t)") ;
   uint32_t    nSent ;     //  Bytes actually sent
   if (!m_nSock)   return E_NOSOCKET ;
   if (nLen == 0)  return E_OK ;
   if (m_pSSL)
       //  nSent = SSL_write(m_pSSL, (const char*) pIn, nLen) ;
       nSent = SSL_write(m_pSSL, pIn, nLen) ;
   else
       //  nSent = write(m_nSock, (const char*) pIn, nLen) ;
       nSent = write(m_nSock, pIn, nLen) ;
   if (nSent == 0)
   {
       threadLog("Socket timed out while writing to server %s port %d socket %d", *m_Hostname, m_nPort, m_nSock) ;
       return E_TIMEOUT ;
   }
   if (nSent != nLen)
   {
       Close() ;
       threadLog("Socket write error to server %s port %d socket %d", *m_Hostname, m_nPort, m_nSock) ;
       return E_WRITEFAIL ;
   }
   return E_OK ;
}