- Timestamp:
- Apr 26, 2012 11:53:33 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_acc.c
r4041 r4095 34 34 35 35 static void schedule_reregistration(pjsua_acc *acc); 36 static void keep_alive_timer_cb(pj_timer_heap_t *th, pj_timer_entry *te); 36 37 37 38 /* … … 562 563 PJ_DEF(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id) 563 564 { 565 pjsua_acc *acc; 564 566 unsigned i; 565 567 … … 570 572 PJSUA_LOCK(); 571 573 574 acc = &pjsua_var.acc[acc_id]; 575 576 /* Cancel keep-alive timer, if any */ 577 if (acc->ka_timer.id) { 578 pjsip_endpt_cancel_timer(pjsua_var.endpt, &acc->ka_timer); 579 acc->ka_timer.id = PJ_FALSE; 580 } 581 if (acc->ka_transport) { 582 pjsip_transport_dec_ref(acc->ka_transport); 583 acc->ka_transport = NULL; 584 } 585 572 586 /* Cancel any re-registration timer */ 573 pjsua_cancel_timer(& pjsua_var.acc[acc_id].auto_rereg.timer);587 pjsua_cancel_timer(&acc->auto_rereg.timer); 574 588 575 589 /* Delete registration */ 576 if ( pjsua_var.acc[acc_id].regc != NULL) {590 if (acc->regc != NULL) { 577 591 pjsua_acc_set_registration(acc_id, PJ_FALSE); 578 if ( pjsua_var.acc[acc_id].regc) {579 pjsip_regc_destroy( pjsua_var.acc[acc_id].regc);580 } 581 pjsua_var.acc[acc_id].regc = NULL;592 if (acc->regc) { 593 pjsip_regc_destroy(acc->regc); 594 } 595 acc->regc = NULL; 582 596 } 583 597 … … 586 600 587 601 /* Release account pool */ 588 if ( pjsua_var.acc[acc_id].pool) {589 pj_pool_release( pjsua_var.acc[acc_id].pool);590 pjsua_var.acc[acc_id].pool = NULL;602 if (acc->pool) { 603 pj_pool_release(acc->pool); 604 acc->pool = NULL; 591 605 } 592 606 593 607 /* Invalidate */ 594 pjsua_var.acc[acc_id].valid = PJ_FALSE;595 pjsua_var.acc[acc_id].contact.slen = 0;608 acc->valid = PJ_FALSE; 609 acc->contact.slen = 0; 596 610 597 611 /* Remove from array */ … … 838 852 acc->cfg.timer_setting = cfg->timer_setting; 839 853 840 /* Transport and keep-alive*/854 /* Transport */ 841 855 if (acc->cfg.transport_id != cfg->transport_id) { 842 856 acc->cfg.transport_id = cfg->transport_id; 843 857 update_reg = PJ_TRUE; 844 858 } 845 acc->cfg.ka_interval = cfg->ka_interval; 859 860 /* Update keep-alive */ 861 if (acc->cfg.ka_interval != cfg->ka_interval || 862 pj_strcmp(&acc->cfg.ka_data, &cfg->ka_data)) 863 { 864 pjsip_transport *ka_transport = acc->ka_transport; 865 866 if (acc->ka_timer.id) { 867 pjsip_endpt_cancel_timer(pjsua_var.endpt, &acc->ka_timer); 868 acc->ka_timer.id = PJ_FALSE; 869 } 870 if (acc->ka_transport) { 871 pjsip_transport_dec_ref(acc->ka_transport); 872 acc->ka_transport = NULL; 873 } 874 875 acc->cfg.ka_interval = cfg->ka_interval; 876 877 if (cfg->ka_interval) { 878 if (ka_transport) { 879 /* Keep-alive has been running so we can just restart it */ 880 pj_time_val delay; 881 882 pjsip_transport_add_ref(ka_transport); 883 acc->ka_transport = ka_transport; 884 885 acc->ka_timer.cb = &keep_alive_timer_cb; 886 acc->ka_timer.user_data = (void*)acc; 887 888 delay.sec = acc->cfg.ka_interval; 889 delay.msec = 0; 890 status = pjsua_schedule_timer(&acc->ka_timer, &delay); 891 if (status == PJ_SUCCESS) { 892 acc->ka_timer.id = PJ_TRUE; 893 } else { 894 pjsip_transport_dec_ref(ka_transport); 895 acc->ka_transport = NULL; 896 pjsua_perror(THIS_FILE, "Error starting keep-alive timer", 897 status); 898 } 899 900 } else { 901 /* Keep-alive has not been running, we need to (re)register 902 * first. 903 */ 904 update_reg = PJ_TRUE; 905 } 906 } 907 } 908 846 909 if (pj_strcmp(&acc->cfg.ka_data, &cfg->ka_data)) 847 910 pj_strdup(acc->pool, &acc->cfg.ka_data, &cfg->ka_data); … … 1527 1590 } 1528 1591 1592 /* Check just in case keep-alive has been disabled. This shouldn't happen 1593 * though as when ka_interval is changed this timer should have been 1594 * cancelled. 1595 */ 1596 if (acc->cfg.ka_interval == 0) 1597 goto on_return; 1598 1529 1599 /* Reschedule next timer */ 1530 1600 delay.sec = acc->cfg.ka_interval; … … 1537 1607 } 1538 1608 1609 on_return: 1539 1610 PJSUA_UNLOCK(); 1540 1611 }
Note: See TracChangeset
for help on using the changeset viewer.