/* Receives data from the TCP/IP server in a blocking manner.  */
bool NetAccessReceive(uint8_t *data, uint32_t *length, uint32_t timeout)
/* Receives data from the TCP/IP server in a blocking manner.  */
bool NetAccessReceive(uint8_t *data, uint32_t *length, uint32_t timeout)
{
  bool result = false;
  struct timeval tv;
  ssize_t receivedLen;
  assert(data != NULL);
  assert(length != NULL);
  assert(timeout > 0);
  if ( (data != NULL) && (length != NULL) && (timeout > 0) )
  {
    if (netAccessSocket >= 0)
    {
      tv.tv_sec = (__time_t)(timeout / 1000u);
      tv.tv_usec = (timeout % 1000u) * 1000u;
      if (setsockopt(netAccessSocket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof(struct timeval)) >= 0)
      {
        receivedLen = recv(netAccessSocket, data, *length, 0);
        if (receivedLen > 0)
        {
          *length = (uint32_t)receivedLen;
          result = true;
        }
      }
    }
  }
  return result;
}