Ignore:
Timestamp:
Feb 6, 2014 5:09:52 AM (10 years ago)
Author:
ming
Message:

Fixed #1733: Fix polling mechanism during STUN server resolution

File:
1 edited

Legend:

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

    r4704 r4735  
    12391239                  sess->srv[sess->idx].ptr, errmsg)); 
    12401240 
    1241         sess->status = status; 
    1242  
    12431241        pj_stun_sock_destroy(stun_sock); 
    12441242        sess->stun_sock = NULL; 
    12451243 
    12461244        ++sess->idx; 
     1245        if (sess->idx >= sess->count) 
     1246            sess->status = status; 
     1247 
    12471248        resolve_stun_entry(sess); 
    12481249 
     
    12741275static void resolve_stun_entry(pjsua_stun_resolve *sess) 
    12751276{ 
     1277    pj_status_t status = PJ_EUNKNOWN; 
     1278 
    12761279    stun_resolve_add_ref(sess); 
    12771280 
     
    12911294 
    12921295        /* Parse the server entry into host:port */ 
    1293         sess->status = pj_sockaddr_parse2(af, 0, &sess->srv[sess->idx], 
     1296        status = pj_sockaddr_parse2(af, 0, &sess->srv[sess->idx], 
    12941297                                          &hostpart, &port, NULL); 
    1295         if (sess->status != PJ_SUCCESS) { 
    1296             PJ_LOG(2,(THIS_FILE, "Invalid STUN server entry %s", target)); 
     1298        if (status != PJ_SUCCESS) { 
     1299            PJ_LOG(2,(THIS_FILE, "Invalid STUN server entry %s", target)); 
    12971300            continue; 
    12981301        } 
     
    13101313        pj_bzero(&stun_sock_cb, sizeof(stun_sock_cb)); 
    13111314        stun_sock_cb.on_status = &test_stun_on_status; 
    1312         sess->status = pj_stun_sock_create(&pjsua_var.stun_cfg, "stunresolve", 
     1315        status = pj_stun_sock_create(&pjsua_var.stun_cfg, "stunresolve", 
    13131316                                           pj_AF_INET(), &stun_sock_cb, 
    13141317                                           NULL, sess, &sess->stun_sock); 
    1315         if (sess->status != PJ_SUCCESS) { 
     1318        if (status != PJ_SUCCESS) { 
    13161319            char errmsg[PJ_ERR_MSG_SIZE]; 
    1317             pj_strerror(sess->status, errmsg, sizeof(errmsg)); 
     1320            pj_strerror(status, errmsg, sizeof(errmsg)); 
    13181321            PJ_LOG(4,(THIS_FILE,  
    13191322                     "Error creating STUN socket for %s: %s", 
     
    13231326        } 
    13241327 
    1325         sess->status = pj_stun_sock_start(sess->stun_sock, &hostpart, 
     1328        status = pj_stun_sock_start(sess->stun_sock, &hostpart, 
    13261329                                          port, pjsua_var.resolver); 
    1327         if (sess->status != PJ_SUCCESS) { 
     1330        if (status != PJ_SUCCESS) { 
    13281331            char errmsg[PJ_ERR_MSG_SIZE]; 
    1329             pj_strerror(sess->status, errmsg, sizeof(errmsg)); 
     1332            pj_strerror(status, errmsg, sizeof(errmsg)); 
    13301333            PJ_LOG(4,(THIS_FILE,  
    13311334                     "Error starting STUN socket for %s: %s", 
     
    13471350    if (sess->idx >= sess->count) { 
    13481351        /* No more entries to try */ 
    1349         PJ_ASSERT_ON_FAIL(sess->status != PJ_SUCCESS,  
    1350                           sess->status = PJ_EUNKNOWN); 
     1352        pj_assert(status != PJ_SUCCESS || sess->status != PJ_EPENDING); 
     1353        if (sess->status == PJ_EPENDING) 
     1354            sess->status = status; 
    13511355        stun_resolve_complete(sess); 
    13521356    } 
     
    13991403 
    14001404    while (sess->status == PJ_EPENDING) { 
    1401         pjsua_handle_events(50); 
     1405        /* If there is no worker thread or 
     1406         * the function is called from the only worker thread, 
     1407         * we have to handle the events here. 
     1408         */ 
     1409        if (pjsua_var.thread[0] == NULL || 
     1410            (pj_thread_this() == pjsua_var.thread[0] && 
     1411             pjsua_var.ua_cfg.thread_cnt == 1)) 
     1412            { 
     1413            pjsua_handle_events(50); 
     1414        } else { 
     1415            pj_thread_sleep(20); 
     1416        } 
    14021417    } 
    14031418 
     
    14851500        if (wait) { 
    14861501            while (pjsua_var.stun_status == PJ_EPENDING) { 
    1487                 if (pjsua_var.thread[0] == NULL) 
     1502                /* If there is no worker thread or 
     1503                 * the function is called from the only worker thread, 
     1504                 * we have to handle the events here. 
     1505                 */ 
     1506                if (pjsua_var.thread[0] == NULL || 
     1507                    (pj_thread_this() == pjsua_var.thread[0] && 
     1508                     pjsua_var.ua_cfg.thread_cnt == 1)) 
     1509                { 
    14881510                    pjsua_handle_events(10); 
    1489                 else 
     1511                } else { 
    14901512                    pj_thread_sleep(10); 
     1513                } 
    14911514            } 
    14921515        } 
Note: See TracChangeset for help on using the changeset viewer.