Skip to content

Commit

Permalink
use :inet.monitor/1
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Nov 10, 2024
1 parent 29d954b commit f04164d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/ch/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,12 @@ defmodule Ch.Connection do
mint_opts = [mode: :passive] ++ Keyword.take(opts, [:hostname, :transport_opts])

with {:ok, conn} <- HTTP.connect(scheme, address, port, mint_opts) do
monitor_ref = monitor_socket(conn.socket)

conn =
conn
|> HTTP.put_private(:timeout, opts[:timeout] || :timer.seconds(15))
|> HTTP.put_private(:monitor, monitor_ref)
|> maybe_put_private(:database, opts[:database])
|> maybe_put_private(:username, opts[:username])
|> maybe_put_private(:password, opts[:password])
Expand Down Expand Up @@ -459,4 +462,15 @@ defmodule Ch.Connection do
conn
end
end

# TODO use ssl_record.hrl
defp monitor_socket({:sslsocket, tcp_socket, _}) do
# TODO support :socket
{:gen_tcp, socket, _, _} = tcp_socket
:inet.monitor(socket)
end

defp monitor_socket(socket) do
:inet.monitor(socket)
end
end

0 comments on commit f04164d

Please sign in to comment.