30 lines
610 B
Elixir
30 lines
610 B
Elixir
|
defmodule Floof do
|
||
|
@moduledoc """
|
||
|
Documentation for `Floof`.
|
||
|
"""
|
||
|
|
||
|
require Logger
|
||
|
|
||
|
def accept(port) do
|
||
|
{:ok, socket} = :gen_tcp.listen(port, [
|
||
|
:binary,
|
||
|
packet: 4,
|
||
|
active: false,
|
||
|
reuseaddr: true
|
||
|
])
|
||
|
Logger.info("Accepting connections on #{port}")
|
||
|
loop_acceptor(socket)
|
||
|
end
|
||
|
|
||
|
def loop_acceptor(socket) do
|
||
|
{:ok, client} = :gen_tcp.accept(socket)
|
||
|
{:ok, pid} = Task.Supervisor.start_child(
|
||
|
Floof.TaskSupervisor, fn -> serve(client) end)
|
||
|
:ok = :gen_tcp.controlling_process(client, pid)
|
||
|
loop_acceptor(socket)
|
||
|
end
|
||
|
|
||
|
def serve(_) do
|
||
|
end
|
||
|
end
|