Function accept [src]

Blocks until a client connects to the server. The returned Connection has an open stream.

Prototype

pub fn accept(s: *Server) AcceptError!Connection

Parameters

s: *Server

Possible Errors

BlockedByFirewall AcceptError

Firewall rules forbid connection.

ConnectionAborted AcceptError
ConnectionResetByPeer AcceptError

An incoming connection was indicated, but was subsequently terminated by the remote peer prior to accepting the call.

FileDescriptorNotASocket AcceptError

The file descriptor sockfd does not refer to a socket.

NetworkSubsystemFailed AcceptError

The network subsystem has failed.

OperationNotSupported AcceptError

The referenced socket is not a type that supports connection-oriented service.

ProcessFdQuotaExceeded AcceptError

The per-process limit on the number of open file descriptors has been reached.

ProtocolFailure AcceptError
SocketNotListening AcceptError

Socket is not listening for new connections.

SystemFdQuotaExceeded AcceptError

The system-wide limit on the total number of open files has been reached.

SystemResources AcceptError

Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory.

Unexpected UnexpectedError

The Operating System returned an undocumented error code.

This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.

When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.

WouldBlock AcceptError

This error occurs when no global event loop is configured, and accepting from the socket would block.

Source

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, }; }