I am using the read()
function to read data from a socket. But sometimes it will block and program will hang.
So, I have used the select()
function to make a timeout. But still I have some issue.
So, please tell me, how should I use both functions?
My code is as below:
do{
rv = select(n, &readfds, NULL, NULL, &tv);
#ifdef WIFI_DEBUG_PRINT
ESP_LOGI(Display, "\nselect returns= %d\n",rv);
#endif
if (rv > 0)
{
if (FD_ISSET(s, &readfds))
{
bzero(recv_buf, sizeof(recv_buf));
read(s, recv_buf, sizeof(recv_buf)-1);
strcat(response_buffer,recv_buf);
printf("\nrecv_buf= %s\n",recv_buf);
}
}
_delay_ms_kt(100); //https://esp32.com/viewtopic.php?f=2&t=809&p=10191&hilit=esp_task_wdt_feed#p10191
//see above link to understand reason to put delay here.
//https://github.com/espressif/arduino-esp32/issues/595
//same.....
}while(rv>0);