Changeset 4230221


Ignore:
Timestamp:
2008-08-09T23:00:38Z (11 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
a830512
Parents:
280e655
Message:

Added ceiling to auto-reconnect delay, changed the default to 5*3<900 and
added documentation.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • account.c

    r280e655 r4230221  
    235235}
    236236
    237 char *set_eval_account_reconnect_delay( set_t *set, char *value )
     237struct account_reconnect_delay
    238238{
    239239        int start;
    240240        char op;
    241241        int step;
    242        
    243         if( sscanf( value, "%d%c%d", &start, &op, &step ) == 3 &&
    244             step > 0 && ( op == '+' || op == '*' ) )
    245                 return value;
     242        int max;
     243};
     244
     245int account_reconnect_delay_parse( char *value, struct account_reconnect_delay *p )
     246{
     247        memset( p, 0, sizeof( *p ) );
     248        /* A whole day seems like a sane "maximum maximum". */
     249        p->max = 86400;
     250       
     251        /* Format: /[0-9]+([*+][0-9]+(<[0-9+]))/ */
     252        while( *value && isdigit( *value ) )
     253                p->start = p->start * 10 + *value++ - '0';
     254       
     255        /* Sure, call me evil for implementing my own fscanf here, but it's
     256           dead simple and I'm immediately at the next part to parse. */
     257       
     258        if( *value == 0 )
     259                /* If the string ends now, the delay is constant. */
     260                return 1;
     261        else if( *value != '+' && *value != '*' )
     262                /* Otherwise allow either a + or a * */
     263                return 0;
     264       
     265        p->op = *value++;
     266       
     267        /* + or * the delay by this number every time. */
     268        while( *value && isdigit( *value ) )
     269                p->step = p->step * 10 + *value++ - '0';
     270       
     271        if( *value == 0 )
     272                /* Use the default maximum (one day). */
     273                return 1;
     274        else if( *value != '<' )
     275                return 0;
     276       
     277        p->max = 0;
     278        value ++;
     279        while( *value && isdigit( *value ) )
     280                p->max = p->max * 10 + *value++ - '0';
     281       
     282        return p->max > 0;
     283}
     284
     285char *set_eval_account_reconnect_delay( set_t *set, char *value )
     286{
     287        struct account_reconnect_delay p;
     288       
     289        return account_reconnect_delay_parse( value, &p ) ? value : NULL;
     290}
     291
     292int account_reconnect_delay( account_t *a )
     293{
     294        char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" );
     295        struct account_reconnect_delay p;
     296       
     297        if( account_reconnect_delay_parse( setting, &p ) )
     298        {
     299                if( a->auto_reconnect_delay == 0 )
     300                        a->auto_reconnect_delay = p.start;
     301                else if( p.op == '+' )
     302                        a->auto_reconnect_delay += p.step;
     303                else if( p.op == '*' )
     304                        a->auto_reconnect_delay *= p.step;
     305               
     306                if( a->auto_reconnect_delay > p.max )
     307                        a->auto_reconnect_delay = p.max;
     308        }
    246309        else
    247                 return set_eval_int( set, value );
    248 }
    249 
    250 int 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 }
     310        {
     311                a->auto_reconnect_delay = 0;
     312        }
     313       
     314        return a->auto_reconnect_delay;
     315}
  • doc/user-guide/commands.xml

    r280e655 r4230221  
    321321        </bitlbee-setting>
    322322
    323         <bitlbee-setting name="auto_reconnect_delay" type="integer" scope="global">
    324                 <default>300</default>
    325 
    326                 <description>
    327                         <para>
    328                                 Tell BitlBee after how many seconds it should attempt to bring an IM-connection back up after a crash. It's not a good idea to set this value very low, it will cause too much useless traffic when an IM-server is down for a few hours.
     323        <bitlbee-setting name="auto_reconnect_delay" type="string" scope="global">
     324                <default>5*3&lt;900</default>
     325
     326                <description>
     327                        <para>
     328                                Tell BitlBee after how many seconds it should attempt to bring a broken IM-connection back up.
     329                        </para>
     330
     331                        <para>
     332                                This can be one integer, for a constant delay. One can also set it to something like &quot;10*10&quot;, which means wait for ten seconds on the first reconnect, multiply it by ten on every failure. Once successfully connected, this delay is re-set to the initial value. With &lt; you can give a maximum delay.
    329333                        </para>
    330334
  • irc.c

    r280e655 r4230221  
    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_account_reconnect_delay, irc );
     141        set_add( &irc->set, "auto_reconnect_delay", "5*3<900", 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

    r280e655 r4230221  
    294294        user_t *t, *u;
    295295        account_t *a;
     296        int delay;
    296297       
    297298        /* Nested calls might happen sometimes, this is probably the best
     
    333334        }
    334335        else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) &&
    335                  set_getbool( &a->set, "auto_reconnect" ) )
    336         {
    337                 int delay = account_reconnect_delay( a );
    338                
     336                 set_getbool( &a->set, "auto_reconnect" ) &&
     337                 ( delay = account_reconnect_delay( a ) ) > 0 )
     338        {
    339339                imcb_log( ic, "Reconnecting in %d seconds..", delay );
    340340                a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a );
Note: See TracChangeset for help on using the changeset viewer.