Changeset 2942


Ignore:
Timestamp:
Oct 13, 2009 2:01:59 PM (10 years ago)
Author:
bennylp
Message:

Ticket #364: Upon unregistration, (un)REGISTER should be sent only after (un)PUBLISH has completed successfully

  • wait for unpublication to complete or some delay expires, before sending unregistration
  • added unpublish_max_wait_time_msec field in account config to control how long to wait
Location:
pjproject/trunk/pjsip
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r2940 r2942  
    17521752 
    17531753/** 
     1754 * Maximum time to wait for unpublication transaction(s) to complete 
     1755 * during shutdown process, before sending unregistration. The library 
     1756 * tries to wait for the unpublication (un-PUBLISH) to complete before 
     1757 * sending REGISTER request to unregister the account, during library 
     1758 * shutdown process. If the value is set too short, it is possible that 
     1759 * the unregistration is sent before unpublication completes, causing 
     1760 * unpublication request to fail. 
     1761 * 
     1762 * Default: 2000 (2 seconds) 
     1763 */ 
     1764#ifndef PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC 
     1765#   define PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC   2000 
     1766#endif 
     1767 
     1768 
     1769/** 
    17541770 * This structure describes account configuration to be specified when 
    17551771 * adding a new account with #pjsua_acc_add(). Application MUST initialize 
     
    18011817     */ 
    18021818    pjsip_publishc_opt  publish_opt; 
     1819 
     1820    /** 
     1821     * Maximum time to wait for unpublication transaction(s) to complete 
     1822     * during shutdown process, before sending unregistration. The library 
     1823     * tries to wait for the unpublication (un-PUBLISH) to complete before 
     1824     * sending REGISTER request to unregister the account, during library 
     1825     * shutdown process. If the value is set too short, it is possible that 
     1826     * the unregistration is sent before unpublication completes, causing 
     1827     * unpublication request to fail. 
     1828     * 
     1829     * Default: PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC 
     1830     */ 
     1831    unsigned        unpublish_max_wait_time_msec; 
    18031832 
    18041833    /** 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r2940 r2942  
    163163    cfg->reg_timeout = PJSUA_REG_INTERVAL; 
    164164    pjsip_publishc_opt_default(&cfg->publish_opt); 
     165    cfg->unpublish_max_wait_time_msec = PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC; 
    165166    cfg->transport_id = PJSUA_INVALID_ID; 
    166167    cfg->allow_contact_rewrite = PJ_TRUE; 
     
    12291230     
    12301231    if (pjsua_var.endpt) { 
     1232        unsigned max_wait; 
     1233 
    12311234        /* Terminate all calls. */ 
    12321235        pjsua_call_hangup_all(); 
     
    12421245        /* Terminate all presence subscriptions. */ 
    12431246        pjsua_pres_shutdown(); 
     1247 
     1248        /* Wait for sometime until all publish client sessions are done 
     1249         * (ticket #364) 
     1250         */ 
     1251        /* First stage, get the maximum wait time */ 
     1252        max_wait = 100; 
     1253        for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
     1254            if (!pjsua_var.acc[i].valid) 
     1255                continue; 
     1256            if (pjsua_var.acc[i].cfg.unpublish_max_wait_time_msec > max_wait) 
     1257                max_wait = pjsua_var.acc[i].cfg.unpublish_max_wait_time_msec; 
     1258        } 
     1259         
     1260        /* Second stage, wait for unpublications to complete */ 
     1261        for (i=0; i<(int)(max_wait/50); ++i) { 
     1262            unsigned j; 
     1263            for (j=0; j<PJ_ARRAY_SIZE(pjsua_var.acc); ++j) { 
     1264                if (!pjsua_var.acc[j].valid) 
     1265                    continue; 
     1266 
     1267                if (pjsua_var.acc[j].publish_sess) 
     1268                    break; 
     1269            } 
     1270            if (j != PJ_ARRAY_SIZE(pjsua_var.acc)) 
     1271                busy_sleep(50); 
     1272            else 
     1273                break; 
     1274        } 
     1275 
     1276        /* Third stage, forcefully destroy unfinished unpublications */ 
     1277        for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
     1278            if (pjsua_var.acc[i].publish_sess) { 
     1279                pjsip_publishc_destroy(pjsua_var.acc[i].publish_sess); 
     1280                pjsua_var.acc[i].publish_sess = NULL; 
     1281            } 
     1282        } 
    12441283 
    12451284        /* Unregister all accounts */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c

    r2940 r2942  
    993993 
    994994    } else { 
    995         if (param->expiration == -1) { 
     995        if (param->expiration < 1) { 
    996996            /* Could happen if server "forgot" to include Expires header 
    997997             * in the response. We will not renew, so destroy the pubc. 
     
    12021202        acc->online_status = PJ_FALSE; 
    12031203        send_publish(acc_id, PJ_FALSE); 
     1204        /* By ticket #364, don't destroy the session yet (let the callback 
     1205           destroy it) 
    12041206        if (acc->publish_sess) { 
    12051207            pjsip_publishc_destroy(acc->publish_sess); 
    12061208            acc->publish_sess = NULL; 
    12071209        } 
     1210        */ 
    12081211        acc_cfg->publish_enabled = PJ_FALSE; 
    12091212    } 
Note: See TracChangeset for help on using the changeset viewer.