Search code examples
c++sdlsdl-2sdl-net

Timeout for SDLNet_TCP_Recv?


Is there any way to cancel a SDLNet_TCP_Recv call after some time when no answer arrives? Or are there alternatives to this function that support a timeout option?


Solution

  • Create a socket set with SDLNet_AllocSocketSet() & add your TCPsocket to it with SDLNet_AddSocket(). Then you can use SDLNet_CheckSockets() with a timeout to wait for network activity.

    Depending on the return-value you can then use SDLNet_SocketReady() to verify that the SDLNet_TCP_Recv() call won't block.