sdlNetWaitUntilResolved function

int sdlNetWaitUntilResolved(
  1. Pointer<SdlNetAddress> address,
  2. int timeout
)

Block until an address is resolved.

The SDLNet_Address objects returned by SDLNet_ResolveHostname 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 address resolution 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_GetAddressStatus).

Resolution can fail after some time (DNS server took awhile to reply that the hostname isn't recognized, etc), so be sure to check the result of this function instead of assuming it worked!

Once an address is successfully resolved, it can be used to connect to the host represented by the address.

If you don't want your program to block, you can call SDLNet_GetAddressStatus from time to time until you get a non-zero result.

\param address The SDLNet_Address 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 resolved, -1 if resolution failed, 0 if still resolving (this function timed out without resolution); if -1, call SDL_GetError() for details.

\threadsafety It is safe to call this function from any thread, and several threads can block on the same address simultaneously.

\since This function is available since SDL_Net 3.0.0.

\sa SDLNet_GetAddressStatus

extern SDL_DECLSPEC int SDLCALL SDLNet_WaitUntilResolved(SDLNet_Address *address, Sint32 timeout)

Implementation

int sdlNetWaitUntilResolved(Pointer<SdlNetAddress> address, int timeout) {
  final sdlNetWaitUntilResolvedLookupFunction = libSdl3Net.lookupFunction<
      Int32 Function(Pointer<SdlNetAddress> address, Int32 timeout),
      int Function(Pointer<SdlNetAddress> address,
          int timeout)>('SDLNet_WaitUntilResolved');
  return sdlNetWaitUntilResolvedLookupFunction(address, timeout);
}