I created the following code to test the socket API in esp_iot_rtos_sdk.
Code: Select all
int ICACHE_FLASH_ATTR mqtt_esp_read(int my_socket, unsigned char* buffer, int len, int timeout_ms)
{
struct timeval tv;
fd_set fdset;
int rc = 0;
int rcvd = 0;
FD_ZERO(&fdset);
FD_SET(my_socket, &fdset);
tv.tv_sec = 0;
tv.tv_usec = timeout_ms * 1000;
rc = select(my_socket + 1, &fdset, 0, 0, &tv);
if ((rc > 0) && (FD_ISSET(my_socket, &fdset)))
{
rcvd = recv(my_socket, buffer, len, 0);
}
else
{
// select fail
return -1;
}
return rcvd;
}
The socket was created using
Code: Select all
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)
It seems that the timeout feature of select() is not functional. select() always returns in ~46us when no data is available to read.
Is there anything I did wrongly or it is not supported in the SDK?
Thanks
Baoshi