cURL / Mailing Lists / curl-library / Single Mail

curl-library

WSAEventSelect and curl_multi_socket_action

From: <tom_at_ashok-art.com>
Date: Fri, 23 Oct 2009 16:00:31 +0100

(Since I appear to be able to post to the mailing list now, I'll try again
with this question - I tried to post it a couple of times a few weeks ago
from another address, but it never got through. I eventually worked around
the problem, but I'm still curious...)

I'm using libcurl on Windows and I would like to do event-driven I/O
using the multi API and WSAEventSelect(). Mainly this is so that I can
have multiple transfers occuring in a worker thread and be able to
have the worker thread wake up when new transfers are added to the
queue as well as when curl is able to do transfers. Also, I need the
worker thread to respond to a shutdown event.

I've tried using the curl_multi_socket_action() API to achieve this,
but I've run into a problem. The WSAEventSelect documentation at
http://msdn.microsoft.com/en-us/library/ms741576(VS.85).aspx has this
to say about the FD_WRITE event:

      "The FD_WRITE network event is handled slightly differently. An
       FD_WRITE network event is recorded when a socket is first connected
       with connect/ WSAConnect or accepted with accept/ WSAAccept, and then
       after a send fails with WSAEWOULDBLOCK and buffer space becomes
       available. Therefore, an application can assume that sends are
       possible starting from the first FD_WRITE network event setting and
       lasting until a send returns WSAEWOULDBLOCK. After such a failure the
       application will find out that sends are again possible when an
       FD_WRITE network event is recorded and the associated event object is
       set."

Therefore, when curl_multi_socket_action returns and curl has
registered an interest in writing to a particular socket, my program
needs to know whether or not curl has just performed a send() call on
that socket and had a return code of WSAEWOULDBLOCK. If it has done
so, WSAEventSelect can be used. Otherwise, my program should
immediately call curl_multi_socket_action again. As far as I can see
there is no way I can tell which is the case.

Does anybody know if there is a solution for this, or is
WSAEventSelect unusable with the curl_multi_socket_action() API? If it
is unusable, does anybody know what the best way to run an
interruptable curl multi loop on a worker thread in Windows is? I
would be very grateful for any help.

Many thanks,
Tom

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-10-23