aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/nogaim.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2012-11-11 23:32:47 +0000
committerWilmer van der Gaast <wilmer@gaast.net>2012-11-11 23:32:47 +0000
commite132b60e77f395463cf95dc4ee09e96e9658ae35 (patch)
tree24a387ad64eaee17589b61cabaded508477b598f /protocols/nogaim.c
parentdd672e2c4d0dcf73a30be3d8f7fc2ec38cb6450e (diff)
Extend keepalive code to time out connections when pings don't get
acknowledged, using this for Twitter streams and MSN so far.
Diffstat (limited to 'protocols/nogaim.c')
-rw-r--r--protocols/nogaim.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index 773e3877..744f73ad 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -260,12 +260,32 @@ static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond )
{
struct im_connection *ic = d;
+ if( ( ic->flags & OPT_PONGS ) && !( ic->flags & OPT_PONGED ) )
+ {
+ /* This protocol is expected to ack keepalives and hasn't
+ since the last time we were here. */
+ imcb_error( ic, "Connection timeout" );
+ imc_logout( ic, TRUE );
+ return FALSE;
+ }
+ ic->flags &= ~OPT_PONGED;
+
if( ic->acc->prpl->keepalive )
ic->acc->prpl->keepalive( ic );
return TRUE;
}
+void start_keepalives( struct im_connection *ic, int interval )
+{
+ b_event_remove( ic->keepalive );
+ ic->keepalive = b_timeout_add( interval, send_keepalive, ic );
+
+ /* Connecting successfully counts as a first successful pong. */
+ if( ic->flags & OPT_PONGS )
+ ic->flags |= OPT_PONGED;
+}
+
void imcb_connected( struct im_connection *ic )
{
/* MSN servers sometimes redirect you to a different server and do
@@ -276,9 +296,9 @@ void imcb_connected( struct im_connection *ic )
imcb_log( ic, "Logged in" );
- b_event_remove( ic->keepalive );
- ic->keepalive = b_timeout_add( 60000, send_keepalive, ic );
ic->flags |= OPT_LOGGED_IN;
+ if( !ic->keepalive )
+ start_keepalives( ic, 60000 );
/* Necessary to send initial presence status, even if we're not away. */
imc_away_send_update( ic );