WSLAY_EVENT_CONTEXT_FREE(3) | wslay | WSLAY_EVENT_CONTEXT_FREE(3) |
wslay_event_context_free - Initialize an event-based API context
#include <wslay/wslay.h>
wslay_event_context_server_init() function initializes an event-based API context for WebSocket server use. wslay_event_context_client_init() function initializes an event-based API context for WebSocket client use. If they return successfully, ctx will point to a structure which holds any necessary resources needed to process WebSocket protocol transfers.
callbacks is a pointer to wslay_event_callbacks, which is defined as follows:
struct wslay_event_callbacks {
wslay_event_recv_callback recv_callback;
wslay_event_send_callback send_callback;
wslay_event_genmask_callback genmask_callback;
wslay_event_on_frame_recv_start_callback on_frame_recv_start_callback;
wslay_event_on_frame_recv_chunk_callback on_frame_recv_chunk_callback;
wslay_event_on_frame_recv_end_callback on_frame_recv_end_callback;
wslay_event_on_msg_recv_callback on_msg_recv_callback; };
If there is an error, return -1 and set error code WSLAY_ERR_CALLBACK_FAILURE using wslay_event_set_error(). Wslay event-based API on the whole assumes non-blocking I/O. If the cause of error is EAGAIN or EWOULDBLOCK, set WSLAY_ERR_WOULDBLOCK instead. This is important because it tells wslay_event_recv() to stop receiving further data and return.
It provides some hints to tune performance and behaviour.
If there is an error, return -1 and set error code WSLAY_ERR_CALLBACK_FAILURE using wslay_event_set_error(). Wslay event-based API on the whole assumes non-blocking I/O. If the cause of error is EAGAIN or EWOULDBLOCK, set WSLAY_ERR_WOULDBLOCK instead. This is important because it tells wslay_event_send() to stop sending data and return.
struct wslay_event_on_frame_recv_start_arg {
uint8_t fin;
uint8_t rsv;
uint8_t opcode;
uint64_t payload_length; };
fin, rsv and opcode is fin bit and reserved bits and opcode of a frame. payload_length is a payload length of a frame.
struct wslay_event_on_frame_recv_chunk_arg {
const uint8_t *data;
size_t data_length; };
data points to a chunk of payload data. data_length is the length of a chunk.
struct wslay_event_on_msg_recv_arg {
uint8_t rsv;
uint8_t opcode;
const uint8_t *msg;
size_t msg_length;
uint16_t status_code; };
The rsv member and the opcode member are reserved bits and opcode of received message respectively. The rsv member is constructed as follows:
rsv = (RSV1 << 2) | (RSV2 << 1) | RSV3
The msg member points to the message of the received message. The msg_length member is the length of message. If a message is close control frame, in other words, opcode == WSLAY_CONNECTION_CLOSE, status_code is set to the status code in the close control frame. If no status code is included in the close control frame, status_code set to 0.
user_data is an arbitrary pointer, which is directly passed to each callback functions as user_data argument.
When initialized event-based API context ctx is no longer used, use wslay_event_context_free() to free any resources allocated for ctx.
wslay_event_context_server_init() and wslay_event_context_client_init() returns 0 if it succeeds, or one of the following negative error codes:
wslay_event_send(), wslay_event_recv(), wslay_event_set_error()
Tatsuhiro Tsujikawa
2021, 2015, Tatsuhiro Tsujikawa
November 7, 2021 | @PACKAGE_VERSION@ |