static int hash_test_with_key(pj_pool_t *pool, unsigned char key) { pj_hash_table_t *ht; unsigned value = 0x12345; pj_hash_iterator_t it_buf, *it; unsigned *entry; ht = pj_hash_create(pool, HASH_COUNT); if (!ht) return -10; pj_hash_set(pool, ht, &key, sizeof(key), 0, &value); entry = (unsigned*) pj_hash_get(ht, &key, sizeof(key), NULL); if (!entry) return -20; if (*entry != value) return -30; if (pj_hash_count(ht) != 1) return -30; it = pj_hash_first(ht, &it_buf); if (it == NULL) return -40; entry = (unsigned*) pj_hash_this(ht, it); if (!entry) return -50; if (*entry != value) return -60; it = pj_hash_next(ht, it); if (it != NULL) return -70; /* Erase item */ pj_hash_set(NULL, ht, &key, sizeof(key), 0, NULL); if (pj_hash_get(ht, &key, sizeof(key), NULL) != NULL) return -80; if (pj_hash_count(ht) != 0) return -90; it = pj_hash_first(ht, &it_buf); if (it != NULL) return -100; return 0; }
static void dump_status(pj_turn_srv *srv) { char addr[80]; pj_hash_iterator_t itbuf, *it; pj_time_val now; unsigned i; for (i=0; i<srv->core.lis_cnt; ++i) { pj_turn_listener *lis = srv->core.listener[i]; printf("Server address : %s\n", lis->info); } printf("Worker threads : %d\n", srv->core.thread_cnt); printf("Total mem usage: %u.%03uMB\n", (unsigned)(g_cp.used_size / 1000000), (unsigned)((g_cp.used_size % 1000000)/1000)); printf("UDP port range : %u %u %u (next/min/max)\n", srv->ports.next_udp, srv->ports.min_udp, srv->ports.max_udp); printf("TCP port range : %u %u %u (next/min/max)\n", srv->ports.next_tcp, srv->ports.min_tcp, srv->ports.max_tcp); printf("Clients # : %u\n", pj_hash_count(srv->tables.alloc)); puts(""); if (pj_hash_count(srv->tables.alloc)==0) { return; } puts("# Client addr. Alloc addr. Username Lftm Expy #prm #chl"); puts("------------------------------------------------------------------------------"); pj_gettimeofday(&now); it = pj_hash_first(srv->tables.alloc, &itbuf); i=1; while (it) { pj_turn_allocation *alloc = (pj_turn_allocation*) pj_hash_this(srv->tables.alloc, it); printf("%-3d %-22s %-22s %-8.*s %-4d %-4ld %-4d %-4d\n", i, alloc->info, pj_sockaddr_print(&alloc->relay.hkey.addr, addr, sizeof(addr), 3), (int)alloc->cred.data.static_cred.username.slen, alloc->cred.data.static_cred.username.ptr, alloc->relay.lifetime, alloc->relay.expiry.sec - now.sec, pj_hash_count(alloc->peer_table), pj_hash_count(alloc->ch_table)); it = pj_hash_next(srv->tables.alloc, it); ++i; } }
void ht_list_item(hash_table_t* table_data) { pj_hash_iterator_t it_buf,*it; unsigned count; int *ret; count = pj_hash_count(table_data->hash_table); SHOW_LOG(4, "Total: %d %s\n", count, (count < 2)?"entry":"entries" ); it = pj_hash_first(table_data->hash_table, &it_buf); while (it) { ret = (int *)pj_hash_this(table_data->hash_table, it); SHOW_LOG(4, "Entry: %d\n", *ret); it = pj_hash_next(table_data->hash_table, it); } }
/* * Destroy DNS resolver instance. */ PJ_DEF(pj_status_t) pj_dns_resolver_destroy( pj_dns_resolver *resolver, pj_bool_t notify) { pj_hash_iterator_t it_buf, *it; PJ_ASSERT_RETURN(resolver, PJ_EINVAL); if (notify) { /* * Notify pending queries if requested. */ it = pj_hash_first(resolver->hquerybyid, &it_buf); while (it) { pj_dns_async_query *q = (pj_dns_async_query *) pj_hash_this(resolver->hquerybyid, it); pj_dns_async_query *cq; if (q->cb) (*q->cb)(q->user_data, PJ_ECANCELLED, NULL); cq = q->child_head.next; while (cq != (pj_dns_async_query*)&q->child_head) { if (cq->cb) (*cq->cb)(cq->user_data, PJ_ECANCELLED, NULL); cq = cq->next; } it = pj_hash_next(resolver->hquerybyid, it); } } /* Destroy cached entries */ it = pj_hash_first(resolver->hrescache, &it_buf); while (it) { struct cached_res *cache; cache = (struct cached_res*) pj_hash_this(resolver->hrescache, it); pj_hash_set(NULL, resolver->hrescache, &cache->key, sizeof(cache->key), 0, NULL); pj_pool_release(cache->pool); it = pj_hash_first(resolver->hrescache, &it_buf); } if (resolver->own_timer && resolver->timer) { pj_timer_heap_destroy(resolver->timer); resolver->timer = NULL; } if (resolver->udp_key != NULL) { pj_ioqueue_unregister(resolver->udp_key); resolver->udp_key = NULL; resolver->udp_sock = PJ_INVALID_SOCKET; } else if (resolver->udp_sock != PJ_INVALID_SOCKET) { pj_sock_close(resolver->udp_sock); resolver->udp_sock = PJ_INVALID_SOCKET; } if (resolver->own_ioqueue && resolver->ioqueue) { pj_ioqueue_destroy(resolver->ioqueue); resolver->ioqueue = NULL; } if (resolver->mutex) { pj_mutex_destroy(resolver->mutex); resolver->mutex = NULL; } if (resolver->pool) { pj_pool_t *pool = resolver->pool; resolver->pool = NULL; pj_pool_release(pool); } return PJ_SUCCESS; }
/* * Destroy the server. */ PJ_DEF(pj_status_t) pj_turn_srv_destroy(pj_turn_srv *srv) { pj_hash_iterator_t itbuf, *it; unsigned i; /* Stop all worker threads */ srv->core.quit = PJ_TRUE; for (i=0; i<srv->core.thread_cnt; ++i) { if (srv->core.thread[i]) { pj_thread_join(srv->core.thread[i]); pj_thread_destroy(srv->core.thread[i]); srv->core.thread[i] = NULL; } } /* Destroy all allocations FIRST */ if (srv->tables.alloc) { it = pj_hash_first(srv->tables.alloc, &itbuf); while (it != NULL) { pj_turn_allocation *alloc = (pj_turn_allocation*) pj_hash_this(srv->tables.alloc, it); pj_hash_iterator_t *next = pj_hash_next(srv->tables.alloc, it); pj_turn_allocation_destroy(alloc); it = next; } } /* Destroy all listeners. */ for (i=0; i<srv->core.lis_cnt; ++i) { if (srv->core.listener[i]) { pj_turn_listener_destroy(srv->core.listener[i]); srv->core.listener[i] = NULL; } } /* Destroy STUN session */ if (srv->core.stun_sess) { pj_stun_session_destroy(srv->core.stun_sess); srv->core.stun_sess = NULL; } /* Destroy hash tables (well, sort of) */ if (srv->tables.alloc) { srv->tables.alloc = NULL; srv->tables.res = NULL; } /* Destroy timer heap */ if (srv->core.timer_heap) { pj_timer_heap_destroy(srv->core.timer_heap); srv->core.timer_heap = NULL; } /* Destroy ioqueue */ if (srv->core.ioqueue) { pj_ioqueue_destroy(srv->core.ioqueue); srv->core.ioqueue = NULL; } /* Destroy thread local IDs */ if (srv->core.tls_key != -1) { pj_thread_local_free(srv->core.tls_key); srv->core.tls_key = -1; } if (srv->core.tls_data != -1) { pj_thread_local_free(srv->core.tls_data); srv->core.tls_data = -1; } /* Destroy server lock */ if (srv->core.lock) { pj_lock_destroy(srv->core.lock); srv->core.lock = NULL; } /* Release pool */ if (srv->core.pool) { pj_pool_t *pool = srv->core.pool; srv->core.pool = NULL; pj_pool_release(pool); } /* Done */ return PJ_SUCCESS; }