Block on multiple sockets until at least one has data available.
Defined in <SDL3_net/SDL_net.h>
int SDLNet_WaitUntilInputAvailable(void **vsockets, int numsockets, Sint32 timeout);
void ** | vsockets | an array of pointers to various objects that can be waited on, each cast to a void pointer. |
int | numsockets | the number of pointers in the vsockets array. |
Sint32 | timeout | Number of milliseconds to wait for new input to become available. -1 to wait indefinitely, 0 to check once without waiting. |
(int) Returns the number of items that have new input, or -1 on error.
This is a complex function that most apps won't need, but it could be used to implement a more efficient server or i/o thread in some cases.
This allows you to give it a list of objects and wait for new input to become available on any of them. The calling thread is put to sleep until such a time.
The following things can be specified in the vsockets
array, cast to void *
:
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.
This returns the number of items that have new input, but it does not tell you which ones; since access to them is non-blocking, you can just try to read from each of them and see which are ready. If nothing is ready and the timeout is reached, this returns zero. On error, this returns -1.
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 sockets at the same time without problems.
This function is available since SDL_Net 3.0.0.