<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Event",
  "identifier" : "/documentation/Event/SocketError",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Event"
    ],
    "preciseIdentifier" : "s:5Event11SocketErrorO"
  },
  "title" : "SocketError"
}
-->

# SocketError

An error surfaced by [`SocketAddress`](/documentation/Event/SocketAddress), [`Socket`](/documentation/Event/Socket), and [`ServerSocket`](/documentation/Event/ServerSocket) operations.

```
enum SocketError
```

## Overview

`SocketError` is the sole error type thrown by the idiomatic [`Event`](/documentation/Event) API for TCP
I/O and address parsing. Every case carries either a user-supplied string (for
input-validation failures) or the raw `errno` value captured at the point of failure,
so callers can disambiguate transient conditions (e.g. `EINPROGRESS`, `EAGAIN`) from
permanent failures (e.g. `ECONNREFUSED`).

### Interpreting the errno payload

The `Int32` payload attached to `.connectionFailed`, `.bindFailed`, `.listenFailed`,
`.acceptFailed`, `.readFailed`, `.writeFailed`, and `.socketCreationFailed` is the
value of `errno` immediately after the failing `connect(2)` / `bind(2)` / `listen(2)` /
`accept(2)` / `read(2)` / `write(2)` / `socket(2)` syscall. It is **not** a POSIX
abstraction — it is the platform’s raw errno. To render a human-readable string, pass
it through `strerror(_:)`; the default [`errorDescription`](/documentation/Event/SocketError/errorDescription) does this for you.

### When each case is thrown

- ``doc://Event/documentation/Event/SocketError/invalidAddress(_:)`` — ``doc://Event/documentation/Event/SocketAddress/ipv4(_:port:)`` or
  ``doc://Event/documentation/Event/SocketAddress/ipv6(_:port:)`` rejected the input string. The payload is the
  original host string.
- ``doc://Event/documentation/Event/SocketError/socketCreationFailed(_:)`` — `socket(2)` failed inside
  ``doc://Event/documentation/Event/Socket/connect(to:port:loop:)`` or ``doc://Event/documentation/Event/Socket/listen(port:backlog:loop:)``.
- ``doc://Event/documentation/Event/SocketError/connectionFailed(_:)`` — `connect(2)` returned a non-`EINPROGRESS`
  error, or the socket’s pending-write event reported failure.
- ``doc://Event/documentation/Event/SocketError/bindFailed(_:)`` / ``doc://Event/documentation/Event/SocketError/listenFailed(_:)`` — server-socket
  setup failed after socket creation.
- ``doc://Event/documentation/Event/SocketError/acceptFailed(_:)`` — `accept(2)` on a ``doc://Event/documentation/Event/ServerSocket`` returned a
  negative value.
- ``doc://Event/documentation/Event/SocketError/readFailed(_:)`` / ``doc://Event/documentation/Event/SocketError/writeFailed(_:)`` — the underlying
  `read(2)` / `write(2)` returned a negative value.
- ``doc://Event/documentation/Event/SocketError/connectionClosed`` — `read(2)` returned 0 (orderly shutdown by peer).
- ``doc://Event/documentation/Event/SocketError/timeout`` — reserved for future timeout-based APIs; not emitted today.

> SeeAlso: <doc://Event/documentation/Event/ProductionConsiderations> for the current caveat list, including
> behaviors not yet wrapped (UDP, TLS, timeouts, cancellation).