Ignore:
Timestamp:
Oct 14, 2009 1:58:04 AM (15 years ago)
Author:
bennylp
Message:

Ticket #970: More gracefull PJSUA-LIB shutdown sequence. Enhancements:

  • wait for unregistration to complete (or a preconfigured delay expires)
  • new account config field to set the maximum delay to wait for unregistration
  • rejects incoming requests (INVITE, SUBSCRIBE, and OPTIONS) when shutdown is in progress
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r2942 r2943  
    162162 
    163163    cfg->reg_timeout = PJSUA_REG_INTERVAL; 
     164    cfg->unreg_timeout = PJSUA_UNREG_TIMEOUT; 
    164165    pjsip_publishc_opt_default(&cfg->publish_opt); 
    165166    cfg->unpublish_max_wait_time_msec = PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC; 
     
    304305    { 
    305306        return PJ_FALSE; 
     307    } 
     308 
     309    /* Don't want to handle if shutdown is in progress */ 
     310    if (pjsua_var.thread_quit_flag) { 
     311        pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata,  
     312                                      PJSIP_SC_TEMPORARILY_UNAVAILABLE, NULL, 
     313                                      NULL, NULL); 
     314        return PJ_TRUE; 
    306315    } 
    307316 
     
    12321241        unsigned max_wait; 
    12331242 
     1243        PJ_LOG(4,(THIS_FILE, "Shutting down...")); 
     1244 
    12341245        /* Terminate all calls. */ 
    12351246        pjsua_call_hangup_all(); 
     
    12451256        /* Terminate all presence subscriptions. */ 
    12461257        pjsua_pres_shutdown(); 
     1258 
     1259        /* Destroy media (to shutdown media transports etc) */ 
     1260        pjsua_media_subsys_destroy(); 
    12471261 
    12481262        /* Wait for sometime until all publish client sessions are done 
     
    12911305            } 
    12921306        } 
    1293     } 
    1294  
    1295     /* Destroy endpoint. */ 
    1296     if (pjsua_var.endpt) { 
    12971307 
    12981308        /* Terminate any pending STUN resolution */ 
     
    13061316        } 
    13071317 
     1318        /* Wait until all unregistrations are done (ticket #364) */ 
     1319        /* First stage, get the maximum wait time */ 
     1320        max_wait = 100; 
     1321        for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
     1322            if (!pjsua_var.acc[i].valid) 
     1323                continue; 
     1324            if (pjsua_var.acc[i].cfg.unreg_timeout > max_wait) 
     1325                max_wait = pjsua_var.acc[i].cfg.unreg_timeout; 
     1326        } 
     1327         
     1328        /* Second stage, wait for unregistrations to complete */ 
     1329        for (i=0; i<(int)(max_wait/50); ++i) { 
     1330            unsigned j; 
     1331            for (j=0; j<PJ_ARRAY_SIZE(pjsua_var.acc); ++j) { 
     1332                if (!pjsua_var.acc[j].valid) 
     1333                    continue; 
     1334 
     1335                if (pjsua_var.acc[j].regc) 
     1336                    break; 
     1337            } 
     1338            if (j != PJ_ARRAY_SIZE(pjsua_var.acc)) 
     1339                busy_sleep(50); 
     1340            else 
     1341                break; 
     1342        } 
     1343        /* Note variable 'i' is used below */ 
     1344 
    13081345        /* Wait for some time to allow unregistration and ICE/TURN 
    13091346         * transports shutdown to complete:  
    1310         */ 
    1311         PJ_LOG(4,(THIS_FILE, "Shutting down...")); 
    1312         busy_sleep(1000); 
     1347         */ 
     1348        if (i < 20) 
     1349            busy_sleep(1000 - i*50); 
    13131350 
    13141351        PJ_LOG(4,(THIS_FILE, "Destroying...")); 
    1315  
    1316         /* Terminate all calls again, just in case there's new call 
    1317          * picked up during busy_sleep() 
    1318          */ 
    1319         pjsua_call_hangup_all(); 
    1320  
    1321         /* Destroy media after all polling is done, as there may be 
    1322          * incoming request that needs handling (e.g. OPTIONS) 
    1323          */ 
    1324         pjsua_media_subsys_destroy(); 
    13251352 
    13261353        /* Must destroy endpoint first before destroying pools in 
     
    13471374            } 
    13481375        } 
    1349     } else { 
    1350         /* Destroy media */ 
    1351         pjsua_media_subsys_destroy(); 
    13521376    } 
    13531377 
Note: See TracChangeset for help on using the changeset viewer.