From e668c4f7df2b68a8a1efb27e58a8450e18d11d4e Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 22 May 2023 16:58:57 +0200 Subject: [PATCH] Extend autoping timer on each stanza we receive. Sometimes the server is too busy sending other stanzas or our connection is saturated because of something else, so the pong arrives too late. Prevent the autoping disconnect event by extending the timeout each time a stanza is received. Signed-off-by: Steffen Jaeckel --- src/xmpp/iq.c | 10 ++++++++-- src/xmpp/message.c | 1 + src/xmpp/presence.c | 1 + src/xmpp/xmpp.h | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 1e4c272a..dbadd468 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -176,8 +176,7 @@ static int _iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata) { log_debug("iq stanza handler fired"); - - iq_autoping_timer_cancel(); // reset the autoping timer + autoping_timer_extend(); char* text; size_t text_size; @@ -1391,6 +1390,13 @@ _autoping_timed_send(xmpp_conn_t* const conn, void* const userdata) return 1; } +void +autoping_timer_extend(void) +{ + if (autoping_time) + g_timer_start(autoping_time); +} + static int _auto_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata) { diff --git a/src/xmpp/message.c b/src/xmpp/message.c index ad9f545e..e9ee166d 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -153,6 +153,7 @@ static int _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata) { log_debug("Message stanza handler fired"); + autoping_timer_extend(); if (_handled_by_plugin(stanza)) { return 1; diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 36c2f6a9..2b0ae7f7 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -347,6 +347,7 @@ static int _presence_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata) { log_debug("Presence stanza handler fired"); + autoping_timer_extend(); char* text = NULL; size_t text_size; diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 2babe536..cc0b62e7 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -269,6 +269,8 @@ void iq_mam_request_older(ProfChatWin* win); void iq_register_change_password(const char* const user, const char* const password); void iq_muc_register_nick(const char* const roomjid); +void autoping_timer_extend(void); + EntityCapabilities* caps_lookup(const char* const jid); void caps_close(void); void caps_destroy(EntityCapabilities* caps);