Changeset 4389


Ignore:
Timestamp:
Feb 27, 2013 10:44:04 AM (11 years ago)
Author:
ming
Message:

Re #1563: Backported to 1.x

Location:
pjproject/branches/1.x
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.x

  • pjproject/branches/1.x/pjsip/include/pjsua-lib/pjsua_internal.h

    r3829 r4389  
    250250 
    251251    pj_pool_t           *pool;      /**< Pool               */ 
     252    int                  ref_cnt;   /**< Reference count    */ 
     253    pj_bool_t            destroy_flag; /**< To be destroyed */ 
     254    pj_bool_t            has_result; 
    252255    unsigned             count;     /**< # of entries       */ 
    253256    pj_str_t            *srv;       /**< Array of entries   */ 
  • pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_core.c

    r4382 r4389  
    957957} 
    958958 
    959 /* Internal function to destroy STUN resolution session 
    960  * (pj_stun_resolve). 
    961  */ 
     959static void stun_resolve_add_ref(pjsua_stun_resolve *sess) 
     960{ 
     961    ++sess->ref_cnt; 
     962} 
     963 
    962964static void destroy_stun_resolve(pjsua_stun_resolve *sess) 
    963965{ 
     966    sess->destroy_flag = PJ_TRUE; 
     967    if (sess->ref_cnt > 0) 
     968        return; 
     969 
    964970    PJSUA_LOCK(); 
    965971    pj_list_erase(sess); 
     
    970976} 
    971977 
     978static void stun_resolve_dec_ref(pjsua_stun_resolve *sess) 
     979{ 
     980    --sess->ref_cnt; 
     981    if (sess->ref_cnt <= 0 && sess->destroy_flag) 
     982        destroy_stun_resolve(sess); 
     983} 
     984 
     985 
    972986/* This is the internal function to be called when STUN resolution 
    973987 * session (pj_stun_resolve) has completed. 
     
    976990{ 
    977991    pj_stun_resolve_result result; 
     992 
     993    if (sess->has_result) 
     994        goto on_return; 
    978995 
    979996    pj_bzero(&result, sizeof(result)); 
     
    982999    result.name = sess->srv[sess->idx]; 
    9831000    pj_memcpy(&result.addr, &sess->addr, sizeof(result.addr)); 
     1001    sess->has_result = PJ_TRUE; 
    9841002 
    9851003    if (result.status == PJ_SUCCESS) { 
     
    9971015    } 
    9981016 
     1017    stun_resolve_add_ref(sess); 
    9991018    sess->cb(&result); 
    1000  
     1019    stun_resolve_dec_ref(sess); 
     1020 
     1021on_return: 
    10011022    if (!sess->blocking) { 
    10021023        destroy_stun_resolve(sess); 
     
    10601081static void resolve_stun_entry(pjsua_stun_resolve *sess) 
    10611082{ 
     1083    stun_resolve_add_ref(sess); 
     1084 
    10621085    /* Loop while we have entry to try */ 
    10631086    for (; sess->idx < sess->count; ++sess->idx) { 
    10641087        const int af = pj_AF_INET(); 
     1088        char target[64]; 
    10651089        pj_str_t hostpart; 
    10661090        pj_uint16_t port; 
     
    10691093        pj_assert(sess->idx < sess->count); 
    10701094 
     1095        pj_ansi_snprintf(target, sizeof(target), "%.*s", 
     1096                         (int)sess->srv[sess->idx].slen, 
     1097                         sess->srv[sess->idx].ptr); 
     1098 
    10711099        /* Parse the server entry into host:port */ 
    10721100        sess->status = pj_sockaddr_parse2(af, 0, &sess->srv[sess->idx], 
    10731101                                          &hostpart, &port, NULL); 
    10741102        if (sess->status != PJ_SUCCESS) { 
    1075             PJ_LOG(2,(THIS_FILE, "Invalid STUN server entry %.*s",  
    1076                       (int)sess->srv[sess->idx].slen,  
    1077                       sess->srv[sess->idx].ptr)); 
     1103            PJ_LOG(2,(THIS_FILE, "Invalid STUN server entry %s", target)); 
    10781104            continue; 
    10791105        } 
     
    10851111        pj_assert(sess->stun_sock == NULL); 
    10861112 
    1087         PJ_LOG(4,(THIS_FILE, "Trying STUN server %.*s (%d of %d)..", 
    1088                   (int)sess->srv[sess->idx].slen, 
    1089                   sess->srv[sess->idx].ptr, 
    1090                   sess->idx+1, sess->count)); 
     1113        PJ_LOG(4,(THIS_FILE, "Trying STUN server %s (%d of %d)..", 
     1114                  target, sess->idx+1, sess->count)); 
    10911115 
    10921116        /* Use STUN_sock to test this entry */ 
     
    11001124            pj_strerror(sess->status, errmsg, sizeof(errmsg)); 
    11011125            PJ_LOG(4,(THIS_FILE,  
    1102                      "Error creating STUN socket for %.*s: %s", 
    1103                       (int)sess->srv[sess->idx].slen, 
    1104                       sess->srv[sess->idx].ptr, errmsg)); 
     1126                     "Error creating STUN socket for %s: %s", 
     1127                     target, errmsg)); 
    11051128 
    11061129            continue; 
     
    11131136            pj_strerror(sess->status, errmsg, sizeof(errmsg)); 
    11141137            PJ_LOG(4,(THIS_FILE,  
    1115                      "Error starting STUN socket for %.*s: %s", 
    1116                       (int)sess->srv[sess->idx].slen, 
    1117                       sess->srv[sess->idx].ptr, errmsg)); 
    1118  
    1119             pj_stun_sock_destroy(sess->stun_sock); 
    1120             sess->stun_sock = NULL; 
     1138                     "Error starting STUN socket for %s: %s", 
     1139                     target, errmsg)); 
     1140 
     1141            if (sess->stun_sock) { 
     1142                pj_stun_sock_destroy(sess->stun_sock); 
     1143                sess->stun_sock = NULL; 
     1144            } 
    11211145            continue; 
    11221146        } 
     
    11251149         * stun_sock_cb() 
    11261150         */ 
    1127         return; 
     1151        goto on_return; 
    11281152    } 
    11291153 
     
    11341158        stun_resolve_complete(sess); 
    11351159    } 
     1160 
     1161on_return: 
     1162    stun_resolve_dec_ref(sess); 
    11361163} 
    11371164 
Note: See TracChangeset for help on using the changeset viewer.