cheatah
Class

websocket::Client

An owning WebSocket client — closes the connection (frame + TLS + socket) on destruction.

The RAII counterpart to the handle-based calls above. A Client owns one session; when it is destroyed (scope exit out of a with body, including via exception) or explicitly close()d, the close frame is sent and the TLS session and TCP socket are torn down, so with websocket.open_url(url) as ws { … } cannot leak the session, its tls session, or its fd. Move-only: the copy operations are deleted and a moved-from Client is left closed.

Functions

fn Client · 4 overloads
Client()=defaultsource#
Client(long long session)source#
Client(const Client &)=deletesource#
Client(Client &&other) noexceptsource#

Construct a closed client (owns nothing).

Complexity

O(1).

Allocation

none.

fn operator= · 2 overloads
Client & operator=(const Client &)=deletesource#
Client & operator=(Client &&other) noexceptsource#

Move-assign, closing this session first, then taking over other's (which becomes closed).

Parameters
other

the client to move from.

Returns

reference to this client.

Complexity

O(1).

Allocation

none.

fn ~Client() source#

Close the connection if still open (close frame + TLS + socket teardown).

Complexity

one TLS write + teardown.

Allocation

a small close frame (when still open).

fn bool is_open() const source#

Is a connection open?

Returns

true iff this owns an open session.

Complexity

O(1).

Allocation

none.

fn long long id() const source#

The raw session handle (for the low-level calls).

Returns

the owned handle, or 0 when closed.

Complexity

O(1).

Allocation

none.

fn std::string recv() source#

Receive the next application message (see the free recv()).

Returns

the message payload; "" once the peer has closed.

Parameters
std::runtime_error

on a transport/protocol error.

Complexity

O(message length).

Allocation

the returned payload.

Concurrency

blocks until a full message arrives; a session has ONE reader — shutdown() is the cross-thread wake-up.

fn long long shutdown() source#

Wake a reader blocked in recv() WITHOUT freeing the session (see the free shutdown()).

Returns

0 on success, -1 on error.

Complexity

O(1) + one syscall.

Allocation

none.

Concurrency

safe to call from another thread while the owner's recv() blocks — that wake-up is its purpose; then join the reader before close().

fn long long close() source#

Close the connection now (idempotent — the destructor will not close it again).

Returns

0 on success, -1 if already closed.

Complexity

one TLS write + teardown.

Allocation

a small close frame (when still open).

Constants & variables

var long long session_ source#