NET_WaitUntilConnected(3)
π NET_WaitUntilConnected β the "bestie just WAIT" page π
okay so this is NET_WaitUntilConnected(3), from the SDL_net3 FUNCTIONS crew. it's a manual page, it's giving "let me pause your whole program for you," and honestly? iconic. let's get into it π«Ά
β¨ NAME β¨
NET_WaitUntilConnected β block until a stream socket has connected to a server. like literally just sit there and wait, no thoughts, head empty, until the socket is done doing its thing π
πΈ SYNOPSIS πΈ
#include <SDL3_net/SDL_net.h>
NET_Status NET_WaitUntilConnected(NET_StreamSocket *sock, Sint32 timeout);
π¦ DESCRIPTION π¦
so the NET_StreamSocket objects you get back from NET_CreateClient? they take time to do their work. that's why they do it asynchronously instead of making your program wait an indefinite amount of time. main character behavior honestly β they're off doing their own thing while you live your life β¨
but. BUT. if you want your program to sleep until the connection is complete? that's what this function is for, bestie. call it and go night-night π΄
this function takes a timeout value, and it's in milliseconds β that's how long it waits for resolution to complete. and here's the vibe check on the special numbers:
- a timeout of
-1tells the library to wait indefinitely. forever. no cap, until the end of time π - a timeout of
0just checks the current status and returns immediately β and it's functionally equivalent to callingNET_GetConnectionStatus.
β οΈ important!! 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! do not assume. assuming is not the move. π
once a connection is successfully made, the socket may read data from, or write data to, the connected server. slay, that's the whole point π
and if you don't want your program to block? you can call NET_GetConnectionStatus() from time to time until you get a non-zero result. casual. lowkey polling. we love her π§
π FUNCTION PARAMETERS π
sockβ theNET_StreamSocketobject to wait on. this is the one you're waiting for, your little guy πtimeoutβ number of milliseconds to wait for resolution to complete.-1to wait indefinitely,0to check once without waiting. that's it, that's the rule β
π₯ RETURN VALUE π₯
- returns
NET_SUCCESSif successfully connected π - returns
NET_FAILUREif connection failed π - returns
NET_WAITINGif still connecting (this function timed out without resolution) β she's still cooking π
and if you got NET_FAILURE, call SDL_GetError() for details. go get the tea, it'll tell you what went wrong.
π THREAD SAFETY π
you should not operate on the same socket from multiple threads at the same time without supplying a serialization mechanism. like, don't. it's not that kind of party.
however, different threads may access different sockets at the same time without problems. so everyone can have their own. sharing is not caring here π
π AVAILABILITY π
this function is available since SDL_net 3.0.0. she's been here. she's a legend. periodt.
π SEE ALSO π
and that's the page!! πβ¨ππ¦πΈπ π«Άππ₯ππβππππ§π
okay so like, this whole thing is from the SDL_net manual, version SDL_net 3.2.0 β shoutout to the source, couldn't have said it better myself (well, except for all the parts I did say better, obviously). anyway bestie, go forth and wait on your sockets responsibly π
π¦ 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