title: Can I force Apache 2.2 connection close from inside a C module?
body: <p>We'd like to have a more fine-grained control on the connections we serve in a C++ Apache 2.2 module (on CentOS 5).</p>
  
  <p>One of the connections needs to stay alive for a few multiple requests, so we set "KeepAlive" to "On" and set a short keep-alive period.</p>
  
  <p>But for every such connection we have a few more connections from the browser which we don't need to leave behind and instead want to force them to close after a single request.</p>
  
  <p>Some of these connections are on different ports (so we can distinguish them by port, since KeepAlive can be set per virtual host) and some request a different URL (so we can tell from the path and parameters that we don't want to leave them behind).</p>
  
  <p>Also for the one we <em>do</em> want to keep alive, we know that after a certain request we'd like to close it too.</p>
  
  <p>But so far the only way we found to "cancel" the keep-alive is to send a polite "Connection: close" header to the client. If the client is not well behaved, or malicious, then they can keep it open and waste our resources.</p>
  
  <p>Is there a way to tell Apache to close the connection from the server side? The documentation advises against just plain close(2) call on the socket since Apache needs to do some clean up before that's done. But is there some API or a trick to "override" the static "KeepAlive On" configuration dynamically (and convince Apache to call close(2))?</p>
  
  <p>Thanks.</p>