Exemplo n.º 1
0
void 
route_delete_obsolete(time_t cur_time)
{   
    int          i, count = 0, timeout;
    hash_node   *hn;
    link_list   *l;
    p_link_node  ln;

    tc_log_info(LOG_NOTICE, 0, "router size:%u", table->total);
#if (INTERCEPT_THREAD)
    pthread_mutex_lock(&mutex);
#endif

    for (i = 0; i < table->size; i++) {

        l  = table->lists[i];
        if (l->size > 0) {
            while (true) {
                ln = link_list_tail(l); 
                if (NULL == ln) {
                    break;
                }       
                hn = (hash_node *)ln->data;
                timeout = table->timeout;
                if (0 == hn->visit_cnt) {
                    /* 
                     * If we have not received the second handshake packet 
                     * for more than 3 seconds,then we clear out router info 
                     */
                    timeout = 3;
                }
                if ((hn->access_time + timeout) < cur_time) {
                    link_list_pop_tail(l);
                    free(hn);
                    ln->data = NULL;
                    free(ln);
                    table->total--;
                    count++;
                } else {
                    break;
                }   
            }
        }
    } 

    tc_log_info(LOG_NOTICE, 0, "router delete obsolete:%d", count);

    delay_table_delete_obsolete(cur_time);

#if (INTERCEPT_THREAD)
    pthread_mutex_unlock(&mutex);
#endif

}
Exemplo n.º 2
0
void
delay_table_delete_obsolete(time_t cur_time)
{
    int          i, count = 0;
    hash_node   *hn1, *hn2;
    link_list   *msg_list, *l;
    p_link_node  ln, tail;

    tc_log_info(LOG_NOTICE, 0, "delay total:%u", table->total);

    for (i = 0; i < table->size; i++) {
        l  = table->lists[i];
        while (true) {

            ln = link_list_tail(l);
            if (ln == NULL) {
                break;
            }   

            hn1 = (hash_node *) ln->data;
            if ( (hn1->access_time + table->timeout) < cur_time) {
                count++;
                table->total--;
                tail = link_list_pop_tail(l);
                hn2  = (hash_node *) tail->data;
                if (hn2 != NULL) {   
                    if (hn2->data != NULL) {
                        msg_list = (link_list *) hn2->data;
                        msg_item_destr_cnt += link_list_clear(msg_list);
                        free(msg_list);     
                        hn2->data = NULL;
                        msg_ls_destr_cnt++;
                    }
                    free(hn2);
                }   
                tail->data = NULL;
                free(tail);
            } else {
                break;
            }   
        } 
    }

    tc_log_info(LOG_NOTICE, 0, "delay delete obsolete :%d", count);
}