title: Close connection with client after inactivty period
body: <p>I'm currently managing a server that can serve at most MAX_CLIENTS clients concurrently.</p>
  <p>This is the code I've written so far:</p>
  <pre><code>//create and bind listen_socket_
  
  struct pollfd poll_fds_[MAX_CLIENTS];
  
  for (auto&amp; poll_fd: poll_fds_)
  {
      poll_fd.fd = -1;
  }
  
  listen(listen_socket_, MAX_CLIENTS);
  
  poll_fds_[0].fd = listen_socket_;
  poll_fds_[0].events = POLLIN;
  
  while (enabled)
      {
          const int result = poll(poll_fds_, MAX_CLIENTS, DEFAULT_TIMEOUT);
  
          if (result == 0)
          {
              continue;
          }
          else if (result &lt; 0)
          {
              // throw error
          }
          else
          {
              for (auto&amp; poll_fd: poll_fds_)
              {
                  if (poll_fd.revents == 0)
                  {
                      continue;
                  }
                  else if (poll_fd.revents != POLLIN)
                  {
                      // throw error
                  }
                  else if (poll_fd.fd == listen_socket_)
                  {
                      int new_socket = accept(listen_socket_, nullptr, nullptr);
  
                      if (new_socket &lt; 0)
                      {
                          // throw error
                      }
                      else
                      {
  
                          for (auto&amp; poll_fd: poll_fds_)
                          {
                              if (poll_fd.fd == -1)
                              {
                                  poll_fd.fd = new_socket;
                                  poll_fd.events = POLLIN;
                                  break;
                              }
                          }
                      }
                  }
                  else
                  {
                      // serve connection
                  }
              }
          }
      }
  </code></pre>
  <p>Everything is working great, and when a client closes the socket on its side, everything gets handled well.</p>
  <p>The problem I'm facing is that when a client connects and send a requests, if it does not close the socket on its side afterwards, I do not detect it and leave that socket &quot;busy&quot;.</p>
  <p>Is there any way to implement a system to detect if nothing is received on a socket after a certain time? In that way I could free that connection on the server side, leaving room for new clients.</p>
  <p>Thanks in advance.</p>