Read a packet from the socket into the client buffer.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzUdpClient::RecvPkt | (hzPacket*,uint32_t&,) |
Declared in file: hzUdpClient.h
Defined in file : hzUdpClient.cpp
Function Logic:
Function body:
hzEcode hzUdpClient::RecvPkt (hzPacket* pData)uint32_t& nRecv,
{
// Read a packet from the socket into the client buffer.
//
// Arguments: 1) pData The packet recepticle
// 2) nRecv Reference to number of bytes received
//
// Returns: E_ARGUMENT If the packet recipticle is not supplied
// E_NOSOCKET If the connection has been closed
// E_NODATA If no data was recieved
// E_RECVFAIL If the socket read operation fails
// E_OK If operation successfull
_hzfunc("hzUdpClient::Recv(buf,recv,max)") ;
if (!pData)
{
hzerr(E_ARGUMENT, "No IP recepticle supplied") ;
return E_ARGUMENT ;
}
if (m_nSock == 0)
{
hzerr(E_NOSOCKET, "Client has no connection") ;
return E_NOSOCKET ;
}
// Get response
// nRecv = recvfrom(m_nSock, pData->m_data, HZ_MAXPACKET, 0, (struct sockaddr*) &m_SvrAddr, &m_SvrLen) ;
nRecv = recvfrom(m_nSock, pData->m_data, HZ_MAXPACKET, 0,(SOCKADDR*) &m_SvrAddr, &m_SvrLen) ;
if (nRecv == 0)
return E_NODATA ;
if (nRecv < 0)
{
close(m_nSock) ;
m_nSock = 0;
hzerr(E_RECVFAIL, "Could not recv from server (%s) on port %d", *m_Hostname, m_nPort) ;
return E_RECVFAIL ;
}
pData->m_data[nRecv] = 0;
threadLog("Client sock %d recv %d bytes\n", m_nSock, nRecv) ;
return E_OK ;
}