Purpose: Read from a socket into a buffer.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzTcpClient::Recv | (void*,uint32_t&,uint32_t,) |
Declared in file: hzTcpClient.h
Defined in file : hzTcpClient.cpp
Function Logic:
Function body:
hzEcode hzTcpClient::Recv (void* vpOut)uint32_t& nRecv, uint32_t nMax,
{
// Purpose: Read from a socket into a buffer.
//
// Arguments: 1) vpOut The buffer to populate
// 2) nRecv A reference to number of bytes received
// 3) nMax The maximum number of bytes to receive
//
// Returns: E_NOSOCKET If the connection has been closed
// E_RECVFAIL If the socket read operation fails
// E_OK If operation successfull
_hzfunc("hzTcpClient::Recv(1)") ;
char* cpOut ; // Buffer recast to char*
int32_t nBytes ; // Bytes recieved in socket read
cpOut = (char*) vpOut ;
cpOut[0]= 0;
nRecv = 0;
if (!m_nSock)
return E_NOSOCKET ;
if (nMax == 0)
return E_OK ;
if (m_pSSL)
nBytes = SSL_read(m_pSSL, cpOut, nMax) ;
else
nBytes = recv(m_nSock, cpOut, nMax, 0);
if (nBytes < 0)
{
if (errno == EAGAIN) return E_OK ;
if (errno == ETIMEDOUT) return E_TIMEOUT ;
// Close() ;
return E_RECVFAIL ;
}
nRecv = nBytes ;
return E_OK ;
}