本文整理汇总了C++中pj_ioqueue_poll函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_ioqueue_poll函数的具体用法?C++ pj_ioqueue_poll怎么用?C++ pj_ioqueue_poll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_ioqueue_poll函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: poll_events
void poll_events(pj_stun_config *stun_cfg, unsigned msec,
pj_bool_t first_event_only)
{
pj_time_val stop_time;
int count = 0;
pj_gettimeofday(&stop_time);
stop_time.msec += msec;
pj_time_val_normalize(&stop_time);
/* Process all events for the specified duration. */
for (;;) {
pj_time_val timeout = {0, 1}, now;
int c;
c = pj_timer_heap_poll( stun_cfg->timer_heap, NULL );
if (c > 0)
count += c;
//timeout.sec = timeout.msec = 0;
c = pj_ioqueue_poll( stun_cfg->ioqueue, &timeout);
if (c > 0)
count += c;
pj_gettimeofday(&now);
if (PJ_TIME_VAL_GTE(now, stop_time))
break;
if (first_event_only && count >= 0)
break;
}
}
示例2: handle_events
//
// Handle events.
//
int handle_events(Pj_Time_Val *max_timeout)
{
Pj_Time_Val timeout(0, 0);
int timer_count;
timer_count = pj_timer_heap_poll( th_, &timeout );
if (timeout.get_sec() < 0)
timeout.sec = PJ_MAXINT32;
/* If caller specifies maximum time to wait, then compare the value
* with the timeout to wait from timer, and use the minimum value.
*/
if (max_timeout && timeout >= *max_timeout) {
timeout = *max_timeout;
}
/* Poll events in ioqueue. */
int ioqueue_count;
ioqueue_count = pj_ioqueue_poll(ioq_, &timeout);
if (ioqueue_count < 0)
return ioqueue_count;
return ioqueue_count + timer_count;
}
示例3: udp_destroy
/*
* udp_destroy()
*
* This function is called by transport manager (by transport->destroy()).
*/
static pj_status_t udp_destroy( pjsip_transport *transport )
{
struct udp_transport *tp = (struct udp_transport*)transport;
int i;
/* Mark this transport as closing. */
tp->is_closing = 1;
/* Cancel all pending operations. */
/* blp: NO NO NO...
* No need to post queued completion as we poll the ioqueue until
* we've got events anyway. Posting completion will only cause
* callback to be called twice with IOCP: one for the post completion
* and another one for closing the socket.
*
for (i=0; i<tp->rdata_cnt; ++i) {
pj_ioqueue_post_completion(tp->key,
&tp->rdata[i]->tp_info.op_key.op_key, -1);
}
*/
/* Unregister from ioqueue. */
if (tp->key) {
pj_ioqueue_unregister(tp->key);
tp->key = NULL;
} else {
/* Close socket. */
if (tp->sock && tp->sock != PJ_INVALID_SOCKET) {
pj_sock_close(tp->sock);
tp->sock = PJ_INVALID_SOCKET;
}
}
/* Must poll ioqueue because IOCP calls the callback when socket
* is closed. We poll the ioqueue until all pending callbacks
* have been called.
*/
for (i=0; i<50 && tp->is_closing < 1+tp->rdata_cnt; ++i) {
int cnt;
pj_time_val timeout = {0, 1};
cnt = pj_ioqueue_poll(pjsip_endpt_get_ioqueue(transport->endpt),
&timeout);
if (cnt == 0)
break;
}
if (tp->grp_lock) {
pj_grp_lock_t *grp_lock = tp->grp_lock;
tp->grp_lock = NULL;
pj_grp_lock_dec_ref(grp_lock);
/* Transport may have been deleted at this point */
} else {
udp_on_destroy(tp);
}
return PJ_SUCCESS;
}
示例4: worker_proc
/**
* Worker thread proc.
*/
static int PJ_THREAD_FUNC worker_proc(void *arg)
{
pjmedia_endpt *endpt = (pjmedia_endpt*) arg;
while (!endpt->quit_flag) {
pj_time_val timeout = { 0, 500 };
pj_ioqueue_poll(endpt->ioqueue, &timeout);
}
return 0;
}
示例5: handle_events
static void handle_events(pj_stun_config *cfg, unsigned msec_delay)
{
pj_time_val delay;
pj_timer_heap_poll(cfg->timer_heap, NULL);
delay.sec = 0;
delay.msec = msec_delay;
pj_time_val_normalize(&delay);
pj_ioqueue_poll(cfg->ioqueue, &delay);
}
示例6: srv_handle_events
/*
* Handle timer and network events
*/
static void srv_handle_events(pj_turn_srv *srv, const pj_time_val *max_timeout)
{
/* timeout is 'out' var. This just to make compiler happy. */
pj_time_val timeout = { 0, 0};
unsigned net_event_count = 0;
int c;
/* Poll the timer. The timer heap has its own mutex for better
* granularity, so we don't need to lock the server.
*/
timeout.sec = timeout.msec = 0;
c = pj_timer_heap_poll( srv->core.timer_heap, &timeout );
/* timer_heap_poll should never ever returns negative value, or otherwise
* ioqueue_poll() will block forever!
*/
pj_assert(timeout.sec >= 0 && timeout.msec >= 0);
if (timeout.msec >= 1000) timeout.msec = 999;
/* If caller specifies maximum time to wait, then compare the value with
* the timeout to wait from timer, and use the minimum value.
*/
if (max_timeout && PJ_TIME_VAL_GT(timeout, *max_timeout)) {
timeout = *max_timeout;
}
/* Poll ioqueue.
* Repeat polling the ioqueue while we have immediate events, because
* timer heap may process more than one events, so if we only process
* one network events at a time (such as when IOCP backend is used),
* the ioqueue may have trouble keeping up with the request rate.
*
* For example, for each send() request, one network event will be
* reported by ioqueue for the send() completion. If we don't poll
* the ioqueue often enough, the send() completion will not be
* reported in timely manner.
*/
do {
c = pj_ioqueue_poll( srv->core.ioqueue, &timeout);
if (c < 0) {
pj_thread_sleep(PJ_TIME_VAL_MSEC(timeout));
return;
} else if (c == 0) {
break;
} else {
net_event_count += c;
timeout.sec = timeout.msec = 0;
}
} while (c > 0 && net_event_count < MAX_NET_EVENTS);
}
示例7: worker_thread_proc
static int worker_thread_proc(void *p)
{
struct stun_test_session *test_sess = (struct stun_test_session*)p;
PJ_LOG(4,(THIS_FILE, "Worker thread running"));
while (!test_sess->thread_quit_flag) {
pj_time_val timeout = {0, 10};
pj_timer_heap_poll(test_sess->stun_cfg.timer_heap, NULL);
pj_ioqueue_poll(test_sess->stun_cfg.ioqueue, &timeout);
}
PJ_LOG(4,(THIS_FILE, "Worker thread quitting"));
return 0;
}
示例8: worker_thread
static int worker_thread(void *unused)
{
PJ_UNUSED_ARG(unused);
while (!g.quit) {
const pj_time_val delay = {0, 10};
/* Poll ioqueue for the TURN client */
pj_ioqueue_poll(g.stun_config.ioqueue, &delay);
/* Poll the timer heap */
pj_timer_heap_poll(g.stun_config.timer_heap, NULL);
}
return 0;
}
示例9: getURL
pj_status_t getURL(const char *curl)
{
pj_str_t url;
pj_http_req_callback hcb;
pj_status_t status;
pj_bzero(&hcb, sizeof(hcb));
hcb.on_complete = &on_complete;
hcb.on_data_read = &on_data_read;
hcb.on_send_data = &on_send_data;
hcb.on_response = &on_response;
/* Create pool, timer, and ioqueue */
pool = pj_pool_create(mem, NULL, 8192, 4096, NULL);
if (pj_timer_heap_create(pool, 16, &timer_heap))
return -31;
if (pj_ioqueue_create(pool, 16, &ioqueue))
return -32;
pj_strdup2(pool, &url, curl);
if ((status = pj_http_req_create(pool, &url, timer_heap, ioqueue,
NULL, &hcb, &http_req)) != PJ_SUCCESS)
return status;
if ((status = pj_http_req_start(http_req)) != PJ_SUCCESS)
return status;
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
pj_http_req_destroy(http_req);
pj_ioqueue_destroy(ioqueue);
pj_timer_heap_destroy(timer_heap);
pj_pool_release(pool);
return PJ_SUCCESS;
}
示例10: worker_thread
/* The worker thread. */
static int worker_thread(void *p)
{
struct thread_arg *arg = (struct thread_arg*) p;
const pj_time_val timeout = {0, 100};
int rc;
while (!thread_quit_flag) {
++arg->counter;
rc = pj_ioqueue_poll(arg->ioqueue, &timeout);
//TRACE_((THIS_FILE, " thread: poll returned rc=%d", rc));
if (rc < 0) {
char errmsg[PJ_ERR_MSG_SIZE];
pj_strerror(-rc, errmsg, sizeof(errmsg));
PJ_LOG(3, (THIS_FILE,
"...error in pj_ioqueue_poll() in thread %d "
"after %d loop: %s [pj_status_t=%d]",
arg->id, arg->counter, errmsg, -rc));
//return -1;
}
}
return 0;
}
示例11: worker_thread
static int worker_thread(void *arg)
{
pj_ioqueue_t *ioqueue = (pj_ioqueue_t*) arg;
struct op_key read_op, write_op;
char recv_buf[512], send_buf[512];
pj_ssize_t length;
pj_status_t rc;
read_op.peer = &write_op;
read_op.is_pending = 0;
read_op.last_err = 0;
read_op.buffer = recv_buf;
read_op.size = sizeof(recv_buf);
read_op.addrlen = sizeof(read_op.addr);
write_op.peer = &read_op;
write_op.is_pending = 0;
write_op.last_err = 0;
write_op.buffer = send_buf;
write_op.size = sizeof(send_buf);
length = sizeof(recv_buf);
rc = pj_ioqueue_recvfrom(key, &read_op.op_key_, recv_buf, &length, 0,
&read_op.addr, &read_op.addrlen);
if (rc == PJ_SUCCESS) {
read_op.is_pending = 1;
on_read_complete(key, &read_op.op_key_, length);
}
while (!thread_quit_flag) {
pj_time_val timeout;
timeout.sec = 0; timeout.msec = 10;
rc = pj_ioqueue_poll(ioqueue, &timeout);
}
return 0;
}
示例12: server_non_ssl
//.........这里部分代码省略.........
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_sock_listen(sock, PJ_SOMAXCONN);
if (status != PJ_SUCCESS) {
goto on_return;
}
asock_cb.on_accept_complete = &asock_on_accept_complete;
status = pj_activesock_create(pool, sock, pj_SOCK_STREAM(), NULL,
ioqueue, &asock_cb, &state_serv, &asock_serv);
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_activesock_start_accept(asock_serv, pool);
if (status != PJ_SUCCESS)
goto on_return;
/* Update listener address */
{
int addr_len;
addr_len = sizeof(listen_addr);
pj_sock_getsockname(sock, (pj_sockaddr_t*)&listen_addr, &addr_len);
}
/* CLIENT */
pj_ssl_sock_param_default(¶m);
param.cb.on_connect_complete = &ssl_on_connect_complete;
param.cb.on_data_read = &ssl_on_data_read;
param.cb.on_data_sent = &ssl_on_data_sent;
param.ioqueue = ioqueue;
param.timer_heap = timer;
param.timeout.sec = 0;
param.timeout.msec = ms_timeout;
pj_time_val_normalize(¶m.timeout);
param.user_data = &state_cli;
state_cli.pool = pool;
state_cli.is_server = PJ_FALSE;
state_cli.is_verbose = PJ_TRUE;
status = pj_ssl_sock_create(pool, ¶m, &ssock_cli);
if (status != PJ_SUCCESS) {
goto on_return;
}
/* Init default bind address */
{
pj_str_t tmp_st;
pj_sockaddr_init(PJ_AF_INET, &addr, pj_strset2(&tmp_st, "127.0.0.1"), 0);
}
status = pj_ssl_sock_start_connect(ssock_cli, pool,
(pj_sockaddr_t*)&addr,
(pj_sockaddr_t*)&listen_addr,
pj_sockaddr_get_len(&listen_addr));
if (status != PJ_EPENDING) {
goto on_return;
}
/* Wait until everything has been sent/received or error */
while ((!state_serv.err && !state_serv.done) || (!state_cli.err && !state_cli.done))
{
#ifdef PJ_SYMBIAN
pj_symbianos_poll(-1, 1000);
#else
pj_time_val delay = {0, 100};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer, &delay);
#endif
}
if (state_serv.err || state_cli.err) {
if (state_cli.err != PJ_SUCCESS)
status = state_cli.err;
else
status = state_serv.err;
goto on_return;
}
PJ_LOG(3, ("", "...Done!"));
on_return:
if (asock_serv)
pj_activesock_close(asock_serv);
if (ssock_cli && !state_cli.err && !state_cli.done)
pj_ssl_sock_close(ssock_cli);
if (timer)
pj_timer_heap_destroy(timer);
if (ioqueue)
pj_ioqueue_destroy(ioqueue);
if (pool)
pj_pool_release(pool);
return status;
}
示例13: client_non_ssl
//.........这里部分代码省略.........
param.timeout.msec = ms_timeout;
pj_time_val_normalize(¶m.timeout);
/* SERVER */
param.user_data = &state_serv;
state_serv.pool = pool;
state_serv.is_server = PJ_TRUE;
state_serv.is_verbose = PJ_TRUE;
status = pj_ssl_sock_create(pool, ¶m, &ssock_serv);
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_ssl_sock_set_certificate(ssock_serv, pool, cert);
if (status != PJ_SUCCESS) {
goto on_return;
}
/* Init bind address */
{
pj_str_t tmp_st;
pj_sockaddr_init(PJ_AF_INET, &listen_addr, pj_strset2(&tmp_st, "127.0.0.1"), 0);
}
status = pj_ssl_sock_start_accept(ssock_serv, pool, &listen_addr, pj_sockaddr_get_len(&listen_addr));
if (status != PJ_SUCCESS) {
goto on_return;
}
/* Update listener address */
{
pj_ssl_sock_info info;
pj_ssl_sock_get_info(ssock_serv, &info);
pj_sockaddr_cp(&listen_addr, &info.local_addr);
}
/* CLIENT */
state_cli.pool = pool;
status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &sock);
if (status != PJ_SUCCESS) {
goto on_return;
}
asock_cb.on_connect_complete = &asock_on_connect_complete;
asock_cb.on_data_read = &asock_on_data_read;
status = pj_activesock_create(pool, sock, pj_SOCK_STREAM(), NULL,
ioqueue, &asock_cb, &state_cli, &asock_cli);
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_activesock_start_connect(asock_cli, pool, (pj_sockaddr_t*)&listen_addr,
pj_sockaddr_get_len(&listen_addr));
if (status == PJ_SUCCESS) {
asock_on_connect_complete(asock_cli, PJ_SUCCESS);
} else if (status == PJ_EPENDING) {
status = PJ_SUCCESS;
} else {
goto on_return;
}
/* Wait until everything has been sent/received or error */
while (!state_serv.err && !state_cli.err && !state_serv.done && !state_cli.done)
{
#ifdef PJ_SYMBIAN
pj_symbianos_poll(-1, 1000);
#else
pj_time_val delay = {0, 100};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer, &delay);
#endif
}
if (state_serv.err || state_cli.err) {
if (state_serv.err != PJ_SUCCESS)
status = state_serv.err;
else
status = state_cli.err;
goto on_return;
}
PJ_LOG(3, ("", "...Done!"));
on_return:
if (ssock_serv)
pj_ssl_sock_close(ssock_serv);
if (asock_cli && !state_cli.err && !state_cli.done)
pj_activesock_close(asock_cli);
if (timer)
pj_timer_heap_destroy(timer);
if (ioqueue)
pj_ioqueue_destroy(ioqueue);
if (pool)
pj_pool_release(pool);
return status;
}
示例14: echo_test
//.........这里部分代码省略.........
param.proto = cli_proto;
param.user_data = &state_cli;
param.ciphers_num = (cli_cipher == -1)? 0 : 1;
ciphers[0] = cli_cipher;
state_cli.pool = pool;
state_cli.check_echo = PJ_TRUE;
state_cli.is_verbose = PJ_TRUE;
{
pj_time_val now;
pj_gettimeofday(&now);
pj_srand((unsigned)now.sec);
state_cli.send_str_len = (pj_rand() % 5 + 1) * 1024 + pj_rand() % 1024;
}
state_cli.send_str = pj_pool_alloc(pool, state_cli.send_str_len);
{
unsigned i;
for (i = 0; i < state_cli.send_str_len; ++i)
state_cli.send_str[i] = (char)(pj_rand() % 256);
}
status = pj_ssl_sock_create(pool, ¶m, &ssock_cli);
if (status != PJ_SUCCESS) {
goto on_return;
}
/* Set cert for client */
{
if (!client_provide_cert) {
pj_str_t tmp1, tmp2;
pj_strset2(&tmp1, (char*)CERT_CA_FILE);
pj_strset2(&tmp2, NULL);
status = pj_ssl_cert_load_from_files(pool,
&tmp1, &tmp2, &tmp2, &tmp2,
&cert);
if (status != PJ_SUCCESS) {
goto on_return;
}
}
status = pj_ssl_sock_set_certificate(ssock_cli, pool, cert);
if (status != PJ_SUCCESS) {
goto on_return;
}
}
status = pj_ssl_sock_start_connect(ssock_cli, pool, &addr, &listen_addr, pj_sockaddr_get_len(&addr));
if (status == PJ_SUCCESS) {
ssl_on_connect_complete(ssock_cli, PJ_SUCCESS);
} else if (status == PJ_EPENDING) {
status = PJ_SUCCESS;
} else {
goto on_return;
}
/* Wait until everything has been sent/received or error */
while (!state_serv.err && !state_cli.err && !state_serv.done && !state_cli.done)
{
#ifdef PJ_SYMBIAN
pj_symbianos_poll(-1, 1000);
#else
pj_time_val delay = {0, 100};
pj_ioqueue_poll(ioqueue, &delay);
#endif
}
/* Clean up sockets */
{
pj_time_val delay = {0, 100};
while (pj_ioqueue_poll(ioqueue, &delay) > 0);
}
if (state_serv.err || state_cli.err) {
if (state_serv.err != PJ_SUCCESS)
status = state_serv.err;
else
status = state_cli.err;
goto on_return;
}
PJ_LOG(3, ("", "...Done!"));
PJ_LOG(3, ("", ".....Sent/recv: %d/%d bytes", state_cli.sent, state_cli.recv));
on_return:
if (ssock_serv)
pj_ssl_sock_close(ssock_serv);
if (ssock_cli && !state_cli.err && !state_cli.done)
pj_ssl_sock_close(ssock_cli);
if (ioqueue)
pj_ioqueue_destroy(ioqueue);
if (pool)
pj_pool_release(pool);
return status;
}
示例15: https_client_test
static int https_client_test(unsigned ms_timeout)
{
pj_pool_t *pool = NULL;
pj_ioqueue_t *ioqueue = NULL;
pj_timer_heap_t *timer = NULL;
pj_ssl_sock_t *ssock = NULL;
pj_ssl_sock_param param;
pj_status_t status;
struct test_state state = {0};
pj_sockaddr local_addr, rem_addr;
pj_str_t tmp_st;
pool = pj_pool_create(mem, "https_get", 256, 256, NULL);
status = pj_ioqueue_create(pool, 4, &ioqueue);
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_timer_heap_create(pool, 4, &timer);
if (status != PJ_SUCCESS) {
goto on_return;
}
state.pool = pool;
state.send_str = HTTP_REQ;
state.send_str_len = pj_ansi_strlen(state.send_str);
state.is_verbose = PJ_TRUE;
pj_ssl_sock_param_default(¶m);
param.cb.on_connect_complete = &ssl_on_connect_complete;
param.cb.on_data_read = &ssl_on_data_read;
param.cb.on_data_sent = &ssl_on_data_sent;
param.ioqueue = ioqueue;
param.user_data = &state;
param.server_name = pj_str((char*)HTTP_SERVER_ADDR);
param.timer_heap = timer;
param.timeout.sec = 0;
param.timeout.msec = ms_timeout;
param.proto = PJ_SSL_SOCK_PROTO_SSL23;
pj_time_val_normalize(¶m.timeout);
status = pj_ssl_sock_create(pool, ¶m, &ssock);
if (status != PJ_SUCCESS) {
goto on_return;
}
pj_sockaddr_init(PJ_AF_INET, &local_addr, pj_strset2(&tmp_st, "0.0.0.0"), 0);
pj_sockaddr_init(PJ_AF_INET, &rem_addr, pj_strset2(&tmp_st, HTTP_SERVER_ADDR), HTTP_SERVER_PORT);
status = pj_ssl_sock_start_connect(ssock, pool, &local_addr, &rem_addr, sizeof(rem_addr));
if (status == PJ_SUCCESS) {
ssl_on_connect_complete(ssock, PJ_SUCCESS);
} else if (status == PJ_EPENDING) {
status = PJ_SUCCESS;
} else {
goto on_return;
}
/* Wait until everything has been sent/received */
while (state.err == PJ_SUCCESS && !state.done) {
#ifdef PJ_SYMBIAN
pj_symbianos_poll(-1, 1000);
#else
pj_time_val delay = {0, 100};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer, &delay);
#endif
}
if (state.err) {
status = state.err;
goto on_return;
}
PJ_LOG(3, ("", "...Done!"));
PJ_LOG(3, ("", ".....Sent/recv: %d/%d bytes", state.sent, state.recv));
on_return:
if (ssock && !state.err && !state.done)
pj_ssl_sock_close(ssock);
if (ioqueue)
pj_ioqueue_destroy(ioqueue);
if (timer)
pj_timer_heap_destroy(timer);
if (pool)
pj_pool_release(pool);
return status;
}