Skip to content

Commit 93174d0

Browse files
authored
Revert handle_info/2 callback (#319)
* Revert "Document handle_info/2 (#317)" This reverts commit 4776530. * Revert "Proxy info messages to the adapter (#316)" This reverts commit 5d088f7.
1 parent 4776530 commit 93174d0

File tree

5 files changed

+5
-145
lines changed

5 files changed

+5
-145
lines changed

examples/tcp_connection/lib/tcp_connection.ex

-17
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ defmodule TCPConnection do
6464

6565
case :gen_tcp.connect(host, port, socket_opts, timeout) do
6666
{:ok, sock} ->
67-
# Monitor the socket so we can react to it being closed. See handle_info/2.
68-
_ref = :inet.monitor(sock)
6967
{:ok, {sock, <<>>}}
7068

7169
{:error, reason} ->
@@ -145,21 +143,6 @@ defmodule TCPConnection do
145143
end
146144
end
147145

148-
# The handle_info callback is optional and can be removed if not needed.
149-
# Here it is used to react to `:inet.monitor/1` messages which arrive
150-
# when socket gets closed while the connection is idle.
151-
def handle_info({:DOWN, _ref, _type, sock, _info}, {sock, _buffer}) do
152-
{:disconnect, TCPConnection.Error.exception({:idle, :closed})}
153-
end
154-
155-
def handle_info(msg, state) do
156-
Logger.info(fn ->
157-
["#{__MODULE__} (", inspect(self()), ") missed message: ", inspect(msg)]
158-
end)
159-
160-
:ok
161-
end
162-
163146
@impl true
164147
def handle_close(_, _, s) do
165148
{:ok, nil, s}

integration_test/cases/info_test.exs

-100
This file was deleted.

lib/db_connection.ex

-9
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,6 @@ defmodule DBConnection do
362362
"""
363363
@callback disconnect(err :: Exception.t(), state :: any) :: :ok
364364

365-
@doc """
366-
Optional callback for handling messages received by the connection.
367-
368-
Returns `{:disconnect, exception}` to close the connection or `:ok` to continue.
369-
"""
370-
@callback handle_info(message :: any, state :: any) :: {:disconnect, Exception.t()} | :ok
371-
372-
@optional_callbacks handle_info: 2
373-
374365
@connection_module_key :connection_module
375366

376367
@doc """

lib/db_connection/connection.ex

+5-15
Original file line numberDiff line numberDiff line change
@@ -330,22 +330,12 @@ defmodule DBConnection.Connection do
330330
handle_timeout(s)
331331
end
332332

333-
def handle_event(:info, msg, :no_state, %{mod: mod, state: state} = s) do
334-
if function_exported?(mod, :handle_info, 2) do
335-
case apply(mod, :handle_info, [msg, state]) do
336-
:ok ->
337-
handle_timeout(s)
338-
339-
{:disconnect, err} ->
340-
{:keep_state, s, {:next_event, :internal, {:disconnect, {:log, err}}}}
341-
end
342-
else
343-
Logger.info(fn ->
344-
[inspect(mod), ?\s, ?(, inspect(self()), ") missed message: " | inspect(msg)]
345-
end)
333+
def handle_event(:info, msg, :no_state, %{mod: mod} = s) do
334+
Logger.info(fn ->
335+
[inspect(mod), ?\s, ?(, inspect(self()), ") missed message: " | inspect(msg)]
336+
end)
346337

347-
handle_timeout(s)
348-
end
338+
handle_timeout(s)
349339
end
350340

351341
@doc false

test/test_support.exs

-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ defmodule TestConnection do
150150
TestAgent.eval(:handle_deallocate, [query, cursor, opts, state])
151151
end
152152

153-
def handle_info(message, state) do
154-
TestAgent.eval(:handle_info, [message, state])
155-
end
156-
157153
defp put_agent_from_opts(opts) do
158154
Process.get(:agent) || Process.put(:agent, agent_from_opts(opts))
159155
end

0 commit comments

Comments
 (0)