src/keep_alive.c
/** refresh timeout for client (new or already monitored) */
refresh timeout for client (new or already monitored)
refresh timeout for client ( new or already monitored )
void ka_update(keep_alive_st *ka, client_st *pc, time_t now)
{
    int rv;
    int interval;
    int hash_value_1, hash_value_2;
    LOG_DEBUG("ka_update sd %d, ka %d", pc->sd, pc->keep_alive);
    if (pc->keep_alive == 0)
        return;
    if (pc->last_ka_update_at == now) {
        return;
    }
    if (pc->ka_node.p) {
        hash_value_1 = HASH_VALUE(pc->expires_at);
        dllist_remove_ref(&ka->hash_table[hash_value_1], &pc->ka_node);
    }
    else {
        hash_value_1 = -1;
        pc->ka_node.p = pc;
        ++ka->cnt;
    }
    interval = pc->keep_alive + (pc->keep_alive + 1) / 2;
    pc->expires_at = now + interval;
    hash_value_2 = HASH_VALUE(pc->expires_at);
    dllist_insert_head(&ka->hash_table[hash_value_2], &pc->ka_node);
    pc->last_ka_update_at = now;
    LOG_DEBUG("ka_update sd %d, h1 %d %d, h2 %d %d, cnt %d, interval %d",
            pc->sd,
            hash_value_1, hash_value_1 == -1 ? 0 : dllist_count(ka->hash_table[hash_value_1]),
            hash_value_2, dllist_count(ka->hash_table[hash_value_2]),
            ka->cnt, interval);
}
void ka_update ( keep_alive_st * ka , client_st * pc , time_t now ) { int rv ; int interval ; int hash_value_1 , hash_value_2 ; LOG_DEBUG ( " " , pc -> sd , pc -> keep_alive ) ; if ( pc -> keep_alive == 0 ) return ; if ( pc -> last_ka_update_at == now ) { return ; } if ( pc -> ka_node . p ) { hash_value_1 = HASH_VALUE ( pc -> expires_at ) ; dllist_remove_ref ( & ka -> hash_table [ hash_value_1 ] , & pc -> ka_node ) ; } else { hash_value_1 = -1 ; pc -> ka_node . p = pc ; ++ ka -> cnt ; } interval = pc -> keep_alive + ( pc -> keep_alive + 1 ) / 2 ; pc -> expires_at = now + interval ; hash_value_2 = HASH_VALUE ( pc -> expires_at ) ; dllist_insert_head ( & ka -> hash_table [ hash_value_2 ] , & pc -> ka_node ) ; pc -> last_ka_update_at = now ; LOG_DEBUG ( " " , pc -> sd , hash_value_1 , hash_value_1 == -1 ? 0 : dllist_count ( ka -> hash_table [ hash_value_1 ] ) , hash_value_2 , dllist_count ( ka -> hash_table [ hash_value_2 ] ) , ka -> cnt , interval ) ; }
refresh timeout for client (new or already monitored)
refresh timeout for client ( new or already monitored )
/* optimize for bursty pattern */