Changeset e132b60 for protocols


Ignore:
Timestamp:
2012-11-11T23:32:47Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
67ebc8e
Parents:
dd672e2
Message:

Extend keepalive code to time out connections when pings don't get
acknowledged, using this for Twitter streams and MSN so far.

Location:
protocols
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    rdd672e2 re132b60  
    5353       
    5454        ic->proto_data = md;
     55        ic->flags |= OPT_PONGS | OPT_PONGED;
    5556       
    5657        if( strchr( acc->user, '@' ) == NULL )
  • protocols/msn/ns.c

    rdd672e2 re132b60  
    576576                if( num_parts >= 7 )
    577577                        handler->msglen = atoi( cmd[6] );
     578        }
     579        else if( strcmp( cmd[0], "QNG" ) == 0 )
     580        {
     581                ic->flags |= OPT_PONGED;
    578582        }
    579583        else if( isdigit( cmd[0][0] ) )
  • protocols/nogaim.c

    rdd672e2 re132b60  
    261261        struct im_connection *ic = d;
    262262       
     263        if( ( ic->flags & OPT_PONGS ) && !( ic->flags & OPT_PONGED ) )
     264        {
     265                /* This protocol is expected to ack keepalives and hasn't
     266                   since the last time we were here. */
     267                imcb_error( ic, "Connection timeout" );
     268                imc_logout( ic, TRUE );
     269                return FALSE;
     270        }
     271        ic->flags &= ~OPT_PONGED;
     272       
    263273        if( ic->acc->prpl->keepalive )
    264274                ic->acc->prpl->keepalive( ic );
    265275       
    266276        return TRUE;
     277}
     278
     279void start_keepalives( struct im_connection *ic, int interval )
     280{
     281        b_event_remove( ic->keepalive );
     282        ic->keepalive = b_timeout_add( interval, send_keepalive, ic );
     283       
     284        /* Connecting successfully counts as a first successful pong. */
     285        if( ic->flags & OPT_PONGS )
     286                ic->flags |= OPT_PONGED;
    267287}
    268288
     
    277297        imcb_log( ic, "Logged in" );
    278298       
    279         b_event_remove( ic->keepalive );
    280         ic->keepalive = b_timeout_add( 60000, send_keepalive, ic );
    281299        ic->flags |= OPT_LOGGED_IN;
     300        if( !ic->keepalive )
     301                start_keepalives( ic, 60000 );
    282302       
    283303        /* Necessary to send initial presence status, even if we're not away. */
  • protocols/nogaim.h

    rdd672e2 re132b60  
    6868#define OPT_THINKING    0x00000200 /* about these values... Stupid me! */
    6969#define OPT_NOOTR       0x00001000 /* protocol not suitable for OTR */
     70#define OPT_PONGS       0x00010000 /* Service sends us keep-alives */
     71#define OPT_PONGED      0x00020000 /* Received a keep-alive during last interval */
    7072
    7173/* ok. now the fun begins. first we create a connection structure */
  • protocols/twitter/twitter.c

    rdd672e2 re132b60  
    7272                   us the rest. \o/ */
    7373                twitter_open_stream(ic);
     74                ic->flags |= OPT_PONGS;
    7475        } else {
    7576                /* Not using the streaming API, so keep polling the old-
  • protocols/twitter/twitter_lib.c

    rdd672e2 re132b60  
    740740                return;
    741741       
     742        ic->flags |= OPT_PONGED;
    742743        td = ic->proto_data;
    743744       
Note: See TracChangeset for help on using the changeset viewer.