Changeset 5556


Ignore:
Timestamp:
Feb 20, 2017 1:16:58 AM (8 years ago)
Author:
ming
Message:

Closed #1995: Add API pjsip_transport_shutdown2() to immediately disconnect a transport

Location:
pjproject/trunk/pjsip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_transport.h

    r5308 r5556  
    904904 
    905905/** 
     906 * Start shutdown procedure for this transport. If \a force is false, 
     907 * the API is the same as #pjsip_transport_shutdown(), while 
     908 * if \a force is true, existing transport users will immediately 
     909 * receive PJSIP_TP_STATE_DISCONNECTED notification and should not 
     910 * use the transport anymore. In either case, transport will 
     911 * only be destroyed after all objects release their references. 
     912 * 
     913 * @param tp                The transport. 
     914 * @param force             Force transport to immediately send 
     915 *                          disconnection state notification. 
     916 * 
     917 * @return                  PJ_SUCCESS on success. 
     918 */ 
     919PJ_DECL(pj_status_t) pjsip_transport_shutdown2(pjsip_transport *tp, 
     920                                               pj_bool_t force); 
     921 
     922/** 
    906923 * Destroy a transport when there is no object currently uses the transport. 
    907924 * This function is normally called internally by transport manager or the 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r5400 r5556  
    11641164PJ_DEF(pj_status_t) pjsip_transport_shutdown(pjsip_transport *tp) 
    11651165{ 
     1166    return pjsip_transport_shutdown2(tp, PJ_FALSE); 
     1167} 
     1168 
     1169 
     1170/* 
     1171 * Start shutdown procedure for this transport.  
     1172 */ 
     1173PJ_DEF(pj_status_t) pjsip_transport_shutdown2(pjsip_transport *tp, 
     1174                                              pj_bool_t force) 
     1175{ 
    11661176    pjsip_tpmgr *mgr; 
    11671177    pj_status_t status; 
    11681178    pjsip_tp_state_callback state_cb; 
    11691179 
    1170     TRACE_((THIS_FILE, "Transport %s shutting down", tp->obj_name)); 
     1180    PJ_LOG(4, (THIS_FILE, "Transport %s shutting down, force=%d", 
     1181                          tp->obj_name, force)); 
    11711182 
    11721183    pj_lock_acquire(tp->lock); 
     
    11881199        status = tp->do_shutdown(tp); 
    11891200 
     1201    if (status == PJ_SUCCESS) 
     1202        tp->is_shutdown = PJ_TRUE; 
     1203 
    11901204    /* Notify application of transport shutdown */ 
    11911205    state_cb = pjsip_tpmgr_get_state_cb(tp->tpmgr); 
     
    11941208 
    11951209        pj_bzero(&state_info, sizeof(state_info)); 
    1196         state_info.status = status; 
    1197         (*state_cb)(tp, PJSIP_TP_STATE_SHUTDOWN, &state_info); 
    1198     } 
    1199  
    1200     if (status == PJ_SUCCESS) 
    1201         tp->is_shutdown = PJ_TRUE; 
     1210        state_info.status = PJ_ECANCELLED; 
     1211        (*state_cb)(tp, (force? PJSIP_TP_STATE_DISCONNECTED: 
     1212                    PJSIP_TP_STATE_SHUTDOWN), &state_info); 
     1213    } 
    12021214 
    12031215    /* If transport reference count is zero, start timer count-down */ 
Note: See TracChangeset for help on using the changeset viewer.