Changeset 280e655


Ignore:
Timestamp:
2008-08-05T23:07:07Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
4230221
Parents:
d84e2a9
Message:

Simple exponential backoff code. Have to add a maximum delay setting,
something like 5*5<300: 5s, multiply by 5 on each failure, but stop
increasing once we hit 5m.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • account.c

    rd84e2a9 r280e655  
    234234        }
    235235}
     236
     237char *set_eval_account_reconnect_delay( set_t *set, char *value )
     238{
     239        int start;
     240        char op;
     241        int step;
     242       
     243        if( sscanf( value, "%d%c%d", &start, &op, &step ) == 3 &&
     244            step > 0 && ( op == '+' || op == '*' ) )
     245                return value;
     246        else
     247                return set_eval_int( set, value );
     248}
     249
     250int account_reconnect_delay( account_t *a )
     251{
     252        char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" );
     253        int start, step;
     254        char op;
     255       
     256        if( sscanf( setting, "%d%c%d", &start, &op, &step ) == 3 && step > 0 )
     257        {
     258                if( a->auto_reconnect_delay == 0 )
     259                        return a->auto_reconnect_delay = start;
     260                else if( op == '+' )
     261                        return a->auto_reconnect_delay += step;
     262                else if( op == '*' )
     263                        return a->auto_reconnect_delay *= step;
     264        }
     265        else if( sscanf( setting, "%d", &start ) == 1 )
     266        {
     267                return a->auto_reconnect_delay = start;
     268        }
     269       
     270        return 0;
     271}
  • account.h

    rd84e2a9 r280e655  
    3535       
    3636        int auto_connect;
     37        int auto_reconnect_delay;
    3738        int reconnect;
    3839       
     
    5253
    5354char *set_eval_account( set_t *set, char *value );
     55char *set_eval_account_reconnect_delay( set_t *set, char *value );
     56int account_reconnect_delay( account_t *a );
    5457
    5558#define ACC_SET_NOSAVE          1
  • irc.c

    rd84e2a9 r280e655  
    139139        set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );
    140140        set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc );
    141         set_add( &irc->set, "auto_reconnect_delay", "300", set_eval_int, irc );
     141        set_add( &irc->set, "auto_reconnect_delay", "300", set_eval_account_reconnect_delay, irc );
    142142        set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
    143143        set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
  • protocols/nogaim.c

    rd84e2a9 r280e655  
    267267           protocols. */
    268268        imc_set_away( ic, u->away );
     269       
     270        /* Apparently we're connected successfully, so reset the
     271           exponential backoff timer. */
     272        ic->acc->auto_reconnect_delay = 0;
    269273}
    270274
     
    331335                 set_getbool( &a->set, "auto_reconnect" ) )
    332336        {
    333                 int delay = set_getint( &irc->set, "auto_reconnect_delay" );
     337                int delay = account_reconnect_delay( a );
    334338               
    335339                imcb_log( ic, "Reconnecting in %d seconds..", delay );
Note: See TracChangeset for help on using the changeset viewer.