函数原型
void
eXosip_automatic_refresh (struct eXosip_t *excontext)
{
eXosip_subscribe_t *js;
eXosip_dialog_t *jd;
eXosip_reg_t *jr;
time_t now;
now = osip_getsystemtime (NULL);
for (js = excontext->j_subscribes; js != NULL; js = js->next) {
for (jd = js->s_dialogs; jd != NULL; jd = jd->next) {
if (jd->d_dialog != NULL && (jd->d_id >= 1)) { /* finished call */
osip_transaction_t *out_tr = NULL;
out_tr = osip_list_get (jd->d_out_trs, 0);
if (out_tr == NULL)
out_tr = js->s_out_tr;
if (js->s_reg_period == 0 || out_tr == NULL) {
}
else if (now - out_tr->birth_time > js->s_reg_period - (js->s_reg_period / 10)) { /* will expires in js->s_reg_period/10: send refresh! */
int i;
i = _eXosip_subscribe_automatic_refresh (excontext, js, jd, out_tr);
if (i != 0) {
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not send subscribe for refresh\n"));
}
}
}
}
}
//针对多个服务器端进行重新注册
for (jr = excontext->j_reg; jr != NULL; jr = jr->next) {
if (jr->r_id >= 1 && jr->r_last_tr != NULL) {
if (jr->r_reg_period == 0) {
/* skip refresh! */
}
else if (now - jr->r_last_tr->birth_time > 900) {
/* automatic refresh */
//这里是15分钟重新注册
eXosip_register_send_register (excontext, jr->r_id, NULL);
#if TARGET_OS_IPHONE
}
else if (now - jr->r_last_tr->birth_time > jr->r_reg_period - 630) {
eXosip_register_send_register (excontext, jr->r_id, NULL);
#endif
}
else if (now - jr->r_last_tr->birth_time > jr->r_reg_period - (jr->r_reg_period / 10)) {
/* automatic refresh at "timeout - 10%" */
//代码测试中执行这个重新注册
eXosip_register_send_register (excontext, jr->r_id, NULL);
}
else if (now - jr->r_last_tr->birth_time > 120 && (jr->r_last_tr->last_response == NULL || (!MSG_IS_STATUS_2XX (jr->r_last_tr->last_response)))) {
/* automatic refresh */
eXosip_register_send_register (excontext, jr->r_id, NULL);
}
}
}
}
函数分析
针对超过有效期的操作,例如订阅和注册,重新进行了操作,简单来说就是续期
r_id标志了是哪个服务器端的注册信息
函数使用说明
可以在调用eXosip_event_wait函数之后,调用该函数处理订阅和注册的续期操作
eXosip_event_t* pEvent = NULL;
pEvent = eXosip_event_wait(m_ctx, 0, 50);
eXosip_automatic_refresh(m_ctx);