diff options
Diffstat (limited to 'lib/irc/connection_socket.ex')
-rw-r--r-- | lib/irc/connection_socket.ex | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/irc/connection_socket.ex b/lib/irc/connection_socket.ex index 29c42c0..d7169fd 100644 --- a/lib/irc/connection_socket.ex +++ b/lib/irc/connection_socket.ex @@ -11,10 +11,10 @@ defmodule Irc.ConnectionSocket do @type t :: {ConnectionSocket, pid(), reference()} - @spec connect(tls :: boolean, host :: String.t, port :: Integer.t, options :: Keyword.t) :: {:ok, t} | {:error, error} - def connect(tls, host, port, options) do + @spec connect(tls :: boolean, host :: String.t, port :: Integer.t, options :: Keyword.t, module()) :: {:ok, t} | {:error, error} + def connect(tls, host, port, options, module) do caller = self() - case GenServer.start(__MODULE__, [caller, tls, host, port, options]) do + case GenServer.start(__MODULE__, [caller, tls, host, port, options, module]) do {:ok, pid} -> mon = Process.monitor(pid) {:ok, {__MODULE__, pid, mon}} @@ -38,10 +38,10 @@ defmodule Irc.ConnectionSocket do end @doc false - def init([caller, tls, host, port, options]) do + def init([caller, tls, host, port, options, caller_module]) do Process.monitor(caller) module = if tls, do: :ssl, else: :gen_tcp - state = %{caller: caller, module: module, host: host, port: port, options: options, socket: nil} + state = %{caller: caller, caller_module: caller_module, module: module, host: host, port: port, options: options, socket: nil} case module.connect(String.to_charlist(host), port, options) do {:ok, socket} -> {:ok, Map.put(state, :socket, socket)} @@ -70,7 +70,7 @@ defmodule Irc.ConnectionSocket do @doc false # Received a line from socket def handle_info({module, socket, line}, state = %{caller: caller, module: module, socket: socket}) do - Kernel.send(caller, {__MODULE__, self(), Line.parse(line)}) + Kernel.send(caller, {__MODULE__, self(), Line.parse(line, state.caller_module, state.caller)}) {:noreply, state} end |