NET_GETSTREAMSOCKETPENDINGWRITES(3)

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

πŸ’– NET_GetStreamSocketPendingWrites(3) πŸ’–

okay bestie, welcome to the SDL_net3 FUNCTIONS section of the manual, and today's main character is NET_GetStreamSocketPendingWrites. she's a little query function and she's lowkey essential. let's get into it 🫢


✨ NAME ✨

NET_GetStreamSocketPendingWrites β€” ask a stream socket how many bytes are still sitting in the queue waiting to be sent. it's giving "are we there yet" but for your network buffer πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3_net/SDL_net.h>

int NET_GetStreamSocketPendingWrites(NET_StreamSocket *sock);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea πŸ“ β€” if NET_WriteToStreamSocket() couldn't send all of its data right that second, it doesn't just give up, no ma'am. it queues the leftovers to be sent later. this function is how your app peeks at that queue and goes "okay so how much of this is still pending?"

the library will try to send more of the queued data before it reports back what's left β€” she's helpful like that β€” but she will not block to do it. no hanging, no waiting around, she's busy πŸ’…

now for the serious part, bestie, pay attention 😭 if the connection has failed β€” like the remote side dropped us, or one of a million other networking failures happened β€” this function reports failure by returning -1. stream sockets only report failure for unrecoverable conditions. and once a stream socket fails? assume it's done, she's not coming back, and you should destroy it with NET_DestroyStreamSocket(). periodt.


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • sock β€” the stream socket you wanna query, bestie. the one you're checking up on πŸ’œ

⭐ RETURN VALUE ⭐

returns the number of bytes still pending transmission, or -1 on failure. and if you get that -1? call SDL_GetError() for the details, she'll tell you what went wrong πŸ™ˆ


πŸ”₯ THREAD SAFETY πŸ”₯

okay so do not operate on the same socket from multiple threads at the same time unless you've got yourself a serialization mechanism, bestie. that's a vibe check you will fail πŸ’€

but good news β€” different threads can absolutely access different sockets at the same time with zero problems. parallel slay πŸ‘‘


🌈 AVAILABILITY 🌈

this function has been available since SDL_net 3.0.0. she's an OG πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're part of the same friend group πŸ’–


and that's the whole page, bestie!! this was SDL_net version 3.2.0, signing off with so much love β€” stay drained, stay non-blocking, and never forget to destroy your failed sockets πŸ«Άβœ¨πŸ’…

πŸ“¦ where this page comes from