diff --git a/lib/tortoise311/connection.ex b/lib/tortoise311/connection.ex index 4431940..3fccf3d 100644 --- a/lib/tortoise311/connection.ex +++ b/lib/tortoise311/connection.ex @@ -22,6 +22,7 @@ defmodule Tortoise311.Connection do :backoff, :subscriptions, :keep_alive, + :keep_alive_timeout, :opts, :handler ] @@ -39,6 +40,7 @@ defmodule Tortoise311.Connection do | {:user_name, String.t()} | {:password, String.t()} | {:keep_alive, non_neg_integer()} + | {:keep_alive_timeout, non_neg_integer()} | {:will, Tortoise311.Package.Publish.t()} | {:subscriptions, [{Tortoise311.topic_filter(), Tortoise311.qos()}] @@ -57,6 +59,7 @@ defmodule Tortoise311.Connection do user_name: Keyword.get(connection_opts, :user_name), password: Keyword.get(connection_opts, :password), keep_alive: Keyword.get(connection_opts, :keep_alive, 60), + keep_alive_timeout: Keyword.get(connection_opts, :keep_alive_timeout, 5) * 1000, will: Keyword.get(connection_opts, :will), # if we re-spawn from here it means our state is gone clean_session: Keyword.get(connection_opts, :clean_session, true) @@ -493,7 +496,7 @@ defmodule Tortoise311.Connection do end def handle_info(:ping, %State{} = state) do - case Controller.ping_sync(state.connect.client_id, 5000) do + case Controller.ping_sync(state.connect.client_id, state.connect.keep_alive_timeout) do {:ok, round_trip_time} -> Events.dispatch(state.connect.client_id, :ping_response, round_trip_time) state = reset_keep_alive(state) diff --git a/lib/tortoise311/package/connect.ex b/lib/tortoise311/package/connect.ex index 62e95b1..f006bd8 100644 --- a/lib/tortoise311/package/connect.ex +++ b/lib/tortoise311/package/connect.ex @@ -13,6 +13,7 @@ defmodule Tortoise311.Package.Connect do password: binary() | nil, clean_session: boolean(), keep_alive: non_neg_integer(), + keep_alive_timeout: non_neg_integer(), client_id: Tortoise311.client_id(), will: Package.Publish.t() | nil } @@ -25,6 +26,7 @@ defmodule Tortoise311.Package.Connect do password: nil, clean_session: true, keep_alive: 60, + keep_alive_timeout: 5000, client_id: nil, will: nil