Changeset 3923003


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

Restored server-initiated PINGs.

Files:
2 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 )
  • irc_commands.c

    r6761a40 r3923003  
    106106        irc_write( irc, ":%s PONG %s :%s", irc->root->host,
    107107                   irc->root->host, cmd[1]?cmd[1]:irc->root->host );
     108}
     109
     110static void irc_cmd_pong( irc_t *irc, char **cmd )
     111{
     112        /* We could check the value we get back from the user, but in
     113           fact we don't care, we're just happy s/he's still alive. */
     114        irc->last_pong = gettime();
     115        irc->pinging = 0;
    108116}
    109117
     
    517525}
    518526
    519 static void irc_cmd_pong( irc_t *irc, char **cmd )
    520 {
    521         /* We could check the value we get back from the user, but in
    522            fact we don't care, we're just happy he's still alive. */
    523         irc->last_pong = gettime();
    524         irc->pinging = 0;
    525 }
    526 
    527527static void irc_cmd_version( irc_t *irc, char **cmd )
    528528{
     
    568568        { "quit",        0, irc_cmd_quit,        0 },
    569569        { "ping",        0, irc_cmd_ping,        0 },
     570        { "pong",        0, irc_cmd_pong,        IRC_CMD_LOGGED_IN },
    570571        { "join",        1, irc_cmd_join,        IRC_CMD_LOGGED_IN },
    571572        { "names",       1, irc_cmd_names,       IRC_CMD_LOGGED_IN },
     
    588589        { "nickserv",    1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
    589590        { "ns",          1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
    590         { "pong",        0, irc_cmd_pong,        IRC_CMD_LOGGED_IN },
    591591        { "version",     0, irc_cmd_version,     IRC_CMD_LOGGED_IN },
    592592        { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN },
Note: See TracChangeset for help on using the changeset viewer.