From ad70abbdad70cbc5e0c61b41531783290fe08f48 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Thu, 1 Jun 2006 11:41:38 +0000 Subject: Added pjsip_endpt_handle_events2(), which has an additional argument to report how many events are caught in the poll git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@486 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsip/sip_endpoint.h | 15 +++++++++++++++ pjsip/src/pjsip/sip_endpoint.c | 32 +++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/pjsip/include/pjsip/sip_endpoint.h b/pjsip/include/pjsip/sip_endpoint.h index c9163ed8..f25c7493 100644 --- a/pjsip/include/pjsip/sip_endpoint.h +++ b/pjsip/include/pjsip/sip_endpoint.h @@ -115,6 +115,21 @@ PJ_DECL(pj_status_t) pjsip_endpt_handle_events( pjsip_endpoint *endpt, const pj_time_val *max_timeout); +/** + * Handle events with additional info about number of events that + * have been handled. + * + * @param endpt The endpoint. + * @param max_timeout Maximum time to wait for events, or NULL to wait forever + * until event is received. + * @param count Optional argument to receive the number of events that + * have been handled by the function. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjsip_endpt_handle_events2(pjsip_endpoint *endpt, + const pj_time_val *max_timeout, + unsigned *count); /** * Schedule timer to endpoint's timer heap. Application must poll the endpoint * periodically (by calling #pjsip_endpt_handle_events) to ensure that the diff --git a/pjsip/src/pjsip/sip_endpoint.c b/pjsip/src/pjsip/sip_endpoint.c index 3ede0102..e04485dc 100644 --- a/pjsip/src/pjsip/sip_endpoint.c +++ b/pjsip/src/pjsip/sip_endpoint.c @@ -582,14 +582,15 @@ PJ_DEF(void) pjsip_endpt_release_pool( pjsip_endpoint *endpt, pj_pool_t *pool ) pj_mutex_unlock(endpt->mutex); } -/* - * Handle events. - */ -PJ_DEF(pj_status_t) pjsip_endpt_handle_events(pjsip_endpoint *endpt, - const pj_time_val *max_timeout) + +PJ_DEF(pj_status_t) pjsip_endpt_handle_events2(pjsip_endpoint *endpt, + const pj_time_val *max_timeout, + unsigned *p_count) { /* timeout is 'out' var. This just to make compiler happy. */ pj_time_val timeout = { 0, 0}; + unsigned count = 0; + int c; PJ_LOG(6, (THIS_FILE, "pjsip_endpt_handle_events()")); @@ -597,7 +598,9 @@ PJ_DEF(pj_status_t) pjsip_endpt_handle_events(pjsip_endpoint *endpt, * granularity, so we don't need to lock end endpoint. */ timeout.sec = timeout.msec = 0; - pj_timer_heap_poll( endpt->timer_heap, &timeout ); + c = pj_timer_heap_poll( endpt->timer_heap, &timeout ); + if (c > 0) + count += c; /* timer_heap_poll should never ever returns negative value, or otherwise * ioqueue_poll() will block forever! @@ -612,14 +615,29 @@ PJ_DEF(pj_status_t) pjsip_endpt_handle_events(pjsip_endpoint *endpt, } /* Poll ioqueue. */ - if (pj_ioqueue_poll( endpt->ioqueue, &timeout) < 0) { + c = pj_ioqueue_poll( endpt->ioqueue, &timeout); + if (c < 0) { pj_thread_sleep(1); + if (p_count) + *p_count = count; return pj_get_netos_error(); } else { + count += c; + if (p_count) + *p_count = count; return PJ_SUCCESS; } } +/* + * Handle events. + */ +PJ_DEF(pj_status_t) pjsip_endpt_handle_events(pjsip_endpoint *endpt, + const pj_time_val *max_timeout) +{ + return pjsip_endpt_handle_events2(endpt, max_timeout, NULL); +} + /* * Schedule timer. */ -- cgit v1.2.3