Skip to content

Commit

Permalink
Add keep_alive_timeout option
Browse files Browse the repository at this point in the history
so library users can adjust the keep_alive response timeout.
  • Loading branch information
greg-freewave committed Jan 16, 2025
1 parent 16413b9 commit e8f73b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/tortoise311/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule Tortoise311.Connection do
:backoff,
:subscriptions,
:keep_alive,
:keep_alive_timeout,
:opts,
:handler
]
Expand All @@ -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()}]
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/tortoise311/package/connect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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

Expand Down

0 comments on commit e8f73b4

Please sign in to comment.