NET_GetConnectionStatus(3)
π« NET_GetConnectionStatus(3) π«
okay bestie, welcome to the SDL_net3 FUNCTIONS corner of the manual, where we talk about NET_GetConnectionStatus β the lil function that peeks at your socket and tells you if it's connected yet, no blocking, no waiting around, no drama π
β¨ NAME β¨
NET_GetConnectionStatus β check if a stream socket is connected, without blocking. π¦
β¨ SYNOPSIS β¨
#include <SDL3_net/SDL_net.h>
NET_Status NET_GetConnectionStatus(NET_StreamSocket *sock);
β¨ DESCRIPTION β¨
so here's the tea π β the NET_StreamSocket objects you get back from NET_CreateClient do not connect instantly. they take time to go negotiate a connection with a server. and because waiting around for an indefinite amount of time is not the vibe, it does all that work _asynchronously_ instead of making your program sit there like π§
this function is your little window into that progress. it lets you check how the connection work is going without blocking. obsessed.
β οΈ but listen β a connection can totally fail after a while (maybe the server took a sec to respond and then was like "no π" and rejected you). so fr fr, actually check the result of this function. do not just assume it worked because the value is non-zero. that's the trap. π
once a connection is successfully made, the stream socket is ready to send and receive data with the server. slay. π
and one more thing, iykyk: if the connection succeeds but later gets dropped, this function will still report the connection as successful. that's because it only deals with the initial asynchronous work of getting connected, periodt. you'll find out the connection dropped later, when your reads and writes start reporting failures. π
β¨ FUNCTION PARAMETERS β¨
sockβ the stream socket you wanna query. π
β¨ RETURN VALUE β¨
- returns
NET_SUCCESSif it's successfully connected π - returns
NET_FAILUREif the connection failed π - returns
NET_WAITINGif it's still connecting β³
and if you got NET_FAILURE, go call SDL_GetError() for the details. it'll spill everything.
β¨ THREAD SAFETY β¨
do not operate on the same socket from multiple threads at the same time unless you bring your own serialization mechanism, bestie. that's a recipe for chaos. π
however! different threads can absolutely access different sockets at the same time with zero problems. main character energy per socket, basically. π
β¨ AVAILABILITY β¨
this function has been available since SDL_net 3.0.0. it's been iconic for a while now. β
β¨ SEE ALSO β¨
NET_WaitUntilConnected(3)β the sibling function, go say hi π«Ά
and that's the whole page, no cap π this was SDL_net 3.2.0, brought to you by the SDL_net girlies. go forth and check your connection status responsibly, mwah ππΈ
π¦ 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