ws.h(3)axil

NAME

ws.h - WebSocket framing on top of the axil I/O table.

SYNOPSIS

#include <unistd.h>
#include <stdarg.h>

Functions

int ws_init (socket_t fd, char *buf)

Initialize WebSocket framing on a descriptor.

void ws_close (socket_t fd)

Close a WebSocket session and tear down its framing state.

io_ssize_t ws_read (socket_t fd, void *data, io_size_t len, int flags)

Framed read hook installed into the I/O table.

io_ssize_t ws_write (socket_t fd, void *data, io_size_t n, int flags)

Framed write hook installed into the I/O table.

int ws_dprintf (socket_t fd, const char *fmt, va_list ap)

Write a formatted string over a WS frame (va_list form).

int ws_printf (socket_t fd, const char *fmt,...)

Write a formatted string over a WS frame.

Detailed Description

WebSocket framing on top of the axil I/O table.

Handles handshake buffers, close, and framed read/write dispatch through the io[fd] slots.

Function Documentation

void ws_close (socket_t fd)

Close a WebSocket session and tear down its framing state.

Parameters

fd Socket descriptor.

int ws_dprintf (socket_t fd, const char * fmt, va_list ap)

Write a formatted string over a WS frame (va_list form).

Parameters

fd Socket descriptor.
fmt Format string.
ap Argument list.

Returns

0 on success, -1 on error.

int ws_init (socket_t fd, char * buf)

Initialize WebSocket framing on a descriptor.

Parameters

fd Socket descriptor.
buf Handshake buffer (consumed by the handshake).

Returns

0 on success, -1 on failure.

int ws_printf (socket_t fd, const char * fmt, ...)

Write a formatted string over a WS frame.

Parameters

fd Socket descriptor.
fmt Format string.

Returns

0 on success, -1 on error.

io_ssize_t ws_read (socket_t fd, void * data, io_size_t len, int flags)

Framed read hook installed into the I/O table.

Parameters

fd Socket descriptor.
data Destination buffer.
len Requested byte count. Must be at least 1 whenever data is non-NULL: a zero-length destination is refused with -1 and errno EMSGSIZE, since it is the one value that cannot describe any buffer at all. data == NULL discards the frame whatever len is. The frame's NUL terminator needs one of these bytes, so a payload is only returned when it fits in len - 1.
flags Operation flags.

Returns

Bytes read (NUL-terminated), or -1 on error. A frame larger than len - 1 is refused with -1 and errno set to EMSGSIZE rather than truncated โ€” note the frame is read off the socket in full before the size is known, so a refused frame is consumed and cannot be retried. -1 with errno EAGAIN means the frame is still arriving and nothing was consumed.

io_ssize_t ws_write (socket_t fd, void * data, io_size_t n, int flags)

Framed write hook installed into the I/O table.

Parameters

fd Socket descriptor.
data Source buffer.
n Byte count.
flags Operation flags.

Returns

The frame size, header included, once the frame is wholly written or queued for a non-blocking socket, or -1 if the connection failed. A non-negative result does not mean the bytes have left the socket: when the peer is slow the tail sits in the descriptor's write queue and is flushed by the event loop. The header goes through the same queue as the payload, so frames cannot interleave or be lost to EAGAIN.

Author

Generated automatically by Doxygen for axil from the source code.