NET_WAITUNTILSTREAMSOCKETDRAINED(3)

πŸ“¦
version 3.2.0 Β· 2 versions
, in fedora 43, fedora 44

✨ NET_WaitUntilStreamSocketDrained ✨

okay bestie, this is a page from the SDL_net3 function crew, and it's about the moment you just gotta wait for your socket to finish yapping. πŸ’…


🌸 NAME 🌸

NET_WaitUntilStreamSocketDrained β€” block until all of a stream socket's pending data is sent.

like, sit there and chill until the socket is done sending everything. no cap. πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3_net/SDL_net.h>

int NET_WaitUntilStreamSocketDrained(NET_StreamSocket *sock, Sint32 timeout);

πŸ’– DESCRIPTION πŸ’–

so here's the tea: if NET_WriteToStreamSocket() couldn't send all its data immediately, it will queue it up to be sent later. this function is literally just letting your app sleep 😴 until all that data is transmitted. it's giving "let her cook."

it takes a timeout value, and that's in milliseconds, bestie β€” how long to wait for transmission to complete:

  • a timeout of -1 tells the library to wait indefinitely (iconic, patient queen behavior πŸ‘‘)
  • a timeout of 0 just checks the current status and returns immediately β€” and that's functionally equivalent to calling NET_GetStreamSocketPendingWrites 🫢

if you don't want your program to block (main character doesn't wait in lines βœ‹), you can call NET_GetStreamSocketPendingWrites from time to time until you get a result <= 0.

and now the serious part, don't skip this 🚨: if the connection has failed β€” remote side dropped us, or one of a million other networking failures occurred β€” this function will report failure by returning -1. stream sockets only report failure for unrecoverable conditions. once a stream socket fails, you should assume it is no longer usable and should destroy it with NET_DestroyStreamSocket(). it's over, it's done, she's not coming back. πŸ’€


🌈 FUNCTION PARAMETERS 🌈

  • sock β€” the stream socket to wait on. your girl. the one you're waiting for. 🧚
  • timeout β€” number of milliseconds to wait for draining to complete. -1 to wait indefinitely, 0 to check once without waiting.

⭐ RETURN VALUE ⭐

returns the number of bytes still pending transmission, or -1 on failure β€” and if it fails, call SDL_GetError() for the details, because she will tell you exactly what went wrong. πŸ’œ


πŸ”₯ THREAD SAFETY πŸ”₯

okay so, do not operate on the same socket from multiple threads at the same time without supplying a serialization mechanism. that's a vibe check you will fail. πŸ™ˆ

however, different threads may access different sockets at the same time without problems. so everyone can have their own socket, just no sharing, periodt. ✨


πŸ¦‹ AVAILABILITY πŸ¦‹

this function is available since SDL_net 3.0.0. she's not new new, she's established. 🌸


πŸ’… SEE ALSO πŸ’…


and that's the whole page, bestie πŸ₯° this lil slice of SDL_net is from SDL_net 3.2.0 β€” go drain that socket, you absolute icon. bye bye πŸ’–πŸŽ€πŸ«Ά

πŸ“¦ where this page comes from