title: How can use select function to make unblock read function
body: <p>I am using the <code>read()</code> function to read data from a socket. But sometimes it will block and program will hang.</p>
  
  <p>So, I have used the <code>select()</code> function to make a timeout. But still I have some issue.</p>
  
  <p>So, please tell me, how should I use both functions?</p>
  
  <p>My code is as below:</p>
  
  <pre><code>do{
      rv = select(n, &amp;readfds, NULL, NULL, &amp;tv);
  
      #ifdef WIFI_DEBUG_PRINT
      ESP_LOGI(Display, "\nselect returns= %d\n",rv);
      #endif
  
      if (rv &gt; 0) 
      {
          if (FD_ISSET(s, &amp;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&amp;t=809&amp;p=10191&amp;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&gt;0);
  </code></pre>