title: Test the client socket is still alive in C
body: <p><code>client_sock_fd</code> is the file descriptor which returned from <code>accept()</code>, and here is my code in the server:</p>
  
  <pre><code>char buff[BUFFSIZE];
  FILE* rstream = fdopen(client_sock_fd, "r");
  
  if(rstream == NULL){
      perror("create read stream failure");
      pthread_exit(NULL);
  }
  
  /* how to exit block when client shutdown the socket */
  while(fscanf(rstream, "%s", buff) != EOF){
      printf("%s\n", buff);
  }
  
  fclose(rstream);
  close(client_sock_fd);
  </code></pre>
  
  <p>When I close the socket in the client or may some errors happen so that shutting the client socket down, but, in the server, it is blocked in <code>fscanf(rstream, "%s", buff) != EOF</code>, that means <code>fscanf()</code> is blocked and never return.</p>
  
  <p>My question is how to test the connection is still alive before execute the <code>fscanf()</code>?</p>