Purpose: Write buffer content to a socket
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzTcpClient::Send | (const void*,uint32_t,) |
Declared in file: hzTcpClient.h
Defined in file : hzTcpClient.cpp
Function Logic:
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 ;
}