title: Sockets & File Descriptor Reuse (or lack thereof)
body: <p>I am getting the error "Too many open files" after the call to socket in the server code below. This code is called repeatedly, and it only occurs just after server_SD gets the value 1022. so i am assuming that i am hitting the limit of 1024 as proscribed by "ulimit -n". What i don't understand is that i am closing the Socket, which should make the fd reusable, but this seems not to be happening. </p>
  
  <p>Notes: Using linux, and yes the client is closed also, no i am not a root user so moving the limits is not an option, I should have a maximum of 20 (or so) sockets open at one time. Over the lifetime of my program i would expect to open &amp; close close to 1000000 sockets (hence need to reuse very strong).</p>
  
  <pre><code>  server_SD = socket (AF_INET, SOCK_STREAM, 0);  
    bind (server_SD, (struct sockaddr *) &amp;server_address, server_len)  
    listen (server_SD,1)  
    client_SD = accept (server_SD, (struct sockaddr *)&amp;client_address, &amp;client_len)  
    // read, write etc...   
    shutdown (server_SD, 2);  
    close (server_SD)
  </code></pre>
  
  <p>Does anyone know how to guarantee closure &amp; re-usability ?</p>
  
  <p>Thanks.</p>