in source/core_sntp_client.c [560:608]
static SntpStatus_t receiveSntpResponse( const UdpTransportInterface_t * pTransportIntf,
uint32_t timeServer,
uint16_t serverPort,
uint8_t * pBuffer,
uint16_t responseSize )
{
SntpStatus_t status = SntpNoResponseReceived;
int32_t bytesRead = 0;
assert( pTransportIntf != NULL );
assert( pTransportIntf->recvFrom != NULL );
assert( pBuffer != NULL );
assert( responseSize >= SNTP_PACKET_BASE_SIZE );
bytesRead = pTransportIntf->recvFrom( pTransportIntf->pUserContext,
timeServer,
serverPort,
pBuffer,
responseSize );
/* Negative return code indicates error. */
if( bytesRead < 0 )
{
status = SntpErrorNetworkFailure;
LogError( ( "Unable to receive server response: Transport receive failed: Code=%ld",
( long int ) bytesRead ) );
}
/* If the packet was not available on the network, check whether we can retry. */
else if( bytesRead == 0 )
{
status = SntpNoResponseReceived;
}
/* Partial reads are not supported by UDP, which only supports receiving the entire datagram as a whole.
* Thus, if the transport receive function returns reception of partial data, it will be treated as failure. */
else if( bytesRead != ( int32_t ) responseSize )
{
LogError( ( "Failed to receive server response: Transport recv returned less than expected bytes."
"ExpectedBytes=%u, ReadBytes=%ld", responseSize, ( long int ) bytesRead ) );
status = SntpErrorNetworkFailure;
}
else
{
LogDebug( ( "Received server response: PacketSize=%ld", ( long int ) bytesRead ) );
status = SntpSuccess;
}
return status;
}