SDL_net WIN32 FIONBIO issue

When creating a server socket the SDL_net code sets FIONBIO on the socket, this is fine by me. The problem for me is that despite the Unix behavior of sockets being that they are blocking by default, all accepted socket connections from this listening socket seem to inherit the nonblocking behavior of their parent. Then when reading from the accepted socket programs recieve -1 error status returned. Now since the error status is always -1 the program cannot determine if there’s an error such as a disconnect or if there is an EAGAIN type error (would block in a blocking socket). So in WIN32 architecture I’ve had to set the FIONBIO to 0 on all accepted sockets in my program. Now obviously I would think you’d want this to happen in SDL_net and not in the program (due to the fact that the struct _TCPsocket is supposed to be opaque).

Another thing to do would be to expose a method to set the blocking mode on the socket, and also to return a different error status from reads and writes so that the EAGAIN error status can be determined.

I personally just need the accepted socket to be set to block. The other thing is just an idea for anyone who thinks they want it. I do hope SDL_net improves soon and obtains 100% compatibility on all 4 normally supported platforms.

If you would like I wouldn’t mind working on this from time to time, but I only have Linux, Win32, and perhaps BeOS. Macintosh support needs to be helped by others.

BTW it looks like the Macintosh version of this code has done this as well already…

here is a simple patch for SDL_net cvs that implements the fix for blocking IO on accepted sockets.

Index: SDLnetTCP.c===================================================================
RCS file: /cvs/SDL_net/SDLnetTCP.c,v
retrieving revision 1.5
diff -r1.5 SDLnetTCP.c
667a668,674

#ifdef WIN32
{
/* passing a zero value, socket mode set to block on /
unsigned long mode = 0;
ioctlsocket (sock->channel, FIONBIO, &mode);
}
#endif /
WIN32 */


-==-
Jon Atkins
http://jonatkins.org/

I may have had the wrong CVS before, but the patch is still needed. Is anyone maintaining this thing? Am I just wasting my time?
Anyways, here is the patch for the cvs at :pserver:guest at libsdl.org:/home/slouken/libsdl.org/cvs SDL_net:

Index: SDLnetTCP.c===================================================================
RCS file: /home/slouken/libsdl.org/cvs/SDL_net/SDLnetTCP.c,v
retrieving revision 1.6
diff -r1.6 SDLnetTCP.c
832a833,839

#ifdef WIN32
{
/* passing a zero value, socket mode set to block on /
unsigned long mode = 0;
ioctlsocket (sock->channel, FIONBIO, &mode);
}
#endif /
WIN32 */


-==-
Jon Atkins
http://jonatkins.org/