Adding a TCP port to a supervision tree

Because ports behave like processes I am assuming it should be possible to link to them.
I am trying to add a listen socket to a supervision tree.

To test how to link to the processes I have been trying to inspect an exit message, however for some reason the port is not generating exit messages. So maybe I have miss understood that in this case ports are not quite like processes.

Sorry for all the inspect statements but it shows what I have been looking at

test "scratchpad" do
    me = self()
    t = Task.async fn () ->
      {:ok, listen_socket} = :gen_tcp.listen(8090, mode: :binary) |> IO.inspect
      send(me, {:lsock, listen_socket})
      receive do
        exit_message -> exit_message |> IO.inspect
    lsock = receive do
      {:lsock, s} ->
    end |> IO.inspect
    |> IO.inspect |> IO.inspect
    assert_receive task_complete_message, 1_000

In this test I would expect that when the test closes the socket that the task process receives an exit message which then allows the task to complete sending a task completed message to the test process.

1 Like

I was missing this line before

:erlang.process_flag(:trap_exit, true)

1 Like