Skip to content

Commit

Permalink
You know it, you log it.
Browse files Browse the repository at this point in the history
  • Loading branch information
IanLuites committed Aug 11, 2017
1 parent 65ff0af commit 5355e69
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/host_pool/connection_pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ defmodule HostPool.ConnectionPool do
@spec checkout_connection(map, tuple, non_neg_integer, tuple, map) :: tuple
defp checkout_connection(
host = %{items: [socket | items]},
id = {_, _, transport},
id = {hostname, _, transport},
checkout_limit,
{client_pid, _},
from = {client_pid, _},
state
) do
host = Map.put(host, :items, items)
Expand All @@ -125,6 +125,10 @@ defmodule HostPool.ConnectionPool do

{:reply, {:ok, socket}, Map.put(state, id, updated_host)}
else
if hostname == 'example.com' do
IO.puts "#{inspect from}:in: LOST CONNECTION"
end

# cleanup by closing socket
close socket

Expand Down Expand Up @@ -269,21 +273,29 @@ defmodule HostPool.ConnectionPool do

@spec socket_alive?(atom, any) :: boolean
defp socket_alive?(transport, socket) do
with {:ok, _} <- transport.peername(socket) do
# with {:ok, _} <- transport.peername(socket) do
sync_socket(transport, socket)
else
_ -> false
end
# else
# m ->
# IO.puts "Connection closed: #{inspect m}"
# false
# end
end

@spec socket_alive?(atom, any) :: boolean
defp sync_socket(transport, socket) do
{msg, msg_closed, msg_error} = transport.messages(socket)

receive do
{^msg, ^socket, _} -> false
{^msg_closed, ^socket} -> false
{^msg_error, ^socket, _} -> false
m = {^msg, ^socket, _} ->
IO.puts "Connection closed [MSG]: #{inspect m}, #{inspect socket}"
false
m = {^msg_closed, ^socket} ->
IO.puts "Connection closed [MSG_CLOSED]: #{inspect m}, #{inspect socket}"
false
m = {^msg_error, ^socket, _} ->
IO.puts "Connection closed [MSG_ERROR]: #{inspect m}, #{inspect socket}"
false
after
0 -> true
end
Expand Down

0 comments on commit 5355e69

Please sign in to comment.