curl-library
Re: libcurl multi interface. Doubts about reusing connection and closing them
Date: Mon, 30 Oct 2017 16:55:15 +0100 (CET)
On Mon, 30 Oct 2017, Santiago Carot via curl-library wrote:
> I've got some doubts about how curl manages persisten connections and if
> there is some chance to close the underlaying TCP connection.
CURLOPT_FRESH_CONNECT and CURLOPT_FORBID_REUSE are there to allow applications
some control of connection reuse. Neither are after-the-fact though so once
the connection exists they can be used to explicitly close one off.
It is sometimes asked for, and I'm not against the general idea, but usually
the wish or request is based on the wrong notion or a misunderstanding of
HTTP. libcurl should already handle connection reuse (or not) by itself to
cover almost all use cases.
> Lets say, for example, I'm using the multi interface.
libcurl's connection reuse logic is independent of what interface you use. It
works the same no matter what.
> Whenever I need to make a request I add a new easy handler, all handlers I'm
> adding to the multi handler have the same URL. Will curL re-use an active
> TCP connection when possible?.
Yes
> If so, when the underlaying TCP socket will be close?.
In the extreme case: when you close down the multi handle. In the more common
case: when the server closes it or when the server tells us to close it after
use with HTTP headers.
> On the other hand, lets suppose that one of those requests results in a
> HTTP 500 error code response, will curl close the underlaying TCP socket?,
Nope. Why would it? A 500 HTTP response code is not a request for closing the
connection.
> if it does not, is there a way to explicitly tell curl to close the socket
> not to be re-used anymore depending of the response code received from the
> server?
There is not. But why would you want that? Are you saying you have a broken
HTTP server that won't accept another request on the connection after a 5xx
response?
You can make libcurl do this if you add a CURLOPT_HEADERFUNCTION and return
error back when a 5xx response is received.
-- / daniel.haxx.se ------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.htmlReceived on 2017-10-30