Skip to content

Commit

Permalink
Merge pull request LandSandBoat#6184 from WinterSolstice8/login_keepa…
Browse files Browse the repository at this point in the history
…lives

[login] Add keepalives to TCP sockets
  • Loading branch information
zach2good authored Aug 28, 2024
2 parents f6433d0 + cabc8d9 commit b736713
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/login/handler_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ void handler_session::start()
{
if (socket_.lowest_layer().is_open())
{
// Enable keepalives for long sessions (view_session in particular)
socket_.lowest_layer().set_option(asio::socket_base::keep_alive(true));

socket_.lowest_layer().set_option(asio::detail::socket_option::integer<IPPROTO_TCP, TCP_KEEPINTVL>(5 * 60)); // interval between keepalive
socket_.lowest_layer().set_option(asio::detail::socket_option::integer<IPPROTO_TCP, TCP_KEEPCNT>(10)); // failed keepalives before declaring dead

#ifdef __APPLE__
socket_.lowest_layer().set_option(asio::detail::socket_option::integer<IPPROTO_TCP, TCP_KEEPALIVE>(5 * 60)); // secs before keepalive probes
#else
socket_.lowest_layer().set_option(asio::detail::socket_option::integer<IPPROTO_TCP, TCP_KEEPIDLE>(5 * 60)); // secs before keepalive probes
#endif

do_read();
}
}
Expand Down

0 comments on commit b736713

Please sign in to comment.