[PATCH] SDL_Net socket blocking on O_NONBLOCK systems

Greetings. This is about SDL_Net, but there’s no SDL_Net mailing list
(or -dev mailing list that I can see), so I’m sending this here. My
apologies if this is not the correct place.

In SDL_Net (specifically SDLnetTCP.c), sock->channel is set to
O_NONBLOCK for accept() on systems that support O_NONBLOCK. However,
when we’re done with accept() and just normal traffic is going across,
the socket is not reset to blocking I/O on O_NONBLOCK systems. This
seems odd, since SDLNet_TCP_Send and friends do block on Linux. There
is also Windows-only code to set the socket back to block after the
accept() call, but it appears to make no such attempt on any other OS.

This causes a problem on FreeBSD, where SDLNet_TCP_Recv errs with
EAGAIN immediately, suggesting nonblocking behavior. On every other OS
I’ve tried, though, SDLNet_TCP_Recv just blocks until it receives data.
The attached patch against svn makes the SDLNet_TCP_* functions act as
blocking functions, on Linux and FreeBSD (and it seems to work on
NetBSD, OpenBSD, and DragonFlyBSD).

Someone please correct me if I’m missing something here, since I’m not
really sure how this would have gone unnoticed for so long… And
shouldn’t it set the socket back to blocking mode for BeOS and OS/2
(and others?) as well? Why is Windows the only OS where this sets the
socket to block after accept()?–
Andrew Deason
@Andrew_Deason
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdlnet-tcp-socket-block.patch
Type: text/x-diff
Size: 465 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20061226/7caa59da/attachment.patch