# `SmolNet.Socket`
[🔗](https://github.com/ausimian/smolnet/blob/0.7.1/lib/smol_net/socket.ex#L1)

A stable, lightweight identity for a socket owned by a `SmolNet` stack.

Socket values are not processes. Operations are serialized by the stack
process identified in the `:stack` field. The native socket ID and generation
together prevent delayed readiness from addressing a later socket.

# `datagram`

```elixir
@type datagram() :: %{
  source: sockaddr_in() | sockaddr_in6(),
  destination: sockaddr_in() | sockaddr_in6(),
  data: binary(),
  truncated: boolean()
}
```

# `ipv4_address`

```elixir
@type ipv4_address() :: {0..255, 0..255, 0..255, 0..255}
```

# `ipv6_address`

```elixir
@type ipv6_address() ::
  {0..65535, 0..65535, 0..65535, 0..65535, 0..65535, 0..65535, 0..65535,
   0..65535}
```

# `sockaddr_in6`

```elixir
@type sockaddr_in6() :: %{
  :family =&gt; :inet6,
  :addr =&gt; ipv6_address(),
  :port =&gt; 0..65535,
  optional(:flowinfo) =&gt; 0,
  optional(:scope_id) =&gt; 0..4_294_967_295
}
```

# `sockaddr_in`

```elixir
@type sockaddr_in() :: %{family: :inet, addr: ipv4_address(), port: 0..65535}
```

# `t`

```elixir
@type t() :: %SmolNet.Socket{
  family: :inet | :inet6,
  generation: pos_integer(),
  id: pos_integer(),
  kind: :stream | :datagram,
  stack: pid()
}
```

# `cancel`

```elixir
@spec cancel(t(), :socket.select_info()) ::
  :ok | :already_sent | :not_found | {:error, :closed | :invalid_socket}
```

Cancels the exact pending operation described by `select_info`.

Returns `:ok` when the waiter was removed, `:already_sent` when its one-shot
readiness notification won the race, or `:not_found` when the reference does
not identify the pending operation.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
