Type Method
connect(to:loop:timeout:)
Connects to a remote SocketAddress.
static func connect(to address: SocketAddress, loop: EventLoop = .shared, timeout: Duration? = nil) async throws -> Socket
Parameters
-
address
-
A pre-built endpoint from SocketAddress.
-
loop
-
The event loop to drive. Defaults to shared.
-
timeout
-
Maximum time to wait for handshake completion. nil (default) waits indefinitely. On expiry the call throws SocketError.timeout; the partially-connected descriptor is closed before the error is thrown.
Return Value
A connected Socket.
Mentioned In
Discussion
Creates a fresh non-blocking TCP socket, calls connect(2), and (for EINPROGRESS) registers an EV_WRITE event to resume the continuation when the kernel completes the handshake — bounded by timeout if provided.
Throws
SocketError.socketCreationFailed(_:) if socket(2) fails; SocketError.connectionFailed(_:) if connect(2) fails with anything other than EINPROGRESS; SocketError.timeout if timeout elapses before the kernel reports write-readiness.