cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: OPENSOCKETFUNCTION hook not called for all socket creations on Windows

From: Christian Hägele <haegele_at_teamviewer.com>
Date: Wed, 14 Dec 2011 13:27:15 +0000 (UTC)

Poul Thomas Lomholt <pt <at> lomholt.com> writes:

> Hi, on Windows, libcurl does not seem to honor the CURLOPT_OPENSOCKETFUNCTION
> hook for the 'dummy_sock' socket created in init_resolve_thread() function.
> This socket is then later presented to the CURLMOPT_SOCKETFUNCTION callback,
> but not having been created via the OPENSOCKETFUNCTION callback causes me
> some headache. I am assuming the same problem exists for
> the CURLOPT_CLOSESOCKETFUNCTION counterpart. This was using libcurl 7.23.0
> but the problem seems to exist also in 7.23.1 based on inspection of the
> latest version of asyn-thread.c. Bug?

I had the same issue reported earlier.(http://thread.gmane.org/
gmane.comp.web.curl.library/33280)

I am using boost::asio to manage the sockets and events on the sockets. My
workaround for this issue is to keep track of all sockets I opened myself via
the CURLOPT_OPENSOCKETFUNCTION and if CURLMOPT_SOCKETFUNCTION gets called with
a unknown socket I just ignore it.

Be careful for another issue, though. (http://thread.gmane.org/
gmane.comp.web.curl.library/31909):
It is possible that CURLOPT_CLOSESOCKETFUNCTION gets called and after that the
CURLMOPT_SOCKETFUNCTION gets called with the socket you closed just before and
the CURL_POLL_REMOVE action is set. That can be tricky and the only solution I
could think of is to wait with closesocket until the
CURLOPT_CLOSESOCKETFUNCTION was called AND you got the CURL_POLL_REMOVE action
for that socket.

In my opinion these two issues are very confusing. Maybe it should be
considered to extend the documentation or to change the behavior to be more
like a user expects it.

Regards,

Christian

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