WSLAY_EVENT_RECV(3)
π WSLAY_EVENT_RECV π
okay so bestie, welcome to the wslay manual, section 3 (that's the library-functions section, iykyk). today's main character is wslay_event_recv(3) and she is literally the one who pulls messages off the wire for you. let's get into it π«Ά
β¨ NAME β¨
wslay_event_recv β Receive messages π
πΈ SYNOPSIS πΈ
#include <wslay/wslay.h>
int wslay_event_recv(wslay_event_context_ptr ctx)
π¦ DESCRIPTION π¦
wslay_event_recv() receives messages from the peer. the way it does that is it leans on the wslay_event_recv_callback function. and here's the thing β one single call of this function doesn't just grab one message, no ma'am, it keeps receiving multiple messages until wslay_event_recv_callback sets the error code WSLAY_ERR_WOULDBLOCK. that's the lil stop sign. π
so wslay_event_recv() calls the following callback functions, each one for its own event (peep wslay_event_context_server_init() or wslay_event_context_client_init() if you want the full deets on each of these callbacks).
wslay_event_on_frame_recv_start_callbackβ called when a new frame starts to be received. π¬wslay_event_on_frame_recv_start_callbackβ called when a new frame starts to be received. (and yes bestie, she's listed twice in the original β iconic behavior, we keep it exactly as-is π )wslay_event_on_frame_recv_chunk_callbackβ called when a chunk of frame payload is received. π§©wslay_event_on_frame_recv_end_callbackβ called when a frame is completely received. βwslay_event_on_msg_recv_callbackβ called when a message is completely received. π¬
now the automatic stuff, and this is lowkey the slay part:
- when a close control frame is received, this function automatically queues a close control frame. also, it calls
wslay_event_set_read_enabled()with the second argument0, which disables any further read from the peer. πͺ - when a ping control frame is received, this function automatically queues a pong control frame. π
and in case of a fatal error β the kind that leads to a negative return code β this function callswslay_event_set_read_enabled()with the second argument0to disable further read from the peer. same energy, sadder context. π
π RETURN VALUE π
wslay_event_recv() returns 0 if it succeeds π β or one of these negative error codes, and no, we are not happy about them:
WSLAY_ERR_CALLBACK_FAILUREβ user defined callback function is failed. πWSLAY_ERR_NOMEMβ out of memory. π
π¨ major warning, bestie, listen up: when a negative error code is returned, the application must not make any further call of wslay_event_recv() and must close the WebSocket connection. that's not a suggestion, that's the rules. periodt. π
π SEE ALSO π
wslay_event_set_read_enabled()
π AUTHOR π
Tatsuhiro Tsujikawa π
π COPYRIGHT π
2024, 2015, Tatsuhiro Tsujikawa
okay that's the whole page, bestie β this one shipped in @PACKAGE_VERSION@ and the date on it is Apr 22, 2024, so go forth, call your callbacks, respect the WSLAY_ERR_WOULDBLOCK, and close those connections when you're told to. mwah πβ¨π
π¦ where this page comes from
- ubuntu noble: libwslay-doc 1.1.1-4build1 Β· MIT
- ubuntu questing: libwslay-doc 1.1.1-4build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms