We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 367

Summary: Socket returned by accept is non-blocking on some OSes
Product: SDL_net Reporter: Joakim L. Gilje <jgilje>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: adeason, jgilje
Version: unspecified   
Hardware: All   
OS: Solaris   

Description Joakim L. Gilje 2006-11-18 16:22:55 UTC
After noticing server-side problems with TCP-communication on Solaris, IRIX and MacOS X, I modified the function SDLNet_TCP_Accept in SDLnetTCP.c to print whether or not the socket returned by accept is blocking using the code below:

int currentMode = fcntl(sock->channel, F_GETFL, 0);
printf("%d\n", currentMode & O_NONBLOCK);

When executed, printf printed non-zero values. When tested under Linux, printf printed 0. So apparently the socket returned by accept is a blocking or non-blocking socket depending on the operating system.

I fixed this by forcing the socket returned to block using the code below:

int currentMode = fcntl(sock->channel, F_GETFL, 0);
fcntl(sock->channel, F_SETFL, currentMode & ~O_NONBLOCK);

I suggest forcing the socket returned by accept to block on all UNIX-platforms, as it will not make a difference on other operating systems like Linux where accept returns a blocking socket anyway.
Comment 1 Ryan C. Gordon 2007-07-03 03:21:10 UTC
*** Bug 381 has been marked as a duplicate of this bug. ***
Comment 2 Sam Lantinga 2007-07-14 22:56:06 UTC
This is fixed in subversion revision 3280, thanks!