SDLNet_TCP_Accept non-blocking contract for cross-platform servers
0 reputation · 09 Aug 2021, 14:27 UTC
SDLNet_TCP_Accept non-blocking contract for cross-platform servers
SDL_net 2.0 specifies that SDLNet_TCP_Accept() should return NULL and set errno to EWOULDBLOCK when the listening socket is placed in non-blocking mode via SDLNet_TCP_SetNonblocking(). However, the implementation varies across Windows, Linux, and macOS: some platforms return immediately, while others block until a connection is ready. This divergence creates uncertainty for applications that require predictable, event-driven socket handling without busy-waiting.
The unresolved decision is whether SDL_net should enforce a single non-blocking contract across all supported operating systems, or whether platform-specific fallback logic is an acceptable design trade-off. Without a definitive answer, developers must choose between defensive polling and accepting inconsistent latency.
Should SDLNet_TCP_Accept() be standardized to never block on non-blocking sockets? Is the current platform-specific behavior an intentional design choice or an implementation gap? What minimal test can confirm the actual behavior for a given SDL_net 2.0 build?