socket::Conn
An owning TCP connection — a socket fd whose destructor closes it.
The RAII counterpart to the fd-based calls above, and the C++/cheatah analog of a Python socket used in a with block. A Conn owns exactly one fd; when it is destroyed (scope exit, including a return/break/exception out of a with body) or explicitly close()d, the fd is released — so a connection opened with with socket.open(host, port) as c { … } cannot leak. Move-only: copying would give two owners of one fd and double-close it, so the copy operations are deleted and a moved-from Conn is left closed.
Functions
Conn · 4 overloads
Construct a closed connection (owns no fd).
operator= · 2 overloads
Move-assign, closing this fd first, then taking over other's (which becomes closed).
other | the connection to move from. |
reference to this connection.
O(1).
none.
Close the fd if still open.
Is a connection open?
true iff this owns an open fd.
O(1).
none.
CheatahSocket.ConnDefaultIsClosedThe raw fd, for the low-level calls or to hand to tls.open(conn.fd(), …).
the owned fd, or -1 when closed.
O(1).
none.
Send some of data (one send(); see the free send()).
data | bytes to send. |
bytes actually sent, or -1 on error.
O(n).
none.
CheatahSocket.ConnLoopbackSend data in full, looping until every byte is written (see the free sendall()).
data | bytes to send. |
0 on success, -1 on error.
O(n).
none.
CheatahSocket.ConnLoopbackReceive up to bufsize bytes (see the free recv()).
bufsize | maximum bytes to read. |
the bytes read (binary-safe), or "" on EOF/error.
O(bufsize).
allocates the returned string (plus the free recv()'s reused per-thread scratch buffer on growth).
blocks until data, EOF, or the set_timeout() deadline.
CheatahSocket.ConnLoopbackBound both blocking directions by timeout_ms (see the free set_timeout()).
timeout_ms | per-operation bound in milliseconds (<= 0 clears it). |
0 on success, -1 on error.
O(1).
none.
CheatahSocket.ConnLoopbackThe local TCP port this fd is bound to (see the free local_port()).
the port, or -1 on error.
O(1) syscall.
none.
CheatahSocket.ConnLoopbackHalf-close both directions WITHOUT releasing the fd (see the free shutdown()) — wakes a blocked reader for a clean shutdown; still call close() (or let the destructor) afterward.
0 on success, -1 on error.
O(1) syscall.
none.
CheatahSocket.ConnLoopbackClose the fd now (idempotent — the destructor will not close it again).
0 on success, -1 if already closed.
O(1) syscall.
none.
