cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to explicitly close underlying TCP connection in libcurl

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 25 Mar 2011 16:12:13 +0100 (CET)

On Fri, 25 Mar 2011, ajil koshy wrote:

> I am writing an HTTPS client using libcurl/OpenSSL. The client is expected
> to periodically connect to the server, exchange data and close the
> connection i.e. not keep a persistent connection. What would be the best way
> to explicitly close the underlying TCP connection from the client side
> without having to close the libcurl handle? I want to keep the Libcurl
> handle alive in order to leverage the SSL session cache. I currently see two
> options.

Are you really really sure you want to force a close of the connection? If you
are to do another request within a reasonable time, it will be much less
strain on the resources if you can reuse the connection.

> a) Using undocumented function Curl_disconnect ()

That's not only undocumented, it is internal and would be a very unwise to
use.

> b) Limit CURLOPT_MAXCONNECTS to 1 and use CURL_OPT_CONNECT_ONLY: To
> disconnect, we can change the URL on the CURL handle and simply call call
> curl_easy_perform ().

Sorry, I don't see how that would have the desired effect.

> Do you think either of the above is a nice way (probably not :-) ) to do it?
> Can you suggest the right way to do this?

Set CURLOPT_FORBID_REUSE on the specific handle you don't want to re-use, as
it should make the connection get closed instead.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2011-03-25