Hello all,
After quite some debugging, I found the trouble with the Win32 socket
extension. I hope someone will implement the fix because I don’t know
how to send a patch (and I’m lazy )
In win32/win32.c, there are a lot of lines like this:
RUBY_CRITICAL(r = recv (TO_SOCKET(s), buf, len, flags));
if (r == SOCKET_ERROR)
errno = WSAGetLastError();
The problem lies in RUBY_CRITICAL. Code is being executed at the end
of this macro that for some reason sets the value returned by
WSAGetLastError to 0 (or it sets another error value, whatever.)
Solution: include the errorhandling in RUBY_CRITICAL, which is more
threadsafe too:
RUBY_CRITICAL(
r = recv (TO_SOCKET(s), buf, len, flags);
if (r == SOCKET_ERROR)
errno = WSAGetLastError();
);
The thing that broke sockets in the first place is probably hidden in
rb_w32_leave_critical, but the code there scares me.