From 085d9c368c260bc824ce6b4cc028a13a6c6b9ef2 Mon Sep 17 00:00:00 2001 From: pstratem Date: Sat, 14 Mar 2015 16:38:29 -0700 Subject: [PATCH] fix timeout logic remove broken hex_net_ping_timeout logic use timestamps in lag_check instead of relying on the function being called every 30 seconds use prefs.hex_net_ping_timeout if available fix whitespace fix whitespace --- src/common/hexchat.c | 46 ++++++++++++++++++++++++++------------------ src/common/hexchat.h | 1 + src/common/server.c | 2 ++ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/common/hexchat.c b/src/common/hexchat.c index a76db332..6fc4cce8 100644 --- a/src/common/hexchat.c +++ b/src/common/hexchat.c @@ -257,35 +257,39 @@ lag_check (void) GSList *list = serv_list; unsigned long tim; char tbuf[128]; - time_t now = time (0); - time_t lag; + time_t now = time(NULL); tim = make_ping_time (); + + time_t ping_interval = 15; + time_t ping_timeout = 30; + + if (prefs.hex_net_ping_timeout != 0) + { + ping_timeout = prefs.hex_net_ping_timeout; + ping_interval = ping_timeout/2; + } while (list) { serv = list->data; if (serv->connected && serv->end_of_motd) { - lag = now - serv->ping_recv; - if (prefs.hex_net_ping_timeout != 0 && lag > prefs.hex_net_ping_timeout && lag > 0) - { - sprintf (tbuf, "%" G_GINT64_FORMAT, (gint64) lag); - EMIT_SIGNAL (XP_TE_PINGTIMEOUT, serv->server_session, tbuf, NULL, - NULL, NULL, 0); - if (prefs.hex_net_auto_reconnect) - serv->auto_reconnect (serv, FALSE, -1); - } - else + if(!serv->lag_sent && (now - serv->ping_recv) > ping_interval) { g_snprintf (tbuf, sizeof (tbuf), "LAG%lu", tim); serv->p_ping (serv, "", tbuf); - - if (!serv->lag_sent) - { - serv->lag_sent = tim; - fe_set_lag (serv, -1); - } + serv->lag_sent = tim; + fe_set_lag (serv, -1); + } + + if (prefs.hex_net_ping_timeout != 0 && (now - serv->socket_recv) > ping_timeout) + { + sprintf (tbuf, "%" G_GINT64_FORMAT, (gint64) now - serv->socket_recv); + EMIT_SIGNAL (XP_TE_PINGTIMEOUT, serv->server_session, tbuf, NULL, + NULL, NULL, 0); + if (prefs.hex_net_auto_reconnect) + serv->auto_reconnect (serv, FALSE, -1); } } list = list->next; @@ -366,10 +370,14 @@ hexchat_misc_checks (void) /* this gets called every 1/2 second */ if (count % 2) dcc_check_timeouts (); /* every 1 second */ - if (count >= 60) /* every 30 seconds */ + if (count % 2) /* every 1 second*/ { if (prefs.hex_gui_lagometer) lag_check (); + } + + if (count > 3600) + { count = 0; } diff --git a/src/common/hexchat.h b/src/common/hexchat.h index 652dcf1d..3961feeb 100644 --- a/src/common/hexchat.h +++ b/src/common/hexchat.h @@ -530,6 +530,7 @@ typedef struct server /*time_t connect_time;*/ /* when did it connect? */ unsigned long lag_sent; /* we are still waiting for this ping response*/ time_t ping_recv; /* when we last got a ping reply */ + time_t socket_recv; /* when we last received something from the socket */ time_t away_time; /* when we were marked away */ char *encoding; diff --git a/src/common/server.c b/src/common/server.c index 62ba9540..c78852db 100644 --- a/src/common/server.c +++ b/src/common/server.c @@ -313,6 +313,8 @@ server_read (GIOChannel *source, GIOCondition condition, server *serv) } return TRUE; } + + serv->socket_recv = time (NULL); i = 0;