title: Socket Blocking and Timeout on Select
body: <p>I am currently creating an echo server that disconnects clients after a maxWaitTime of being in idle.</p>
  
  <p>I was hoping the program would block the socket until the client sent data but when I run the program in gdb it goes through the select and blocks on Readline.</p>
  
  <p>I know retval = 0 whenever it goes through the select and that the fd_set sock goes to [256, (31 zeroes)] and after the select, sock goes to [32 zeroes].</p>
  
  <p>The accepting of the connection happens in another function and the connection descriptor is passed to the echo function.</p>
  
  <p>If you are able to help point me in the right direction or let me know how I can disconnect a client after a certain amount of time please let me know.</p>
  
  <p>If you require any further information please let me know.</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>    FD_ZERO(&amp;sock);
      FD_SET(sockfd,&amp;sock);
  
      int opt = 3;
  
      setsockopt(sockfd, SOL_SOCKET, SO_RCVLOWAT,&amp;opt,sizeof(opt));
  
      timeout.tv_sec = maxWaitTime;
      timeout.tv_usec = 0;
  
      for ( ; ; ) {
              FD_SET(sockfd,&amp;sock);
  
              printf("Set is %d\n",FD_ISSET(sockfd,&amp;sock));
  
              int retval;
              retval = select(1, &amp;sock, NULL, NULL, &amp;timeout);
  
              if(retval)
              {
                      quitProgram(number);
              }
              else
              {
              printf("n is %d\n",retval);
  
              if ( (n = Readline(sockfd, line, MAXLINE)) == 0)
              {
                      return;         /* connection closed by other end */
              }
  
              Writen(sockfd, line, n);
  
      }
  </code></pre>
  
  <p>`</p>