std.net.tcp
TCP streams and listeners over socket.Socket
TcpStream
Section titled “TcpStream”pub TcpStream :: struct { sock: socket::Socket,}connected TCP socket
TcpStream.send
Section titled “TcpStream.send”pub send :: fn(self: *Self, data: []const u8) -> usize ! NetErrormay write fewer than data.len; returns bytes sent
TcpStream.send_all
Section titled “TcpStream.send_all”pub send_all :: fn(self: *Self, data: []const u8) -> void ! NetErrorloops over short writes; send_failed on error, closed if 0 bytes go out
TcpStream.recv
Section titled “TcpStream.recv”pub recv :: fn(self: *Self, buf: []u8) -> usize ! NetErrorreturns bytes read; 0 = peer closed
TcpStream.recv_exact
Section titled “TcpStream.recv_exact”pub recv_exact :: fn(self: *Self, buf: []u8) -> void ! NetErrorfills buf; closed if the peer hangs up first (truncated message)
TcpStream.set_nodelay
Section titled “TcpStream.set_nodelay”pub set_nodelay :: fn(self: *Self, on: bool) -> void ! NetErrordisables Nagle: small packets go out at once
TcpStream.set_read_timeout
Section titled “TcpStream.set_read_timeout”pub set_read_timeout :: fn(self: *Self, ms: i32) -> void ! NetErrorTcpStream.set_write_timeout
Section titled “TcpStream.set_write_timeout”pub set_write_timeout :: fn(self: *Self, ms: i32) -> void ! NetErrorTcpStream.local_addr
Section titled “TcpStream.local_addr”pub local_addr :: fn(self: *Self) -> addr::SocketAddr ! NetErrorTcpStream.shutdown_write
Section titled “TcpStream.shutdown_write”pub shutdown_write :: fn(self: *Self) -> void ! NetErrorhalf-close: EOF to the peer, reads still work
TcpStream.close
Section titled “TcpStream.close”pub close :: fn(self: *Self)Accepted
Section titled “Accepted”pub Accepted :: struct { stream: TcpStream, peer: addr::SocketAddr,}stream and peer address from accept
TcpListener
Section titled “TcpListener”pub TcpListener :: struct { sock: socket::Socket,}TcpListener.accept
Section titled “TcpListener.accept”pub accept :: fn(self: *Self) -> Accepted ! NetErrorblocks until a client connects
TcpListener.accept_stream
Section titled “TcpListener.accept_stream”pub accept_stream :: fn(self: *Self) -> TcpStream ! NetErroraccept without the peer address
TcpListener.local_addr
Section titled “TcpListener.local_addr”pub local_addr :: fn(self: *Self) -> addr::SocketAddr ! NetErrorbound address; resolves an ephemeral port
TcpListener.close
Section titled “TcpListener.close”pub close :: fn(self: *Self)connect
Section titled “connect”pub connect :: fn(sa: addr::SocketAddr) -> TcpStream ! NetErrorclient side
listen_backlog
Section titled “listen_backlog”pub listen_backlog :: fn(sa: addr::SocketAddr, backlog: i32) -> TcpListener ! NetErrorsets SO_REUSEADDR first so a restart survives TIME_WAIT
listen
Section titled “listen”pub listen :: fn(sa: addr::SocketAddr) -> TcpListener ! NetErrorbacklog 16