sdlNetWaitUntilInputAvailable function
- Pointer<
Pointer< vsockets,NativeType> > - int numsockets,
- int timeout
Block on multiple sockets until at least one has data available.
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 *
:
- SDLNet_Server (reports new input when a connection is ready to be accepted with SDLNet_AcceptClient())
- SDLNet_StreamSocket (reports new input when the remote end has sent more bytes of data to be read with SDLNet_ReadFromStreamSocket).
- SDLNet_DatagramSocket (reports new input when a new packet arrives that can be read with SDLNet_ReceiveDatagram).
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.
\param vsockets an array of pointers to various objects that can be waited
on, each cast to a void pointer.
\param numsockets the number of pointers in the vsockets
array.
\param timeout Number of milliseconds to wait for new input to become
available. -1 to wait indefinitely, 0 to check once without
waiting.
\returns the number of items that have new input, or -1 on error.
\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 sockets at the same time without problems.
\since This function is available since SDL_Net 3.0.0.
\sa SDLNet_CreateDatagramSocket \sa SDLNet_SendDatagram \sa SDLNet_ReceiveDatagram
extern SDL_DECLSPEC int SDLCALL SDLNet_WaitUntilInputAvailable(void **vsockets, int numsockets, Sint32 timeout)
Implementation
int sdlNetWaitUntilInputAvailable(
Pointer<Pointer<NativeType>> vsockets, int numsockets, int timeout) {
final sdlNetWaitUntilInputAvailableLookupFunction = libSdl3Net.lookupFunction<
Int32 Function(Pointer<Pointer<NativeType>> vsockets, Int32 numsockets,
Int32 timeout),
int Function(Pointer<Pointer<NativeType>> vsockets, int numsockets,
int timeout)>('SDLNet_WaitUntilInputAvailable');
return sdlNetWaitUntilInputAvailableLookupFunction(
vsockets, numsockets, timeout);
}