Packages
thousand_island
1.3.4
1.5.0
1.4.3
1.4.2
1.4.1
1.4.0
1.3.14
1.3.13
1.3.12
1.3.11
1.3.10
1.3.9
1.3.8
1.3.7
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.0
1.1.0
1.0.0
1.0.0-pre.7
1.0.0-pre.6
1.0.0-pre.5
1.0.0-pre.4
1.0.0-pre.3
1.0.0-pre.2
1.0.0-pre.1
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.17
0.5.16
0.5.15
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
A simple & modern pure Elixir socket server
Current section
Files
Jump to
Current section
Files
lib/thousand_island/acceptor_supervisor.ex
defmodule ThousandIsland.AcceptorSupervisor do
@moduledoc false
use Supervisor
@spec start_link({server_pid :: pid, ThousandIsland.ServerConfig.t()}) :: Supervisor.on_start()
def start_link(arg) do
Supervisor.start_link(__MODULE__, arg)
end
@spec connection_sup_pid(Supervisor.supervisor()) :: pid() | nil
def connection_sup_pid(supervisor) do
supervisor
|> Supervisor.which_children()
|> Enum.find_value(fn
{:connection_sup, connection_sup_pid, _, _} when is_pid(connection_sup_pid) ->
connection_sup_pid
_ ->
false
end)
end
@spec suspend(Supervisor.supervisor()) :: :ok | :error
def suspend(pid) do
case Supervisor.terminate_child(pid, :acceptor) do
:ok -> :ok
{:error, :not_found} -> :error
end
end
@spec resume(Supervisor.supervisor()) :: :ok | :error
def resume(pid) do
case Supervisor.restart_child(pid, :acceptor) do
{:ok, _child} -> :ok
{:error, reason} when reason in [:running, :restarting] -> :ok
{:error, _reason} -> :error
end
end
@impl Supervisor
@spec init({server_pid :: pid, ThousandIsland.ServerConfig.t()}) ::
{:ok,
{Supervisor.sup_flags(),
[Supervisor.child_spec() | (old_erlang_child_spec :: :supervisor.child_spec())]}}
def init({server_pid, %ThousandIsland.ServerConfig{} = config}) do
children = [
{DynamicSupervisor, strategy: :one_for_one, max_children: config.num_connections}
|> Supervisor.child_spec(id: :connection_sup),
{ThousandIsland.Acceptor, {server_pid, self(), config}}
|> Supervisor.child_spec(id: :acceptor)
]
Supervisor.init(children, strategy: :rest_for_one)
end
end