sdlNetWaitUntilConnected function
Block until a stream socket has connected to a server.
The SDLNet_StreamSocket objects returned by SDLNet_CreateClient take time to do their work, so it is does so asynchronously instead of making your program wait an indefinite amount of time.
However, if you want your program to sleep until the connection is complete, you can call this function.
This function takes a timeout value, represented in milliseconds, of how long to wait for resolution to complete. Specifying a timeout of -1 instructs the library to wait indefinitely, and a timeout of 0 just checks the current status and returns immediately (and is functionally equivalent to calling SDLNet_GetConnectionStatus).
Connections can fail after some time (server took awhile to respond at all, and then refused the connection outright), so be sure to check the result of this function instead of assuming it worked!
Once a connection is successfully made, the socket may read data from, or write data to, the connected server.
If you don't want your program to block, you can call SDLNet_GetConnectionStatus() from time to time until you get a non-zero result.
\param sock The SDLNet_StreamSocket object to wait on. \param timeout Number of milliseconds to wait for resolution to complete. -1 to wait indefinitely, 0 to check once without waiting. \returns 1 if successfully connected, -1 if connection failed, 0 if still connecting (this function timed out without resolution); if -1, call SDL_GetError() for details.
\threadsafety You should not operate on the same socket from multiple threads at the same time without supplying a serialization mechanism. However, different threads may access different socket at the same time without problems.
\since This function is available since SDL_Net 3.0.0.
\sa SDLNet_GetConnectionStatus
extern SDL_DECLSPEC int SDLCALL SDLNet_WaitUntilConnected(SDLNet_StreamSocket *sock, Sint32 timeout)
Implementation
int sdlNetWaitUntilConnected(Pointer<SdlNetStreamSocket> sock, int timeout) {
final sdlNetWaitUntilConnectedLookupFunction = libSdl3Net.lookupFunction<
Int32 Function(Pointer<SdlNetStreamSocket> sock, Int32 timeout),
int Function(Pointer<SdlNetStreamSocket> sock,
int timeout)>('SDLNet_WaitUntilConnected');
return sdlNetWaitUntilConnectedLookupFunction(sock, timeout);
}