Stream
struct StreamA connected TCP socket. It's non-blocking, but write_all and read_into wait for it, so to its users it blocks; the head's loop uses send_some and recv_some, which don't. Closes itself when dropped.
Implements Movable
- Fields
fd: c_int
__init__
def __init__(out self, fd: Int32) __deinit__
def __deinit__(deinit self) connect
def connect(port: Int, timeout_ms: Int = Int(-1)) -> Self Connects to 127.0.0.1:port, waiting at most timeout_ms (-1: as long as the kernel tries).
def connect(host: String, port: Int, timeout_ms: Int = Int(-1)) -> Self Connects to host:port; host is a name or a dotted quad. Waits at most timeout_ms (-1: as long as the kernel tries).
def connect(ip: Array[UInt8, Int(4)], port: Int, timeout_ms: Int = Int(-1)) -> Self Connects to ip:port, waiting at most timeout_ms (-1: as long as the kernel tries).
start_connect
def start_connect(ip: Array[UInt8, Int(4)], port: Int) -> Self Starts connecting to ip:port and returns at once. The socket is writable once the connect completes or fails; finish_connect then says which. An event loop connects this way, so a peer that never answers doesn't stall it.
finish_connect
def finish_connect(mut self) Raises if the connect start_connect began failed. Call it once the socket polls writable (or failed).
local_ip
def local_ip(self) -> Array[UInt8, Int(4)] The local IPv4 address this connection goes out from.
write_all
def write_all(self, data: Span[UInt8]) Writes every byte of data.
read_into
def read_into(self, buf: Pointer[UInt8], size: Int) -> Int Reads exactly size bytes into buf.
Returns size, or 0 when the peer closed before sending anything.
Raises if the peer closes partway through.
close
def close(mut self)