Changeset 4506 for pjproject


Ignore:
Timestamp:
Apr 26, 2013 6:01:43 AM (11 years ago)
Author:
bennylp
Message:

Fixed #1661: Option to use SO_REUSEADDR for TCP and TLS listeners and use it by default on non-Windows platforms

Location:
pjproject/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/ssl_sock.h

    r4146 r4506  
    712712 
    713713    /** 
     714     * Specify if SO_REUSEADDR should be used for listening socket. This 
     715     * option will only be used with accept() operation. 
     716     * 
     717     * Default is PJ_FALSE. 
     718     */ 
     719    pj_bool_t reuse_addr; 
     720 
     721    /** 
    714722     * QoS traffic type to be set on this transport. When application wants 
    715723     * to apply QoS tagging to the transport, it's preferable to set this 
  • pjproject/trunk/pjlib/src/pj/ssl_sock_ossl.c

    r4466 r4506  
    23782378        goto on_error; 
    23792379 
     2380    /* Apply SO_REUSEADDR */ 
     2381    if (ssock->param.reuse_addr) { 
     2382        int enabled = 1; 
     2383        status = pj_sock_setsockopt(ssock->sock, pj_SOL_SOCKET(), 
     2384                                    pj_SO_REUSEADDR(), 
     2385                                    &enabled, sizeof(enabled)); 
     2386        if (status != PJ_SUCCESS) { 
     2387            PJ_PERROR(4,(ssock->pool->obj_name, status, 
     2388                         "Warning: error applying SO_REUSEADDR")); 
     2389        } 
     2390    } 
     2391 
    23802392    /* Apply QoS, if specified */ 
    23812393    status = pj_sock_apply_qos2(ssock->sock, ssock->param.qos_type, 
  • pjproject/trunk/pjsip/include/pjsip/sip_config.h

    r4442 r4506  
    570570 
    571571/** 
     572 * Specify whether TCP listener should use SO_REUSEADDR option. This constant 
     573 * will be used as the default value for the "reuse_addr" field in the 
     574 * pjsip_tcp_transport_cfg structure. 
     575 * 
     576 * Default is FALSE on Windows and TRUE on non-Windows. 
     577 * 
     578 * @see PJSIP_TLS_TRANSPORT_REUSEADDR 
     579 */ 
     580#ifndef PJSIP_TCP_TRANSPORT_REUSEADDR 
     581# if defined(PJ_WIN32) && PJ_WIN32 
     582#   define PJSIP_TCP_TRANSPORT_REUSEADDR        0 
     583# else 
     584#   define PJSIP_TCP_TRANSPORT_REUSEADDR        1 
     585# endif 
     586#endif 
     587 
     588 
     589/** 
    572590 * Set the interval to send keep-alive packet for TCP transports. 
    573591 * If the value is zero, keep-alive will be disabled for TCP. 
     
    676694#endif 
    677695 
     696 
     697/** 
     698 * Specify whether TLS listener should use SO_REUSEADDR option. 
     699 * 
     700 * Default is FALSE on Windows and TRUE on non-Windows. 
     701 * 
     702 * @see PJSIP_TCP_TRANSPORT_REUSEADDR 
     703 */ 
     704#ifndef PJSIP_TLS_TRANSPORT_REUSEADDR 
     705# if defined(PJ_WIN32) && PJ_WIN32 
     706#   define PJSIP_TLS_TRANSPORT_REUSEADDR        0 
     707# else 
     708#   define PJSIP_TLS_TRANSPORT_REUSEADDR        1 
     709# endif 
     710#endif 
    678711 
    679712 
  • pjproject/trunk/pjsip/include/pjsip/sip_transport_tcp.h

    r3553 r4506  
    6363     */ 
    6464    pj_sockaddr         bind_addr; 
     65 
     66    /** 
     67     * Should SO_REUSEADDR be used for the listener socket. 
     68     * Default value is PJSIP_TCP_TRANSPORT_REUSEADDR. 
     69     */ 
     70    pj_bool_t           reuse_addr; 
    6571 
    6672    /** 
  • pjproject/trunk/pjsip/include/pjsip/sip_transport_tls.h

    r4262 r4506  
    175175 
    176176    /** 
     177     * Should SO_REUSEADDR be used for the listener socket. 
     178     * Default value is PJSIP_TLS_TRANSPORT_REUSEADDR. 
     179     */ 
     180    pj_bool_t reuse_addr; 
     181 
     182    /** 
    177183     * QoS traffic type to be set on this transport. When application wants 
    178184     * to apply QoS tagging to the transport, it's preferable to set this 
     
    226232{ 
    227233    pj_memset(tls_opt, 0, sizeof(*tls_opt)); 
     234    tls_opt->reuse_addr = PJSIP_TLS_TRANSPORT_REUSEADDR; 
    228235    tls_opt->qos_type = PJ_QOS_TYPE_BEST_EFFORT; 
    229236    tls_opt->qos_ignore_error = PJ_TRUE; 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c

    r4451 r4506  
    218218    pj_sockaddr_init(cfg->af, &cfg->bind_addr, NULL, 0); 
    219219    cfg->async_cnt = 1; 
     220    cfg->reuse_addr = PJSIP_TCP_TRANSPORT_REUSEADDR; 
    220221} 
    221222 
     
    298299                                2, listener->factory.obj_name,  
    299300                                "SIP TCP listener socket"); 
     301 
     302    /* Apply SO_REUSEADDR */ 
     303    if (cfg->reuse_addr) { 
     304        int enabled = 1; 
     305        status = pj_sock_setsockopt(sock, pj_SOL_SOCKET(), pj_SO_REUSEADDR(), 
     306                                    &enabled, sizeof(enabled)); 
     307        if (status != PJ_SUCCESS) { 
     308            PJ_PERROR(4,(listener->factory.obj_name, status, 
     309                         "Warning: error applying SO_REUSEADDR")); 
     310        } 
     311    } 
    300312 
    301313    /* Bind address may be different than factory.local_addr because 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c

    r4450 r4506  
    338338    ssock_param.ciphers_num = listener->tls_setting.ciphers_num; 
    339339    ssock_param.ciphers = listener->tls_setting.ciphers; 
     340    ssock_param.reuse_addr = listener->tls_setting.reuse_addr; 
    340341    ssock_param.qos_type = listener->tls_setting.qos_type; 
    341342    ssock_param.qos_ignore_error = listener->tls_setting.qos_ignore_error; 
Note: See TracChangeset for help on using the changeset viewer.