Changeset 5884


Ignore:
Timestamp:
Sep 14, 2018 1:27:32 AM (9 months ago)
Author:
ming
Message:

Fixed #2149: Add option to disable transport connection reuse via the setting pjsip_tpselector.disable_connection_reuse

Thanks to Joshua Colp for the patch.

Location:
pjproject/trunk/pjsip
Files:
2 edited

Legend:

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

    r5851 r5884  
    222222 * should be used to send request. This structure is used when calling 
    223223 * pjsip_tsx_set_transport() and pjsip_dlg_set_transport(). 
     224 * 
     225 * If application disables connection reuse and wants to force creating 
     226 * a new transport, it needs to consider the following couple of things: 
     227 * - If it still wants to reuse an existing transport (if any), it 
     228 *   needs to keep a reference to that transport and specifically set 
     229 *   the transport to be used for sending requests. 
     230 * - Delete those existing transports manually when no longer needed. 
    224231 */ 
    225232typedef struct pjsip_tpselector 
     
    227234    /** The type of data in the union */ 
    228235    pjsip_tpselector_type   type; 
     236 
     237    /** 
     238     * Whether to disable reuse of an existing connection. 
     239     * This setting will be ignored if (type == PJSIP_TPSELECTOR_TRANSPORT) 
     240     * and transport in the union below is set. 
     241     */ 
     242    pj_bool_t disable_connection_reuse; 
    229243 
    230244    /** Union representing the transport/listener criteria to be used. */ 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r5851 r5884  
    21202120        pjsip_transport_key key; 
    21212121        int key_len; 
    2122         pjsip_transport *transport; 
     2122        pjsip_transport *transport = NULL; 
    21232123 
    21242124        /* If listener is specified, verify that the listener type matches 
     
    21332133        } 
    21342134 
    2135         pj_bzero(&key, sizeof(key)); 
    2136         key_len = sizeof(key.type) + addr_len; 
    2137  
    2138         /* First try to get exact destination. */ 
    2139         key.type = type; 
    2140         pj_memcpy(&key.rem_addr, remote, addr_len); 
    2141  
    2142         transport = (pjsip_transport*) 
    2143                     pj_hash_get(mgr->table, &key, key_len, NULL); 
    2144  
    2145         if (transport == NULL) { 
     2135        if (!sel || sel->disable_connection_reuse == PJ_FALSE) { 
     2136            pj_bzero(&key, sizeof(key)); 
     2137            key_len = sizeof(key.type) + addr_len; 
     2138 
     2139            /* First try to get exact destination. */ 
     2140            key.type = type; 
     2141            pj_memcpy(&key.rem_addr, remote, addr_len); 
     2142 
     2143            transport = (pjsip_transport*) 
     2144                        pj_hash_get(mgr->table, &key, key_len, NULL); 
     2145        } 
     2146 
     2147        if (transport == NULL && 
     2148            (!sel || sel->disable_connection_reuse == PJ_FALSE)) 
     2149        { 
    21462150            unsigned flag = pjsip_transport_get_flag_from_type(type); 
    21472151            const pj_sockaddr *remote_addr = (const pj_sockaddr*)remote; 
     
    21812185            /* This will cause a new transport to be created which will be a 
    21822186             * 'duplicate' of the existing transport (same type & remote addr, 
    2183              * but different factory). Any future hash lookup will return 
    2184              * the new one, and eventually the old one will still be freed 
    2185              * (by application or #1774). 
     2187             * but different factory). 
    21862188             */ 
    21872189        } 
     
    22012203 
    22022204        /* 
    2203          * Transport not found! 
    2204          * So we need to create one, find factory that can create 
    2205          * such transport. 
     2205         * Either transport not found, or we don't want to use the existing 
     2206         * transport (such as in the case of different factory or 
     2207         * if connection reuse is disabled). So we need to create one, 
     2208         * find factory that can create such transport. 
     2209         * 
     2210         * If there's an existing transport, its place in the hash table 
     2211         * will be replaced by this new one. And eventually the existing 
     2212         * transport will still be freed (by application or #1774). 
    22062213         */ 
    22072214        if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER && sel->u.listener) 
Note: See TracChangeset for help on using the changeset viewer.