cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: SO_REUSEADDR and libcurl

From: Sachin Nikumbh <sanikumbh_at_gmail.com>
Date: Mon, 30 Jun 2014 09:43:53 -0400

Hi Daniel,

Thanks a lot for the response. I am going to investigate the cause behind
sockets getting into the TIME_WAIT state. But in the mean time, I am trying
to understand how CURLOPT_SOCKOPTFUNCTION and CURLOPT_OPENSOCKETFUNCTION can
be used. I could not find any examples so, I am trying to understand their
functionality by following the documentation for these options and just
want to make sure that my understanding is correct. I was wondering if ou
could help me with this.
* given that I need to set the SO_REUSEADDR option after the socket is
created, I need to use the CURLOPT_SOCKOPTFUNCTION option
* curlsockettype in this case needs to be CURLSOCKTYPE_IPCXN
* the 2nd input to the callback, curl_socket_t is the socket handle which
needs to be used with setsockopt() function
* I am not sure what the first input, void*, is representing
* How are CURLOPT_SOCKOPTFUNCTION and CURLOPT_OPENSOCKETFUNCTION options
related? The description of the case when the callback needs to return 2
mentions CURLOPT_OPENSOCKETFUNCTION. Does it mean if I am setting
CURLOPT_SOCKOPTFUNCTION,
I also need to set the CURLOPT_OPENSOCKETFUNCTION handler as well?

Thanks
Sachin

On Fri, Jun 27, 2014 at 10:54 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Fri, 27 Jun 2014, Sachin Nikumbh wrote:
>
> Is there any way to set the SO_REUSEADDR socket option through the
>> libcurl API? My client application is spawning many threads which are
>> opening new connections with an application server. But soon the
>> application fails due to lack of available ports as most of them are in the
>> TIME_WAIT state.
>>
>
> Why do they end up in TIME_WAIT ?
>
>
> Based on some old threads found over the net, it was not possible at some
>> point.
>>
>
> What wasn't possible? Also, be careful about trusting specific information
> "found over the net" if it is about libcurl details and doesn't come from
> this mailing list or our documentation.
>
>
> I was wondering of there is any undocumented way of passing SO_REUSEADDR
>> option.
>>
>
> Several. CURLOPT_SOCKOPTFUNCTION and CURLOPT_OPENSOCKETFUNCTION are two
> obvious ways you can do it with. But I would also persue the reason for
> this situation in the first place and make sure there's nothing wrong that
> causes it to trigger as then doing socket options would only hide the
> symptom and not fix the real problem - if even that.
>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-06-30