Changeset 3923003 for irc.c


Ignore:
Timestamp:
2010-03-28T02:49:19Z (10 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
38ee021
Parents:
6761a40
Message:

Restored server-initiated PINGs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    r6761a40 r3923003  
    2828GSList *irc_connection_list;
    2929
     30static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond );
    3031static char *set_eval_charset( set_t *set, char *value );
    3132
     
    8788                myhost = g_strdup( "localhost.localdomain" );
    8889       
    89         //if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
    90         //      irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
     90        if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
     91                irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
    9192
    9293        irc_connection_list = g_slist_append( irc_connection_list, irc );
     
    689690
    690691
     692/* Returns 0 if everything seems to be okay, a number >0 when there was a
     693   timeout. The number returned is the number of seconds we received no
     694   pongs from the user. When not connected yet, we don't ping but drop the
     695   connection when the user fails to connect in IRC_LOGIN_TIMEOUT secs. */
     696static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond )
     697{
     698        irc_t *irc = _irc;
     699        int rv = 0;
     700       
     701        if( !( irc->status & USTATUS_LOGGED_IN ) )
     702        {
     703                if( gettime() > ( irc->last_pong + IRC_LOGIN_TIMEOUT ) )
     704                        rv = gettime() - irc->last_pong;
     705        }
     706        else
     707        {
     708                if( ( gettime() > ( irc->last_pong + global.conf->ping_interval ) ) && !irc->pinging )
     709                {
     710                        irc_write( irc, "PING :%s", IRC_PING_STRING );
     711                        irc->pinging = 1;
     712                }
     713                else if( gettime() > ( irc->last_pong + global.conf->ping_timeout ) )
     714                {
     715                        rv = gettime() - irc->last_pong;
     716                }
     717        }
     718       
     719        if( rv > 0 )
     720        {
     721                irc_abort( irc, 0, "Ping Timeout: %d seconds", rv );
     722                return FALSE;
     723        }
     724       
     725        return TRUE;
     726}
     727
    691728
    692729static char *set_eval_charset( set_t *set, char *value )
Note: See TracChangeset for help on using the changeset viewer.