Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

Server

net.Server
pub const Server = struct

File

lib/std/Io/net.zig:1424

Code

pub const Server = struct {
    socket: Socket,
    options: AcceptOptions,

    pub fn deinit(s: *Server, io: Io) void {
        s.socket.close(io);
        s.* = undefined;
    }

    pub const AcceptError = error{
        /// The per-process limit on the number of open file descriptors has been reached.
        ProcessFdQuotaExceeded,
        /// The system-wide limit on the total number of open files has been reached.
        SystemFdQuotaExceeded,
        /// Not enough free memory. This often means that the memory allocation is limited
        /// by the socket buffer limits, not by the system memory.
        SystemResources,
        /// Either `listen` was never called, or `shutdown` was called (possibly while
        /// this call was blocking). This allows `shutdown` to be used as a concurrent
        /// cancellation mechanism.
        SocketNotListening,
        /// The network subsystem has failed.
        NetworkDown,
        /// No connection is already queued and ready to be accepted, and
        /// the socket is configured as non-blocking.
        WouldBlock,
        /// An incoming connection was indicated, but was subsequently terminated by the
        /// remote peer prior to accepting the call.
        ConnectionAborted,
        /// Firewall rules forbid connection.
        BlockedByFirewall,
        ProtocolFailure,
    } || Io.UnexpectedError || Io.Cancelable;

    pub const AcceptOptions = switch (native_os) {
        .windows => struct { mode: Socket.Mode, protocol: ?Protocol },
        else => void,
    };

    /// Blocks until a client connects to the server.
    pub fn accept(s: *Server, io: Io) AcceptError!Stream {
        return .{ .socket = try io.vtable.netAccept(io.userdata, s.socket.handle, s.options) };
    }
}