warden/lib/server/connection/conn.ex
2025-01-03 16:50:52 -08:00

35 lines
674 B
Elixir

defmodule Server.Conn do
require Logger
use GenServer
@impl true
def init(_args) do
initial_state = %{"num_conns" => 0}
{:ok, initial_state}
end
@impl true
def handle_call(_socket, _from, _state) do
throw("call is unimplementedd")
end
@impl true
def handle_cast(socket, state) do
spawn(handle(socket))
%{"num_conns" => state.num_conns + 1}
end
defp handle(socket) do
case :gen_tcp.recv(socket, 1024) do
{:ok, packet} ->
Logger.debug("[Server.Conn] packet #{packet}")
{:error, reason} ->
Logger.error("[Server.Conn] failed to read connection: #{reason}")
end
handle(socket)
end
end