NET_DestroyStreamSocket(3)

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

πŸ’– NET_DestroyStreamSocket(3) πŸ’–

okay bestie, we're in the SDL_net3 FUNCTIONS section of the SDL_net manual, and today's main character is NET_DestroyStreamSocket β€” the lil cleanup queen who takes your stream sockets to their final resting place 🫢


✨ NAME ✨

NET_DestroyStreamSocket β€” dispose of a previously-created stream socket. literally the goodbye button πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3_net/SDL_net.h>

void NET_DestroyStreamSocket(NET_StreamSocket *sock);  /* Destroy your sockets when finished with them. Does not block, handles shutdown internally. */

yes the comment is in the code block, that's just how they do it here, and it's giving helpful honestly πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

so this will immediately disconnect the other side of the connection, if necessary. like, no waiting around, no "let me think about it", just gone ✨ and fr fr, any further attempts to read or write the socket on the remote end will fail.

now here's the part you need to clock, bestie: this will _abandon_ any data queued for sending that hasn't made it to the socket. not "finish sending it first", not "politely wait" β€” abandon. 😭 so if you actually need that data to arrive, you should wait for it to transmit before destroying the socket, using NET_GetStreamSocketPendingWrites() or NET_WaitUntilStreamSocketDrained().

and any data that has arrived from the remote end of the connection that hasn't been read yet? lost. gone. poof. πŸ™ˆ

not me destroying sockets with unread data like it's nothing πŸ’€ check your pending writes FIRST, i'm begging

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • sock β€” stream socket to destroy. the one we're sending off πŸ‘‘

🌈 THREAD SAFETY 🌈

do not operate on the same socket from multiple threads at the same time without supplying a serialization mechanism. that's the rule. that's the vibe check, and you will fail it if you ignore this 🚫

but β€” different threads may access different sockets at the same time without problems. so like, everybody gets their own socket, everybody stays in their own lane, no drama πŸ’œ


⭐ AVAILABILITY ⭐

this function is available since SDL_net 3.0.0. iconic behavior, been here since the beginning πŸ‘‘


πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group fr fr 🫢 go read them, iykyk


and that's the page!! this is from SDL_net, version SDL_net 3.2.0, and it's filed under NET_DestroyStreamSocket(3). slay, go clean up your sockets responsibly, bestie πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from