diff options
author | Liong Sauw Ming <ming@teluu.com> | 2011-03-15 10:49:59 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2011-03-15 10:49:59 +0000 |
commit | bfd49295b48a31eae9d7d9d8c018eea8e193179c (patch) | |
tree | 735165feb58f2d80c76b60222fc22d248d65e246 /pjsip/src/pjsip-ua | |
parent | 2db53631ab7583e95c0a3a7d27096af651afe753 (diff) |
Re #1205: If refresh timer is already running, it will be cancelled and rescheduled with the new delay. This can be useful if app wants to correct the delay after it checks the timeout in the callback.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3444 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/pjsip-ua')
-rw-r--r-- | pjsip/src/pjsip-ua/sip_reg.c | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/pjsip/src/pjsip-ua/sip_reg.c b/pjsip/src/pjsip-ua/sip_reg.c index 45a69ba2..d96e3c88 100644 --- a/pjsip/src/pjsip-ua/sip_reg.c +++ b/pjsip/src/pjsip-ua/sip_reg.c @@ -391,15 +391,6 @@ PJ_DEF(pj_status_t) pjsip_regc_init( pjsip_regc *regc, return PJ_SUCCESS; } -PJ_DEF(pj_status_t) -pjsip_regc_set_delay_before_refresh( pjsip_regc *regc, - pj_uint32_t delay ) -{ - PJ_ASSERT_RETURN(regc, PJ_EINVAL); - regc->delay_before_refresh = delay; - return PJ_SUCCESS; -} - PJ_DEF(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc, int count, const pjsip_cred_info cred[] ) @@ -783,6 +774,56 @@ static void regc_refresh_timer_cb( pj_timer_heap_t *timer_heap, } } +static void schedule_registration ( pjsip_regc *regc, pj_int32_t expiration ) +{ + if (regc->auto_reg && expiration > 0) { + pj_time_val delay = { 0, 0}; + + delay.sec = expiration - regc->delay_before_refresh; + if (regc->expires != PJSIP_REGC_EXPIRATION_NOT_SPECIFIED && + delay.sec > (pj_int32_t)regc->expires) + { + delay.sec = regc->expires; + } + if (delay.sec < DELAY_BEFORE_REFRESH) + delay.sec = DELAY_BEFORE_REFRESH; + regc->timer.cb = ®c_refresh_timer_cb; + regc->timer.id = REFRESH_TIMER; + regc->timer.user_data = regc; + pjsip_endpt_schedule_timer( regc->endpt, ®c->timer, &delay); + pj_gettimeofday(®c->last_reg); + regc->next_reg = regc->last_reg; + regc->next_reg.sec += delay.sec; + } +} + +PJ_DEF(pj_status_t) +pjsip_regc_set_delay_before_refresh( pjsip_regc *regc, + pj_uint32_t delay ) +{ + PJ_ASSERT_RETURN(regc, PJ_EINVAL); + + if (delay > regc->expires) + return PJ_ETOOBIG; + + if (regc->delay_before_refresh != delay) + { + regc->delay_before_refresh = delay; + + if (regc->timer.id != 0) { + /* Cancel registration timer */ + pjsip_endpt_cancel_timer(regc->endpt, ®c->timer); + regc->timer.id = 0; + + /* Schedule next registration */ + schedule_registration(regc, regc->expires); + } + } + + return PJ_SUCCESS; +} + + static pj_int32_t calculate_response_expiration(const pjsip_regc *regc, const pjsip_rx_data *rdata, unsigned *contact_cnt, @@ -1127,25 +1168,7 @@ handle_err: regc->current_op = REGC_IDLE; /* Schedule next registration */ - if (regc->auto_reg && expiration > 0) { - pj_time_val delay = { 0, 0}; - - delay.sec = expiration - regc->delay_before_refresh; - if (regc->expires != PJSIP_REGC_EXPIRATION_NOT_SPECIFIED && - delay.sec > (pj_int32_t)regc->expires) - { - delay.sec = regc->expires; - } - if (delay.sec < DELAY_BEFORE_REFRESH) - delay.sec = DELAY_BEFORE_REFRESH; - regc->timer.cb = ®c_refresh_timer_cb; - regc->timer.id = REFRESH_TIMER; - regc->timer.user_data = regc; - pjsip_endpt_schedule_timer( regc->endpt, ®c->timer, &delay); - pj_gettimeofday(®c->last_reg); - regc->next_reg = regc->last_reg; - regc->next_reg.sec += delay.sec; - } + schedule_registration(regc, expiration); } else { rdata = (event->body.tsx_state.type==PJSIP_EVENT_RX_MSG) ? |