NET_WAITUNTILINPUTAVAILABLE(3)
π NET_WaitUntilInputAvailable(3) π
okay bestie, grab a boba because we're diving into the SDL_net3 manual, and this one is a functions girlie through and through. her name is NET_WaitUntilInputAvailable, and she's the friend who holds your spot in line while you're asleep. let's go π«Ά
β¨ NAME β¨
NET_WaitUntilInputAvailable β block on multiple sockets until at least one of them has data available. literally just vibing on a bunch of sockets at once, waiting for one of them to wake up π
πΈ SYNOPSIS πΈ
#include <SDL3_net/SDL_net.h>
int NET_WaitUntilInputAvailable(void **vsockets, int numsockets, Sint32 timeout);
π¦ DESCRIPTION π¦
ngl, 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. so like, not for everyone, but if you're that girl, you're that girl β¨
this lets you hand it a list of objects and then wait for new input to become available on any of them. the calling thread is put to sleep until such a time. it's giving "nap until someone knocks" energy π΄
here's what you can put in the vsockets array, each one cast to void *:
NET_Serverβ reports new input when a connection is ready to be accepted withNET_AcceptClient(). so someone's knocking at the door πͺNET_StreamSocketβ reports new input when the remote end has sent more bytes of data to be read withNET_ReadFromStreamSocket, or if the socket finished making its initial connection. new messages in the group chat π¬NET_DatagramSocketβ reports new input when a new packet arrives that can be read withNET_ReceiveDatagram. a whole lil parcel just landed π¦
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. so: -1 is "i'll wait forever, i'm loyal", 0 is "okay bye, tell me if anything happened" πβοΈ
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. so you gotta do the detective work yourself, bestie π
π FUNCTION PARAMETERS π
vsocketsβ an array of pointers to various objects that can be waited on, each cast to avoidpointer.numsocketsβ the number of pointers in thevsocketsarray.timeoutβ number of milliseconds to wait for new input to become available.-1to wait indefinitely,0to check once without waiting.
π RETURN VALUE π
returns the number of items that have new input, or -1 on error. that's it, that's the whole tea β
π§ THREAD SAFETY π§
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. so like β one socket, one thread, no sharing, no drama π shared custody of the same socket is a no, but y'all can each hold your own socket at the same time, no problem π
β AVAILABILITY β
this function is available since SDL_net 3.0.0. she's been iconic since day one, no cap π
π SEE ALSO π
and that's the whole page, bestie!! this was brought to you by the SDL_net girlies, version SDL_net 3.2.0 β fr fr, slay, periodt π β¨ππ¦π
π¦ where this page comes from
- fedora 43: SDL3_net-devel 3.2.0-2.fc43 Β· Zlib
- fedora 43: SDL3_net-devel 3.2.0-2.fc43 Β· Zlib
- fedora 44: SDL3_net-devel 3.2.0-2.fc44 Β· Zlib
- fedora 44: SDL3_net-devel 3.2.0-2.fc44 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms