On 2019-06-27 17:04, Daniel Stenberg wrote:
> On Thu, 27 Jun 2019, Robert NEMKIN via curl-library wrote:
>
>> I don't know if setsockopt bind address is thread-safe?
>
> Assuming you speak of Linux, I certainly presume bind() is thread-safe.

Debian Buster.

Hope I'm right, but bind() is for server/receiving sockets.
I want to bind to a specific interface as client socket.

I use curl_easy_setopt(curl, CURLOPT_INTERFACE, interface) to bind to a specific interface. I guess, that I set up the options in libcurl, then when I issue curl_easy_perform(curl), it does all the work to set up the socket and do the transfer.

> But your way of saying this makes me curious. Why do you call it
> setsockopt bind address? Where exactly does it hang? And for how long?

I know, that setsockopt is thread safe according to the POSIX standard. But is the linux kernel (4.19.37-5) implementation correct? Sometimes it took more than a minute to start the transfer, sometimes it never starts.

>
>> Maybe I can use some workaround? E.g. download a little testfile
>> sequential to do the bindaddress serialized with keepalive, then start
>> the multithreaded download?
>
> You could add one transfer at a time and only start the next once the
> previous has started to get data as then you know they don't do bind()
> at the same time. But I wouldn't feel entirely safe with that since then
> we don't know for sure where the problem is or that this is actually a
> working fix or just accidentally working...
>

I guess it's a kernel problem, because if I start four wget from commandline, it locks too.
Example:

wget --bind-address=x.y.z.p -O /dev/null -q http://server1.domain/testfile & wget --bind-address=x.y.z.p -O /dev/null -q http://server2.domain/testfile & wget --bind-address=x.y.z.p -O /dev/null -q http://server3.domain/testfile & wget --bind-address=x.y.z.p -O /dev/null -q http://server4.domain/testfile &

I need a fix in short term. If I'm right and the kernel implementation has a bug, it would took more time to resolve it. To transfer two files per connectin is my newest idea, I don't know if it's working or not.

My guess is that the kernel is fast enough to do the setsockopt in case of 1-2 ethernet cards, so the bug remains hidden. Maybe I'm the first who installed 18 cards in one machine, and tested it for this usage.

Robert
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html

Reply via email to