Instance Method
read(maxBytes:timeout:)
Reads up to maxBytes bytes from the socket, awaiting readiness.
func read(maxBytes: Int = 4096, timeout: Duration? = nil) async throws -> Data
Parameters
-
maxBytes
-
Requested maximum byte count (ignored today; see note).
-
timeout
-
Maximum time to wait for readability. nil (default) waits indefinitely. On expiry the call throws SocketError.timeout and the socket remains usable for retry.
Return Value
The data read from the socket.
Mentioned In
Discussion
Registers an EV_READ event and drives the loop until the descriptor is readable, then issues a single read(2) syscall.
Important
The maxBytes parameter is currently advisory — the internal buffer is fixed at 4096 bytes regardless. This is a known limitation; the parameter is preserved for ABI stability so a future release can honor it without breaking callers.
Throws
SocketError.connectionClosed on orderly peer shutdown (read(2) returns 0), SocketError.readFailed(_:) with the errno payload on transport failure, or SocketError.timeout if timeout elapses before data arrives.