Packages
thousand_island
0.5.0
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/connection.ex
defmodule ThousandIsland.Connection do
@moduledoc false
def start(sup_pid, transport_socket, acceptor_id, %ThousandIsland.ServerConfig{
transport_module: transport_module,
handler_module: handler_module,
handler_opts: handler_opts
}) do
connection_id = unique_id()
# This is a multi-step process since we need to do a bit of work from within
# the process which owns the socket (us, at this point).
# Start by creating the worker process which will eventually handle this socket
{:ok, pid} = DynamicSupervisor.start_child(sup_pid, {handler_module, handler_opts})
# Since this process owns the socket at this point, it needs to be the
# one to make this call. connection_pid is sitting and waiting for the
# word from us to start processing, in order to ensure that we've made
# the following call. Note that we purposefully do not match on the
# return from this function; if there's an error the connection process
# will see it, but it's no longer our problem if that's the case
transport_module.controlling_process(transport_socket, pid)
# Now that we have transferred ownership over to the new process, create a Socket
# struct and send it to the new process via a message so it can start working
# with the socket (note that the new process will still need to handshake with the remote end)
socket =
ThousandIsland.Socket.new(transport_socket, transport_module, connection_id, acceptor_id)
Process.send(pid, {:thousand_island_ready, socket}, [])
end
defp unique_id, do: Base.encode16(:crypto.strong_rand_bytes(6))
end