Exemplo n.º 1
0
static p_link_node
hash_find_node(hash_table *table, uint64_t key)
{
    hash_node   *hn;
    link_list   *l  = get_link_list(table, key);
    p_link_node  ln  = link_list_first(l);

    table->total_visit++;

    while (ln) {

        hn = (hash_node *)ln->data;
        table->total_key_compared++;
        if (hn->key == key) {
            hn->access_time = time(0);
            hn->visit_cnt++;
            /* Put the lastest item to the head of the linked list */
            (void)link_list_remove(l, ln);
            link_list_push(l, ln);
            return ln;
        }
        ln = link_list_get_next(l, ln);
    }

    return NULL;
}
Exemplo n.º 2
0
static p_link_node
hash_find_node(hash_table *table, uint64_t key)
{
    bool         first = true;
    hash_node   *hn;
    link_list   *l  = get_link_list(table, key);
    p_link_node  ln = link_list_first(l);

    while (ln) {

        hn = (hash_node *) ln->data;
        if (hn->key == key) {
            if (!first) {
                /* put the lastest item to the head of the linked list */
                link_list_remove(l, ln);
                link_list_push(l, ln);
            }
            return ln;
        }
        ln = link_list_get_next(l, ln);
        first = false;
    }

    return NULL;
}
Exemplo n.º 3
0
void
hash_deep_destroy(hash_table *table)
{
    uint32_t      index = 0;
    hash_node    *hn;
    link_list    *l;
    p_link_node   ln, tmp_ln;

    for (; index < table->size; index++) {

        l = table->lists[index];
        if (l != NULL) {
            ln   = link_list_first(l);   
            while (ln) {
                tmp_ln = link_list_get_next(l, ln);
                hn = (hash_node *)ln->data;
                if (hn->data != NULL) {
                    free(hn->data);
                    hn->data = NULL;
                }
                ln = tmp_ln;
            }
        }
    }

    hash_destroy(table);
}
static int 
release_resources(uint64_t key)
{
    link_list          *list;
    p_link_node         ln, tln;
    mysql_table_item_t *item;

    item = hash_find(ctx.table, key);
    if (item != NULL) {
        list = item->list;
        ln   = link_list_first(list);
        while (ln) {
            tln = ln;
            ln = link_list_get_next(list, ln);
            link_list_remove(list, tln);
            tc_pfree(ctx.pool, tln->data);
            tc_pfree(ctx.pool, tln);
        }

        tc_pfree(ctx.pool, item);
        tc_pfree(ctx.pool, list);

        hash_del(ctx.table, ctx.pool, key);
    }

    return TC_OK;
}
Exemplo n.º 5
0
inline p_link_node
link_list_pop_first(link_list *l)
{
    p_link_node first = link_list_first(l);

    if (!first) {
        return first;
    }

    return link_list_remove(l, first);
}
Exemplo n.º 6
0
static void 
address_release()
{   
    int             i, j, fd;
    hash_node      *hn;
    link_list      *list;
    p_link_node     ln, tmp_ln;
    connections_t  *connections;

    if (addr_table == NULL) {
        return;
    }

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

        list = addr_table->lists[i];
        ln   = link_list_first(list);   
        while (ln) {

            tmp_ln = link_list_get_next(list, ln);
            hn = (hash_node *) ln->data;
            if (hn->data != NULL) {

                connections = (connections_t *) hn->data;
                hn->data = NULL;

                for (j = 0; j < connections->num; j++) {
                    fd = connections->fds[j];
                    if (fd > 0) {
                        tc_log_info(LOG_NOTICE, 0, "it close socket:%d", fd);
                        connections->fds[j] = -1;
                        tc_socket_close(fd);
                    }
                }
                free(connections);
            }
            ln = tmp_ln;
        }
    }

    tc_log_info(LOG_NOTICE, 0, "destroy addr table");
    hash_destroy(addr_table);
    free(addr_table);
    addr_table = NULL;

}
Exemplo n.º 7
0
/* destroy delay table */
void
delay_table_destroy()
{
    uint32_t     i;
    link_list   *msg_list, *list;
    hash_node   *hn;
    p_link_node  ln;

    if (table != NULL) {

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

        for (i = 0; i < table->size; i++) {
            list = table->lists[i];
            ln   = link_list_first(list);
            while (ln) {
                hn = (hash_node *) ln->data;
                if (hn->data != NULL) {
                    msg_list = (link_list *) hn->data;
                    msg_item_destr_cnt += link_list_clear(msg_list);
                    free(msg_list);
                    msg_ls_destr_cnt++;
                }   
                hn->data = NULL;
                ln = link_list_get_next(list, ln);
            }
        }

        tc_log_info(LOG_NOTICE, 0, "destroy items:%llu,free:%llu,total:%llu",
                msg_item_destr_cnt, msg_item_free_cnt, msg_item_cnt);
        tc_log_info(LOG_NOTICE, 0, "create msg list:%llu,free:%llu,destr:%llu",
                msg_ls_cnt, msg_ls_free_cnt, msg_ls_destr_cnt);
        tc_log_info(LOG_NOTICE, 0, "delay actual sent:%llu", 
                msg_delay_sent_cnt);


        hash_destroy(table);
        free(table);
        table = NULL;
    }
}
Exemplo n.º 8
0
void 
address_release()
{   
    int          i, fd;
    hash_node   *hn;
    link_list   *list;
    p_link_node  ln, tmp_ln;

    if (addr_table == NULL) {
        return;
    }

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

        list = addr_table->lists[i];
        ln   = link_list_first(list);   
        while (ln) {

            tmp_ln = link_list_get_next(list, ln);
            hn = (hash_node *) ln->data;
            if (hn->data != NULL) {

                fd  = (int) (long) hn->data;
                hn->data = NULL;

                if (fd != 0) {
                    tc_log_info(LOG_NOTICE, 0, "it close socket:%d", fd);
                    close(fd);
                }
            }
            ln = tmp_ln;
        }
    }

    tc_log_info(LOG_NOTICE, 0, "destroy addr table");
    hash_destroy(addr_table);
    free(addr_table);
    addr_table = NULL;

}
static void 
remove_obsolete_resources(int is_full) 
{
    time_t      thresh_access_tme;
    uint32_t    i, cnt = 0;
    link_list  *l;
    hash_node  *hn;
    p_link_node ln, next_ln;

    if (ctx.table == NULL || ctx.table->total == 0) {
        return;
    }

    if (is_full) {
        thresh_access_tme = tc_time() + 1;
    } else {
        thresh_access_tme = tc_time() - MAX_IDLE_TIME;
    }

    for (i = 0; i < ctx.table->size; i ++) {
        l  = get_link_list(ctx.table, i);
        if (l->size > 0) {
            ln = link_list_first(l);
            while (ln) {
                hn = (hash_node *) ln->data;
                next_ln = link_list_get_next(l, ln);
                if (hn->access_time < thresh_access_tme) {
                    release_resources(hn->key);
                }
                ln = next_ln;
            }
            
            cnt += l->size;

            if (ctx.table->total == cnt) {
                break;
            }
        }
    }
}
static int 
prepare_for_renew_session(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
{
    uint16_t            size_ip;
    uint32_t            tot_clen, base_seq;
    tc_iph_t           *fir_ip, *t_ip;
    tc_tcph_t          *fir_tcp, *t_tcp;
    p_link_node         ln;
    unsigned char      *p;
    mysql_table_item_t *item;
    tc_mysql_session   *mysql_sess;

    if (!ctx.fir_auth_pack) {
        tc_log_info(LOG_WARN, 0, "no first auth pack here");
        return TC_ERR;
    }

    mysql_sess = s->data;
    if (mysql_sess == NULL) {
        tc_log_info(LOG_WARN, 0, "mysql session structure is not allocated");
        return TC_ERR;
    } else if (mysql_sess->fir_auth_added) {
        tc_log_info(LOG_NOTICE, 0, "dup visit prepare_for_renew_session");
        return TC_OK;
    }

    s->sm.need_rep_greet = 1;

    fir_ip        = ctx.fir_auth_pack;
    fir_ip->saddr = ip->saddr;
    size_ip       = fir_ip->ihl << 2;
    fir_tcp = (tc_tcph_t *) ((char *) fir_ip + size_ip);
    fir_tcp->source = tcp->source;

    tot_clen = ctx.fir_auth_cont_len;

    item = hash_find(ctx.table, s->hash_key);
    if (item) {
        tot_clen += item->tot_cont_len;
    }

    tc_log_debug2(LOG_INFO, 0, "total len subtracted:%u,p:%u", tot_clen, 
            ntohs(s->src_port));

    tcp->seq     = htonl(ntohl(tcp->seq) - tot_clen);
    fir_tcp->seq = htonl(ntohl(tcp->seq) + 1);
    tc_save_pack(s, s->slide_win_packs, fir_ip, fir_tcp);  
    mysql_sess->fir_auth_added = 1;

    base_seq = ntohl(fir_tcp->seq) + ctx.fir_auth_cont_len;

    if (item) {
        ln = link_list_first(item->list); 
        while (ln) {
            p = (unsigned char *) ln->data;
            t_ip  = (tc_iph_t *) (p + ETHERNET_HDR_LEN);
            t_tcp = (tc_tcph_t *) ((char *) t_ip + size_ip);
            t_tcp->seq = htonl(base_seq);
            tc_save_pack(s, s->slide_win_packs, t_ip, t_tcp);  
            base_seq += TCP_PAYLOAD_LENGTH(t_ip, t_tcp);
            ln = link_list_get_next(item->list, ln);
        }
    }

    mysql_sess->old_ps_cleaned = 0;

    return TC_OK;
}