# `AVModbus.Server.TCP`
[🔗](https://github.com/piyopiyoex/avmodbus/blob/v0.1.0/lib/avmodbus/server/tcp.ex#L1)

Modbus TCP listener と client connection を管理する server です。

connection ごとに独立した process が fragmented / concatenated MBAP stream を処理し、
同じ connection の request は順番に、異なる connection は並行して処理します。
socket owner は handler の完了を待たず受信を続け、worker へ未配送の broker buffer を
`:max_buffer` で制限します。active socket mailbox、worker が処理中の data、runtime の
socket buffer はこの値に含みません。
request semantics、handler isolation、authorization、device identification は
`AVModbus.Server` と共有します。

# `option`

```elixir
@type option() ::
  {:port, 0..65535}
  | {:address, :inet.ip_address()}
  | {:connections, pos_integer()}
  | {:idle, pos_integer() | :infinity}
  | {:handler_timeout, pos_integer() | :infinity}
  | {:max_buffer, pos_integer()}
  | {:allow, nil | [term()]}
  | {:authorize, AVModbus.Server.authorize() | nil}
  | {:identification, AVModbus.Server.Identification.objects() | nil}
  | {:name, atom()}
```

# `server`

```elixir
@type server() :: pid() | atom()
```

# `port`

```elixir
@spec port(server()) :: 0..65535
```

server が listen している port を返します。port `0` で起動した場合にも利用できます。

# `start_link`

```elixir
@spec start_link(AVModbus.Server.handler(), [option()]) ::
  {:ok, pid()} | {:error, term()}
```

TCP port を listen して server を起動します。

# `status`

```elixir
@spec status(server()) :: {:listening, non_neg_integer()}
```

listener state と現在の connection 数を返します。

# `stop`

```elixir
@spec stop(server()) :: :ok
```

listener と connection を閉じて server を停止します。

---

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