title: libwebsockets for C, can i use websocket file descriptor with select()?
body: <p>I am coding with <code>libwebsockets</code> for client which is websocket library for C.</p>
  
  <p>And i want to use websocket file descriptor with <code>select()</code> so that i can handle websocket while handling other events.</p>
  
  <p>and then only if websocket got an event, i can call <code>libwebsocket_service();</code> to handle websocket event.</p>
  
  <p>So i tried below steps.</p>
  
  <ol>
  <li><p>Connect websocket through <code>struct libwebsocket *wsi = libwebsocket_client_connect(..)</code>
  I did also check if the reture value is NULL or not for error.</p></li>
  <li><p>Get file descriptor through int <code>fd = libwebsocket_get_socket_fd(wsi);</code></p></li>
  <li><p><code>FD_SET(fd, &amp;readFd);</code> and <code>select(maxFd + 1, &amp;readFd, NULL, NULL, NULL);</code></p></li>
  </ol>
  
  <p>But it keeps being blocked, though i think it must be wake up since server send message after connection is completed.</p>
  
  <p><strong>---EDIT----</strong></p>
  
  <p>After more testing.</p>
  
  <p>It seems because select() is called before connection is completed.
  It means before handling LWS_CALLBACK_CLIENT_ESTABLISHED.</p>
  
  <p>I put <code>libwebsocket_service()</code> one more between <code>libwebsocket_client_connect()</code> and <code>select()</code>, so that it can handle <code>LWS_CALLBACK_CLIENT_ESTABLISHED</code> before calling <code>select()</code>.</p>
  
  <p>And then it works with select() when it receive some message from server.</p>
  
  <p>It means socket is normally open after handling <code>LWS_CALLBACK_CLIENT_ESTABLISHED</code>?</p>