Instance Method
write(_:)
Writes all bytes in data to the socket, awaiting write-readiness.
func write(_ data: Data) async throws
Parameters
-
data
-
The bytes to send.
Mentioned In
Discussion
Registers an EV_WRITE event and drives the loop until the descriptor is writable, then issues a single write(2) syscall covering the full buffer.
Warning
This implementation does not handle partial writes — if the kernel accepts fewer bytes than requested the remainder is silently discarded (the callback just reports success). In practice, small writes on connected TCP sockets complete in one syscall on all supported platforms, but callers writing large buffers should chunk explicitly until the planned backpressure helper lands. See Production Considerations.
Throws
SocketError.writeFailed(_:) with the errno payload if write(2) returns a negative value (e.g. EPIPE when the peer closed).