Added hardcoded autoping timeout

This commit is contained in:
James Booth
2015-12-31 01:48:04 +00:00
parent 08d30a4a83
commit 94b0d2c6da
5 changed files with 81 additions and 12 deletions

View File

@@ -99,6 +99,7 @@ static int _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t
static int _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static gboolean autoping_wait = FALSE;
static GTimer *autoping_time;
void
iq_add_handlers(void)
@@ -125,6 +126,28 @@ iq_add_handlers(void)
}
}
void
iq_autoping_check(void)
{
if (jabber_get_connection_status() != JABBER_CONNECTED) {
return;
}
if (autoping_wait == FALSE) {
return;
}
gdouble elapsed = g_timer_elapsed(autoping_time, NULL);
unsigned long seconds_elapsed = elapsed * 1.0;
log_debug("Autoping check: waiting, %u", seconds_elapsed);
if (seconds_elapsed > 5) {
// disconnect
jabber_ping_fail();
autoping_wait = FALSE;
g_timer_destroy(autoping_time);
}
}
void
iq_set_autoping(const int seconds)
{
@@ -529,6 +552,7 @@ static int
_auto_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata)
{
autoping_wait = FALSE;
g_timer_destroy(autoping_time);
char *id = xmpp_stanza_get_id(stanza);
if (id == NULL) {
@@ -870,6 +894,7 @@ _autoping_timed_handler(xmpp_conn_t *const conn, void *const userdata)
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
autoping_wait = TRUE;
autoping_time = g_timer_new();
return 1;
}