Skip to content

stdlib/wsView source ↗

ws

33 items · generated by scribe fromstdlib/ws.fd· synced 2026-11-15

stdlib/ws33 items

Contents

ws_sha1

SHA-1 of a byte Vec → 20-byte Vec.

pub fn ws_sha1(bytes: Vec) -> Vec {

Parameters:

  • bytes: Vec

Returns: Vec

Defined at line 33


WsConn

A WebSocket connection. fd < 0 means handshake/connect failed.

pub struct WsConn {

Fields:

NameType
fdi64
is_clientbool
openbool
tlsi64

Defined at line 137


WsFrame

A received frame/message.

pub struct WsFrame {

Fields:

NameType
opcodei64
textstr
bytesVec
finbool

Defined at line 145


ws_ok

pub fn ws_ok(c: WsConn) -> bool {

Parameters:

  • c: WsConn

Returns: bool

Defined at line 155


ws_failed

A connection that failed (fd -1), for modules that open their own (module wss).

pub fn ws_failed(is_client: bool) -> WsConn {

Parameters:

  • is_client: bool

Returns: WsConn

Defined at line 161


ws_accept_key

The RFC 6455 accept key for a given Sec-WebSocket-Key.

pub fn ws_accept_key(key: str) -> str {

Parameters:

  • key: str

Returns: str

Defined at line 170


ws_set_tls

For module wss: how to read, write and close a TLS session.

pub fn ws_set_tls(recv: fn(i64, i64, i64, i64) -> i64, send: fn(i64, i64, i64) -> i64, close: fn(i64) -> i64) {

Parameters:

  • recv: fn(i64
  • send: fn(i64
  • close: fn(i64) -> i64

Defined at line 208


ws_connect

Client-side connect: TCP + Upgrade handshake. host may be a hostname or IP. Returns WsConn with fd<0 on failure.

pub fn ws_connect(host: str, port: i64, path: str) -> WsConn {

Parameters:

  • host: str
  • port: i64
  • path: str

Returns: WsConn

Defined at line 260


ws_handshake

The client’s Upgrade handshake on a connected socket, or over the TLS session tls on it (module wss). Returns WsConn with fd<0 on failure, the socket then closed.

pub fn ws_handshake(fd: i64, tls: i64, host: str, path: str) -> WsConn {

Parameters:

  • fd: i64
  • tls: i64
  • host: str
  • path: str

Returns: WsConn

Defined at line 275


ws_accept

Server-side accept: given an accepted socket fd and the client’s HTTP request text (read by the caller), validate the Upgrade and send the 101 response. Returns WsConn with fd<0 on failure.

pub fn ws_accept(fd: i64, request: str) -> WsConn {

Parameters:

  • fd: i64
  • request: str

Returns: WsConn

Defined at line 299


ws_read_request

The request of a client that wants to upgrade: its headers, read from the socket or the TLS session.

pub fn ws_read_request(fd: i64, tls: i64) -> str {

Parameters:

  • fd: i64
  • tls: i64

Returns: str

Defined at line 305


ws_accept_on

ws_accept over the TLS session tls on fd (0: none).

pub fn ws_accept_on(fd: i64, tls: i64, request: str) -> WsConn {

Parameters:

  • fd: i64
  • tls: i64
  • request: str

Returns: WsConn

Defined at line 310


ws_frame_encode

Encode a frame. Clients must mask (RFC 6455 §5.3); servers must not.

pub fn ws_frame_encode(opcode: i64, payload: Vec, mask: bool) -> Vec {

Parameters:

  • opcode: i64
  • payload: Vec
  • mask: bool

Returns: Vec

Defined at line 355


ws_recv

Receive one message; opcode -1 on connection failure/close. Continuation frames are accumulated so a fragmented message arrives as one WsFrame. A ping in the middle of one is answered and a pong skipped; a close there ends it (opcode 8). A control frame before any data frame is returned as it is.

pub fn ws_recv(c: WsConn) -> WsFrame {

Parameters:

  • c: WsConn

Returns: WsFrame

Defined at line 438


ws_send_text

Send a text message.

pub fn ws_send_text(c: WsConn, text: str) -> i64 {

Parameters:

  • c: WsConn
  • text: str

Returns: i64

Defined at line 546


ws_send_binary

Send a binary message.

pub fn ws_send_binary(c: WsConn, data: Vec) -> i64 {

Parameters:

  • c: WsConn
  • data: Vec

Returns: i64

Defined at line 551


ws_send_ping

Send a ping.

pub fn ws_send_ping(c: WsConn, text: str) -> i64 {

Parameters:

  • c: WsConn
  • text: str

Returns: i64

Defined at line 556


ws_send_pong

Reply to a ping (callers handle it automatically in ws_recv_loop).

pub fn ws_send_pong(c: WsConn, payload: Vec) -> i64 {

Parameters:

  • c: WsConn
  • payload: Vec

Returns: i64

Defined at line 561


ws_close

Close handshake + socket close.

pub fn ws_close(c: WsConn) -> void {

Parameters:

  • c: WsConn

Returns: void

Defined at line 566


Generated by scribe, the Fides documentation generator