struct Server [src]

Fields

listen_address: Address
stream: std.net.Stream

Members

Source

pub const Server = struct { listen_address: Address, stream: std.net.Stream, pub const Connection = struct { stream: std.net.Stream, address: Address, }; pub fn deinit(s: *Server) void { s.stream.close(); s.* = undefined; } pub const AcceptError = posix.AcceptError; /// Blocks until a client connects to the server. The returned `Connection` has /// an open stream. pub fn accept(s: *Server) AcceptError!Connection { var accepted_addr: Address = undefined; var addr_len: posix.socklen_t = @sizeOf(Address); const fd = try posix.accept(s.stream.handle, &accepted_addr.any, &addr_len, posix.SOCK.CLOEXEC); return .{ .stream = .{ .handle = fd }, .address = accepted_addr, }; } }