std.net.socket
raw OS socket handle; options shared by tcp and udp
Socket
Section titled “Socket”pub Socket :: struct { fd: usize,}raw Winsock SOCKET; INVALID_SOCKET = none; make with tcp()/udp() or from_fd
Socket.is_valid
Section titled “Socket.is_valid”pub is_valid :: fn(self: *Self) -> boolfalse for INVALID_SOCKET
Socket.close
Section titled “Socket.close”pub close :: fn(self: *Self)safe on an invalid handle
Socket.shutdown
Section titled “Socket.shutdown”pub shutdown :: fn(self: *Self, how: i32) -> void ! NetErrorhow: os::SHUT_RECV, SHUT_SEND or SHUT_BOTH
Socket.set_opt_int
Section titled “Socket.set_opt_int”pub set_opt_int :: fn(self: *Self, level: i32, opt: i32, value: i32) -> void ! NetErrorint-valued option: timeouts, BOOL flags
Socket.set_reuse_addr
Section titled “Socket.set_reuse_addr”pub set_reuse_addr :: fn(self: *Self, on: bool) -> void ! NetErrorallow binding an address in TIME_WAIT; servers set it before bind
Socket.set_broadcast
Section titled “Socket.set_broadcast”pub set_broadcast :: fn(self: *Self, on: bool) -> void ! NetErrorallow sending to broadcast addresses (UDP)
Socket.set_recv_timeout
Section titled “Socket.set_recv_timeout”pub set_recv_timeout :: fn(self: *Self, ms: i32) -> void ! NetErrorms, 0 = block forever; a blocking recv then fails instead of hanging
Socket.set_send_timeout
Section titled “Socket.set_send_timeout”pub set_send_timeout :: fn(self: *Self, ms: i32) -> void ! NetErrorms, 0 = block forever
Socket.set_nonblocking
Section titled “Socket.set_nonblocking”pub set_nonblocking :: fn(self: *Self, on: bool) -> void ! NetErrornon-blocking calls fail with would_block instead of waiting (os::is_would_block)
Socket.bind_to
Section titled “Socket.bind_to”pub bind_to :: fn(self: *Self, sa: addr::SocketAddr) -> void ! NetErrorservers, or a fixed UDP port
Socket.local_addr
Section titled “Socket.local_addr”pub local_addr :: fn(self: *Self) -> addr::SocketAddr ! NetErrorbound address; resolves the ephemeral port after binding port 0
from_fd
Section titled “from_fd”pub from_fd :: fn(fd: usize) -> Socketwraps an open OS socket, e.g. from accept
pub tcp :: fn() -> Socket ! NetErrorIPv4 TCP stream socket
pub udp :: fn() -> Socket ! NetErrorIPv4 UDP datagram socket