static int stun_destroy_test_session(struct stun_test_session *test_sess) { unsigned i; pj_stun_sock_cb stun_cb; pj_status_t status; pj_stun_sock *stun_sock[MAX_SOCK_CLIENTS]; pj_bzero(&stun_cb, sizeof(stun_cb)); stun_cb.on_status = &stun_sock_on_status; pj_event_reset(test_sess->server_event); /* Create all clients first */ for (i=0; i<MAX_SOCK_CLIENTS; ++i) { char name[10]; sprintf(name, "stun%02d", i); status = pj_stun_sock_create(&test_sess->stun_cfg, name, pj_AF_INET(), &stun_cb, NULL, test_sess, &stun_sock[i]); if (status != PJ_SUCCESS) { PJ_PERROR(1,(THIS_FILE, status, "Error creating stun socket")); return -10; } } /* Start resolution */ for (i=0; i<MAX_SOCK_CLIENTS; ++i) { pj_str_t server_ip = pj_str("127.0.0.1"); status = pj_stun_sock_start(stun_sock[i], &server_ip, (pj_uint16_t)test_sess->server_port, NULL); if (status != PJ_SUCCESS) { PJ_PERROR(1,(THIS_FILE, status, "Error starting stun socket")); return -20; } } /* settle down */ pj_thread_sleep(test_sess->param.client_sleep_after_start); /* Resume server threads */ pj_event_set(test_sess->server_event); pj_thread_sleep(test_sess->param.client_sleep_before_destroy); /* Destroy clients */ for (i=0; i<MAX_SOCK_CLIENTS; ++i) { status = pj_stun_sock_destroy(stun_sock[i]); if (status != PJ_SUCCESS) { PJ_PERROR(1,(THIS_FILE, status, "Error destroying stun socket")); } } /* Give some time to ioqueue to free sockets */ pj_thread_sleep(PJ_IOQUEUE_KEY_FREE_DELAY); return 0; }
void dupsock_init(dupsock_t *p_dupsock, pj_sock_t *p_sock, pj_pool_t *p_mempool, dupsock_callback_proc rcb, dupsock_callback_proc scb) { p_dupsock->p_sock = p_sock; p_dupsock->p_mempool = p_mempool; p_dupsock->thread = NULL; p_dupsock->recv_callback = rcb; p_dupsock->send_callback = scb; p_dupsock->to_send = NULL; p_dupsock->in_packet.data = p_dupsock->in_buffer; p_dupsock->in_packet.len = 0; pj_event_create(p_dupsock->p_mempool, "dupsock-event", PJ_FALSE, PJ_TRUE, &(p_dupsock->p_event)); pj_event_reset(p_dupsock->p_event); p_dupsock->wait_cnt = 0; p_dupsock->p_user = NULL; }
// // Set a non-signalled. // pj_status_t reset() { return pj_event_reset(this->pj_event_t_()); }