WSLAY_EVENT_QUEUE_CLOSE(3)

πŸ’– WSLAY_EVENT_QUEUE_CLOSE πŸ’–

okay bestie, welcome to wslay(3) β€” specifically the WSLAY_EVENT_QUEUE_CLOSE page. this one's short, sweet, and honestly kind of iconic. let's get into it ✨


🌸 NAME 🌸

wslay_event_queue_close β€” queue a close control frame πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <wslay/wslay.h>

int wslay_event_queue_close(wslay_event_context_ptr ctx, uint16_t
status_code, const uint8_t *reason, size_t reason_length)

like. look at her. four args, one return value, zero drama. πŸ’…


✨ DESCRIPTION ✨

so wslay_event_queue_close() queues a close control frame. that's the whole vibe fr fr.

real talk though β€” this function is provided just for convenience. it's giving "you could do this yourself, but why would you". because here's the thing: wslay_event_queue_msg() can queue a close control frame as well. so if you're already deep in that function's DMs, you're covered. wslay_event_queue_close() is just the easy button. 🫢

now let's talk about the args, because they matter:

  • status_code β€” this is the status code of the close control frame. it's a uint16_t, so it's a cute little number.
  • reason β€” the close reason, encoded in UTF-8. yes, it has to be UTF-8, don't come at me with your latin-1 nonsense πŸ™ˆ
  • reason_length β€” the length of reason in bytes. not characters, bestie. bytes.
⚠️ and here's the one that will get you: reason_length must be less than 123 bytes. not less than or equal to. less than. 123 is the ceiling and you are not touching it. πŸ’€

there's also a lil special case, and it's lowkey my fave:

if status_code is 0, then reason and reason_length are not used at all β€” they get ignored, no cap β€” and a close control frame with a zero-length payload will be queued instead. so you can just pass 0 and dip. 🌈

and now the part everyone forgets:

this function just queues a message. it does not send it. 🚨

nothing goes out on the wire from calling this. you have to call wslay_event_send() to actually send these queued messages. so don't queue your close frame and then sit there wondering why nothing happened, because that's on you, not on her. 😭


πŸ”₯ RETURN VALUE πŸ”₯

wslay_event_queue_close() returns 0 if it succeeds. slay. βœ…

or it returns one of these negative error codes, and honestly, mood:

  • WSLAY_ERR_NO_MORE_MSG β€” could not queue the given message. one of the possible reasons is that a close control frame has already been queued/sent, and no further queueing of a message is not allowed. so basically: you already closed the door, why are you trying to close it again πŸšͺπŸ”’
  • WSLAY_ERR_INVALID_ARGUMENT β€” the given message is invalid. something about your args is not passing the vibe check.
  • WSLAY_ERR_NOMEM β€” out of memory. πŸ’€ the classic.

πŸ’œ SEE ALSO πŸ’œ

go read these too, they're in the group chat:

  • wslay_event_queue_msg()
  • wslay_event_queue_fragmented_msg()

πŸ‘‘ AUTHOR πŸ‘‘

Tatsuhiro Tsujikawa β€” the icon, the legend, the moment. 🌟


2024, 2015, Tatsuhiro Tsujikawa


and that's the page, bestie!! πŸ¦‹ this was @PACKAGE_VERSION@, dated Apr 22, 2024, living in section 3 of the wslay manual. queue responsibly, keep your reason_length under 123 bytes, and always remember to actually call wslay_event_send(). mwah πŸ’–βœ¨

πŸ“¦ where this page comes from