From f04164da69489f069ff8acd8f33ec32519112e7a Mon Sep 17 00:00:00 2001 From: ruslandoga <67764432+ruslandoga@users.noreply.github.com> Date: Sun, 10 Nov 2024 12:30:20 +0700 Subject: [PATCH] use :inet.monitor/1 --- lib/ch/connection.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/ch/connection.ex b/lib/ch/connection.ex index 09ba17e..6925519 100644 --- a/lib/ch/connection.ex +++ b/lib/ch/connection.ex @@ -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]) @@ -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