cURL / Mailing Lists / curl-library / Single Mail


holding HTTP socket open for a long time

From: Mohun Biswas <>
Date: Wed, 29 Jul 2009 13:20:29 -0400

Let me start by explaining a bit about how my app works. During the
initialization phase it makes a small number of HTTP connections to the
server to do things like logging in and starting a session. This is done
synchronously using a single curl easy handle. Then we get into the main
part where files are uploaded over a period of time (which could be many
hours) using the multi API for performance reasons. Then, just before
finishing a last round trip is made, using the original easy handle, to
finalize server state.

Left to its own devices, libcurl prefers to keep socket connections
open, which - given the above design - would result in the socket
associated with the initialization handle being kept open for the entire
run. Is this a problem? Is there a chance something could time out and
close the socket causing my app to fail? I don't see anything in TFM
about this so for now I'm being a wimp and setting CURLOPT_FORBID_REUSE
after initialization, thus forcing a reconnect at finish time. I guess
at the very least a file descriptor is freed up by doing it this way
(probably not important). But will libcurl silently re-establish the
socket connection if lost?

The overhead is only a small constant, and probably not critical, but
I'd like to do the elegant thing, whatever that is.

Received on 2009-07-29