<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Event",
  "identifier" : "/documentation/Event/Socket/write(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Event"
    ],
    "preciseIdentifier" : "s:5Event6SocketC5writeyy10Foundation4DataVYaKF"
  },
  "title" : "write(_:)"
}
-->

# write(_:)

Writes all bytes in `data` to the socket, awaiting write-readiness.

```
func write(_ data: Data) async throws
```

## Parameters

`data`

The bytes to send.

## 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 <doc://Event/documentation/Event/ProductionConsiderations>.

> Throws: ``doc://Event/documentation/Event/SocketError/writeFailed(_:)`` with the errno payload if
> `write(2)` returns a negative value (e.g. `EPIPE` when the peer closed).