curl-library
Re: OPENSOCKETFUNCTION hook not called for all socket creations on Windows
Date: Wed, 14 Dec 2011 19:54:12 +0000 (UTC)
Daniel Stenberg <daniel <at> haxx.se> writes:
> > 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.
>
> Yes, this is probably even the order in which these events happen most of the
> times. I think this is primarily a matter of improving the documentation to
> make it become less surprising.
IMHO that behavior can be worse than just surprising. Independent if libCurl
calls the CURLOPT_CLOSESOCKETFUNCTION or closes the socket itself. If the
CURLMOPT_SOCKETFUNCTION is called after closesocket it is possible that the same
file-descriptor is already reused for another socket (or something else).
Most of the time this shouldn't be a problem because normally only one thread
works with the curl-multi-handle and the application shouldn't care if the file-
descriptor is already invalid(or valid and pointing to something else). But
either way it is always a bad thing to call a function with a 'dangling' file-
descriptor. This might cause strange bugs is some place.
Do you think that problem is serious enough to think about a change in the
behavior(don't do anything with the socket after you called sclose).
A patch for that problem is not easy because it changes some of the internal
behavior of the multi-api which can always lead to side-effects. What do you
think?
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