cheatah
Class

tls::Conn

An owning TLS 1.3 client session — closes (and erases) itself on destruction.

The RAII counterpart to the handle-based calls above. A Conn owns one session; when it is destroyed (scope exit out of a with body, including via exception) or explicitly close()d, the session is torn down and removed from the module's session table, so with tls.open(sock.fd(), host) as conn { … } cannot leak the session. Move-only: the copy operations are deleted and a moved-from Conn is left closed. The underlying TCP fd is NOT owned here (tls rides a caller-owned socket) — guard it with a socket::Conn.

Functions

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

Construct a closed session (owns nothing).

Complexity

O(1).

Allocation

none.

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

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

Parameters
other

the session to move from.

Returns

reference to this session.

Complexity

O(1).

Allocation

none.

fn ~Conn() source#

Send close_notify and forget the session if still open.

Complexity

O(log n) lookup + a close_notify write.

Allocation

a small close_notify record (when still open).

fn bool is_open() const source#

Is a session 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 long long send(const std::string &data) source#

Encrypt and send data as TLS application data (see the free send()).

Parameters
data

plaintext to send.

Returns

0 on success, -1 on error.

Complexity

O(|data|).

Allocation

the ciphertext record(s).

Concurrency

a session is single-owner — never send on one session from two threads at once (the record sequence would race). Separate sessions are independent.

fn std::string recv(long long bufsize) source#

Receive and decrypt up to bufsize bytes of application data (see the free recv()).

Parameters
bufsize

maximum plaintext bytes to return.

Returns

the plaintext, or "" on clean close/EOF/error.

Complexity

O(bytes drained) — it decrypts every record already buffered, up to bufsize.

Allocation

the returned plaintext (plus per-record decryption buffers while draining).

Concurrency

blocks (bounded by the fd's socket.set_timeout()) only while nothing is ready; a session has ONE reader — shutdown() is the cross-thread wake-up.

fn long long shutdown() source#

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

Returns

0 on success, -1 on error.

Complexity

O(log n) lookup + 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 session now (idempotent — the destructor will not close it again).

Returns

0 on success, -1 if already closed / unknown.

Complexity

O(log n) lookup + a close_notify write.

Allocation

a small close_notify record (when still open).

Constants & variables

var long long session_ source#