Ignore:
Timestamp:
Dec 28, 2016 3:40:07 AM (7 years ago)
Author:
nanang
Message:

Re #1900: More merged from trunk (r5512 mistakenly contains merged changes in third-party dir only).

Location:
pjproject/branches/projects/uwp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/uwp

  • pjproject/branches/projects/uwp/pjsip/src/pjsip/sip_transport.c

    r5173 r5513  
    492492PJ_DEF(pj_status_t) pjsip_tx_data_dec_ref( pjsip_tx_data *tdata ) 
    493493{ 
    494     pj_assert( pj_atomic_get(tdata->ref_cnt) > 0); 
    495     if (pj_atomic_dec_and_get(tdata->ref_cnt) <= 0) { 
     494    pj_atomic_value_t ref_cnt; 
     495     
     496    PJ_ASSERT_RETURN(tdata && tdata->ref_cnt, PJ_EINVAL); 
     497 
     498    ref_cnt = pj_atomic_dec_and_get(tdata->ref_cnt); 
     499    pj_assert( ref_cnt >= 0); 
     500    if (ref_cnt == 0) { 
    496501        tx_data_destroy(tdata); 
    497502        return PJSIP_EBUFDESTROYED; 
     
    12941299{ 
    12951300    pj_bzero(prm, sizeof(*prm)); 
     1301} 
     1302 
     1303static pj_bool_t pjsip_tpmgr_is_tpfactory_valid(pjsip_tpmgr *mgr, 
     1304                                                pjsip_tpfactory *tpf) 
     1305{ 
     1306    pjsip_tpfactory *p; 
     1307 
     1308    pj_lock_acquire(mgr->lock); 
     1309    for (p=mgr->factory_list.next; p!=&mgr->factory_list; p=p->next) { 
     1310        if (p == tpf) { 
     1311            pj_lock_release(mgr->lock); 
     1312            return PJ_TRUE; 
     1313        } 
     1314    } 
     1315    pj_lock_release(mgr->lock); 
     1316 
     1317    return PJ_FALSE; 
    12961318} 
    12971319 
     
    20012023        return PJ_SUCCESS; 
    20022024 
    2003  
    2004     } else if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER && 
    2005                sel->u.listener) 
    2006     { 
    2007         /* Application has requested that a specific listener is to 
    2008          * be used. In this case, skip transport hash table lookup. 
    2009          */ 
    2010  
    2011         /* Verify that the listener type matches the destination type */ 
    2012         if (sel->u.listener->type != type) { 
    2013             pj_lock_release(mgr->lock); 
    2014             return PJSIP_ETPNOTSUITABLE; 
    2015         } 
    2016  
    2017         /* We'll use this listener to create transport */ 
    2018         factory = sel->u.listener; 
    2019  
    20202025    } else { 
    20212026 
    20222027        /* 
    20232028         * This is the "normal" flow, where application doesn't specify 
    2024          * specific transport/listener to be used to send message to. 
     2029         * specific transport to be used to send message to. 
    20252030         * In this case, lookup the transport from the hash table. 
    20262031         */ 
     
    20282033        int key_len; 
    20292034        pjsip_transport *transport; 
     2035 
     2036        /* If listener is specified, verify that the listener type matches 
     2037         * the destination type. 
     2038         */ 
     2039        if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER && sel->u.listener) 
     2040        { 
     2041            if (sel->u.listener->type != type) { 
     2042                pj_lock_release(mgr->lock); 
     2043                return PJSIP_ETPNOTSUITABLE; 
     2044            } 
     2045        } 
    20302046 
    20312047        pj_bzero(&key, sizeof(key)); 
     
    20702086        } 
    20712087 
     2088        /* If transport is found and listener is specified, verify listener */ 
     2089        else if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER && 
     2090                 sel->u.listener && transport->factory != sel->u.listener) 
     2091        { 
     2092            transport = NULL; 
     2093            /* This will cause a new transport to be created which will be a 
     2094             * 'duplicate' of the existing transport (same type & remote addr, 
     2095             * but different factory). Any future hash lookup will return 
     2096             * the new one, and eventually the old one will still be freed 
     2097             * (by application or #1774). 
     2098             */ 
     2099        } 
     2100 
    20722101        if (transport!=NULL && !transport->is_shutdown) { 
    20732102            /* 
     
    20822111        } 
    20832112 
     2113 
    20842114        /* 
    20852115         * Transport not found! 
    2086          * Find factory that can create such transport. 
     2116         * So we need to create one, find factory that can create 
     2117         * such transport. 
    20872118         */ 
    2088         factory = mgr->factory_list.next; 
    2089         while (factory != &mgr->factory_list) { 
    2090             if (factory->type == type) 
    2091                 break; 
    2092             factory = factory->next; 
    2093         } 
    2094  
    2095         if (factory == &mgr->factory_list) { 
    2096             /* No factory can create the transport! */ 
    2097             pj_lock_release(mgr->lock); 
    2098             TRACE_((THIS_FILE, "No suitable factory was found either")); 
    2099             return PJSIP_EUNSUPTRANSPORT; 
     2119        if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER && sel->u.listener) 
     2120        { 
     2121            /* Application has requested that a specific listener is to 
     2122             * be used. 
     2123             */ 
     2124 
     2125            /* Verify that the listener type matches the destination type */ 
     2126            if (sel->u.listener->type != type) { 
     2127                pj_lock_release(mgr->lock); 
     2128                return PJSIP_ETPNOTSUITABLE; 
     2129            } 
     2130 
     2131            /* We'll use this listener to create transport */ 
     2132            factory = sel->u.listener; 
     2133 
     2134            /* Verify if listener is still valid */ 
     2135            if (!pjsip_tpmgr_is_tpfactory_valid(mgr, factory)) { 
     2136                pj_lock_release(mgr->lock); 
     2137                PJ_LOG(3,(THIS_FILE, "Specified factory for creating " 
     2138                                     "transport is not found")); 
     2139                return PJ_ENOTFOUND; 
     2140            } 
     2141 
     2142        } else { 
     2143 
     2144            /* Find factory with type matches the destination type */ 
     2145            factory = mgr->factory_list.next; 
     2146            while (factory != &mgr->factory_list) { 
     2147                if (factory->type == type) 
     2148                    break; 
     2149                factory = factory->next; 
     2150            } 
     2151 
     2152            if (factory == &mgr->factory_list) { 
     2153                /* No factory can create the transport! */ 
     2154                pj_lock_release(mgr->lock); 
     2155                TRACE_((THIS_FILE, "No suitable factory was found either")); 
     2156                return PJSIP_EUNSUPTRANSPORT; 
     2157            } 
    21002158        } 
    21012159    } 
     
    21172175            {pj_lock_release(mgr->lock); return PJ_EBUG;}); 
    21182176        pjsip_transport_add_ref(*tp); 
     2177        (*tp)->factory = factory; 
    21192178    } 
    21202179    pj_lock_release(mgr->lock); 
Note: See TracChangeset for help on using the changeset viewer.