Type Method
listen(on:backlog:loop:)
Creates a listening server socket bound to a specific SocketAddress.
static func listen(on address: SocketAddress, backlog: Int32 = 128, loop: EventLoop = .shared) async throws -> ServerSocket
Parameters
-
address
-
The local endpoint to bind. Only IPv4 is currently supported — passing an IPv6 address will succeed at bind time only if the caller has previously coerced the kernel’s AF_INET socket to accept it (generally not recommended; IPv6 server support is a future enhancement).
-
backlog
-
The listen(2) backlog size.
-
loop
-
The event loop to drive.
Return Value
A ServerSocket ready to accept connections.
Mentioned In
Discussion
Applies SO_REUSEADDR before bind(2) so that restart-after-crash doesn’t block on TIME_WAIT sockets. On failure, closes the allocated fd before throwing, so no descriptor leaks (constitution Principle II).
Throws
SocketError.socketCreationFailed(_:), SocketError.bindFailed(_:), or SocketError.listenFailed(_:).