[SDL_net][PATCH] Fix nonblocking socket code for BeOS

Hi,

Congrats for all recent SDL* releases :slight_smile:
I thought that maybe You will want to release SDL_net too so i’m
re-sending patch (a bit modified/cleaner than the last one). It wasn’t
rejected or accepted before, and it seems it was lost in time (it was
almost a year ago, or so :).

Patch works for SDL_net 1.2.5 and for version in CVS (luckly line numbers
didn’t change :).

It fixes nonblocking socket code for BeOS. BeOS R5 has O_NONBLOCK, but it
doesn’t work for sockets, as (at least on R5) sockets != files.
This patch is needed to make TCP sockets work correctly (for example,
without it BeOS people wouldn’t be able to play Wesnoth game :).

Other BeOS networking versions (BONE, and BONE-based Zeta) keep setsockopt
for compatibility so all should work just fine. If You don’t want to use
setsockopt on BONE, there can be another defined() added, which should
work on both BONE and Zeta:

instead of line (after patch):

#if defined(BEOS) && defined(SO_NONBLOCK)

use

#if defined(BEOS) && defined(SO_NONBLOCK) && !defined(BONE_VERSION)

That should make BONE and Zeta networking use O_NONBLOCK.

THX
Regards
ahwayakchih
-------------- next part --------------
— SDL_net-1.2.5/SDLnetTCP.c- Sat Apr 13 16:50:37 2002
+++ SDL_net-1.2.5/SDLnetTCP.c Thu Dec 16 12:09:21 2004
@@ -755,11 +755,21 @@
SDLNet_SetError(“Couldn’t listen to local port”);
goto error_return;
}
-#ifdef O_NONBLOCK+
+#if defined(BEOS) && defined(SO_NONBLOCK)

  •   /*
    
  •   	On BeOS r5 there is O_NONBLOCK but it's for files only
    
  •   	(and socket != file on BeOS r5), so it doesn't work on sockets.
    
  •    */
    
  •   {
    
  •   	/* passing a non-zero value, socket mode set non-blocking */
    
  •   	long b = 1;
    
  •   	setsockopt(sock->channel, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
    
  •   }
    

+#elif defined(O_NONBLOCK)
/* Set the socket to non-blocking mode for accept() /
fcntl(sock->channel, F_SETFL, O_NONBLOCK);
-#else
-#ifdef WIN32
+#elif defined(WIN32)
{
/
passing a non-zero value, socket mode set non-blocking /
unsigned long mode = 1;
@@ -767,8 +777,7 @@
}
#else
#warning How do we set non-blocking mode on other operating systems?
-#endif /
WIN32 /
-#endif /
O_NONBLOCK */
+#endif

	sock->sflag = 1;
}