title: Reusing Client TCP Connection for HTTP
body: <p>Why can't I reuse a http client socket in a C web client, since I don't call <code>close(http_socket_fd)</code>? The first write/read to the socket file descriptor works perfectly well. Any/all successive reads return zero (hardly any error).</p>
  
  <p>Basically, I don't want to keep recreating new client connection sockets to the same host for successive requests. Is it not possible in C to reuse an open client socket (which already has HTTP keep-alive enabled) for successive read/writes? It seems possible with Java <a href="http://www.mail-archive.com/httpclient-dev@jakarta.apache.org/msg04687.html" rel="nofollow">http://www.mail-archive.com/httpclient-dev@jakarta.apache.org/msg04687.html</a></p>
  
  <pre><code>Example: (PSEUDO_CODE)
  MANY_DOMAINS=30,000;
  //initial connection
  do{
    http_socket_to_domain_x=open(NEW_TCP_SOCKET_PER_DOMAIN);
    get(initial_url_path);
    read(http_socket_to_domain_x,initial_http_response);
  } while(EACH_DOMAIN)
  for(LIST_OF_URLS FROM EACH_DOMAIN);
    //successive connections - NO RECREATING TCP SOCKET!
  do{
    get(another_url_path);
    read(http_socket_to_domain_x,another_http_response);
  } while(EACH_URL_PER_DOMAIN)
  //finally
  close(http_socket_to_domain_x);
  </code></pre>