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
Conn · 4 overloads
Construct a closed session (owns nothing).
operator= · 2 overloads
Move-assign, closing this session first, then taking over other's (which becomes closed).
other | the session to move from. |
reference to this session.
O(1).
none.
TlsSys.ConnGuardRoundTripSend close_notify and forget the session if still open.
O(log n) lookup + a close_notify write.
a small close_notify record (when still open).
TlsSys.ConnGuardRoundTripIs a session open?
true iff this owns an open session.
O(1).
none.
TlsSys.ConnGuardRoundTripThe raw session handle (for the low-level calls).
the owned handle, or 0 when closed.
O(1).
none.
TlsSys.ConnGuardRoundTripEncrypt and send data as TLS application data (see the free send()).
data | plaintext to send. |
0 on success, -1 on error.
O(|data|).
the ciphertext record(s).
a session is single-owner — never send on one session from two threads at once (the record sequence would race). Separate sessions are independent.
TlsSys.ConnGuardRoundTripReceive and decrypt up to bufsize bytes of application data (see the free recv()).
bufsize | maximum plaintext bytes to return. |
the plaintext, or "" on clean close/EOF/error.
O(bytes drained) — it decrypts every record already buffered, up to bufsize.
the returned plaintext (plus per-record decryption buffers while draining).
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.
TlsSys.ConnGuardRoundTripWake a reader blocked in recv() WITHOUT closing the session (see the free shutdown()).
0 on success, -1 on error.
O(log n) lookup + one syscall.
none.
safe to call from another thread while the owner's recv() blocks — that wake-up is its purpose; then join the reader before close().
TlsSys.ConnGuardRoundTripClose the session now (idempotent — the destructor will not close it again).
0 on success, -1 if already closed / unknown.
O(log n) lookup + a close_notify write.
a small close_notify record (when still open).
TlsSys.ConnGuardRoundTrip