Changeset 4860 for pjproject/trunk
- Timestamp:
- Jun 19, 2014 5:07:12 AM (10 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/sock.h
r4538 r4860 617 617 } pj_ip_mreq; 618 618 619 /* Maximum number of socket options. */ 620 #define PJ_MAX_SOCKOPT_PARAMS 4 621 622 /** 623 * Options to be set for the socket. 624 */ 625 typedef struct pj_sockopt_params 626 { 627 /* The number of options to be applied. */ 628 unsigned cnt; 629 630 /* Array of options to be applied. */ 631 struct { 632 /* The level at which the option is defined. */ 633 int level; 634 635 /* Option name. */ 636 int optname; 637 638 /* Pointer to the buffer in which the option is specified. */ 639 void *optval; 640 641 /* Buffer size of the buffer pointed by optval. */ 642 int optlen; 643 } options[PJ_MAX_SOCKOPT_PARAMS]; 644 } pj_sockopt_params; 619 645 620 646 /***************************************************************************** … … 1306 1332 int optlen); 1307 1333 1334 /** 1335 * Set socket options associated with a socket. This method will apply all the 1336 * options specified, and ignore any errors that might be raised. 1337 * 1338 * @param sockfd The socket descriptor. 1339 * @param params The socket options. 1340 * 1341 * @return PJ_SUCCESS or the last error code. 1342 */ 1343 PJ_DECL(pj_status_t) pj_sock_setsockopt_params( pj_sock_t sockfd, 1344 const pj_sockopt_params *params); 1308 1345 1309 1346 /** -
pjproject/trunk/pjlib/include/pj/ssl_sock.h
r4829 r4860 750 750 pj_bool_t qos_ignore_error; 751 751 752 /** 753 * Specify options to be set on the transport. 754 * 755 * By default there is no options. 756 * 757 */ 758 pj_sockopt_params sockopt_params; 759 760 /** 761 * Specify if the transport should ignore any errors when setting the 762 * sockopt parameters. 763 * 764 * Default: PJ_TRUE 765 * 766 */ 767 pj_bool_t sockopt_ignore_error; 752 768 753 769 } pj_ssl_sock_param; -
pjproject/trunk/pjlib/src/pj/sock_bsd.c
r4537 r4860 27 27 #include <pj/unicode.h> 28 28 29 #define THIS_FILE "sock_bsd.c" 30 29 31 /* 30 32 * Address families conversion. … … 766 768 int optlen) 767 769 { 768 PJ_CHECK_STACK(); 769 if (setsockopt(sock, level, optname, (const char*)optval, optlen) != 0) 770 int status; 771 PJ_CHECK_STACK(); 772 773 #if (defined(PJ_WIN32) && PJ_WIN32) || (defined(PJ_SUNOS) && PJ_SUNOS) 774 /* Some opt may still need int value (e.g:SO_EXCLUSIVEADDRUSE in win32). */ 775 status = setsockopt(sock, 776 level, 777 ((optname&0xff00)==0xff00)?(int)optname|0xffff0000:optname, 778 (const char*)optval, optlen); 779 #else 780 status = setsockopt(sock, level, optname, (const char*)optval, optlen); 781 #endif 782 783 if (status != 0) 770 784 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); 771 785 else 772 786 return PJ_SUCCESS; 787 } 788 789 /* 790 * Set socket option. 791 */ 792 PJ_DEF(pj_status_t) pj_sock_setsockopt_params( pj_sock_t sockfd, 793 const pj_sockopt_params *params) 794 { 795 unsigned int i = 0; 796 pj_status_t retval = PJ_SUCCESS; 797 PJ_CHECK_STACK(); 798 PJ_ASSERT_RETURN(params, PJ_EINVAL); 799 800 for (;i<params->cnt && i<PJ_MAX_SOCKOPT_PARAMS;++i) { 801 pj_status_t status = pj_sock_setsockopt(sockfd, 802 (pj_uint16_t)params->options[i].level, 803 (pj_uint16_t)params->options[i].optname, 804 params->options[i].optval, 805 params->options[i].optlen); 806 if (status != PJ_SUCCESS) { 807 retval = status; 808 PJ_PERROR(4,(THIS_FILE, status, 809 "Warning: error applying sock opt %d", 810 params->options[i].optname)); 811 } 812 } 813 814 return retval; 773 815 } 774 816 -
pjproject/trunk/pjlib/src/pj/sock_linux_kernel.c
r3553 r4860 36 36 #include <asm/ioctls.h> /* FIONBIO */ 37 37 #include <linux/utsname.h> /* for pj_gethostname() */ 38 39 #define THIS_FILE "sock_linux_kernel.c" 38 40 39 41 /* … … 627 629 628 630 /* 631 * Set socket option. 632 */ 633 PJ_DEF(pj_status_t) pj_sock_setsockopt_params( pj_sock_t sockfd, 634 const pj_sockopt_params *params) 635 { 636 unsigned int i = 0; 637 pj_status_t retval = PJ_SUCCESS; 638 PJ_CHECK_STACK(); 639 PJ_ASSERT_RETURN(params, PJ_EINVAL); 640 641 for (;i<params->cnt && i<PJ_MAX_SOCKOPT_PARAMS;++i) { 642 pj_status_t status = pj_sock_setsockopt(sockfd, 643 params->options[i].level, 644 params->options[i].optname, 645 params->options[i].optval, 646 params->options[i].optlen); 647 if (status != PJ_SUCCESS) { 648 retval = status; 649 PJ_PERROR(4,(THIS_FILE, status, 650 "Warning: error applying sock opt %d", 651 params->options[i].optname)); 652 } 653 } 654 655 return retval; 656 } 657 658 /* 629 659 * Shutdown socket. 630 660 */ -
pjproject/trunk/pjlib/src/pj/ssl_sock_common.c
r3999 r4860 41 41 param->qos_type = PJ_QOS_TYPE_BEST_EFFORT; 42 42 param->qos_ignore_error = PJ_TRUE; 43 44 param->sockopt_ignore_error = PJ_TRUE; 43 45 44 46 /* Security config */ -
pjproject/trunk/pjlib/src/pj/ssl_sock_ossl.c
r4858 r4860 1651 1651 goto on_return; 1652 1652 1653 /* Apply socket options, if specified */ 1654 if (ssock->param.sockopt_params.cnt) { 1655 status = pj_sock_setsockopt_params(ssock->sock, 1656 &ssock->param.sockopt_params); 1657 if (status != PJ_SUCCESS && !ssock->param.sockopt_ignore_error) 1658 goto on_return; 1659 } 1660 1653 1661 /* Update local address */ 1654 1662 ssock->addr_len = src_addr_len; … … 2453 2461 &ssock->param.qos_params, 2, 2454 2462 ssock->pool->obj_name, NULL); 2463 2455 2464 if (status != PJ_SUCCESS && !ssock->param.qos_ignore_error) 2456 2465 goto on_error; 2466 2467 /* Apply socket options, if specified */ 2468 if (ssock->param.sockopt_params.cnt) { 2469 status = pj_sock_setsockopt_params(ssock->sock, 2470 &ssock->param.sockopt_params); 2471 2472 if (status != PJ_SUCCESS && !ssock->param.sockopt_ignore_error) 2473 goto on_error; 2474 } 2457 2475 2458 2476 /* Bind socket */ … … 2537 2555 if (status != PJ_SUCCESS && !ssock->param.qos_ignore_error) 2538 2556 goto on_error; 2557 2558 /* Apply socket options, if specified */ 2559 if (ssock->param.sockopt_params.cnt) { 2560 status = pj_sock_setsockopt_params(ssock->sock, 2561 &ssock->param.sockopt_params); 2562 2563 if (status != PJ_SUCCESS && !ssock->param.sockopt_ignore_error) 2564 goto on_error; 2565 } 2539 2566 2540 2567 /* Bind socket */ -
pjproject/trunk/pjsip/include/pjsip/sip_transport_tcp.h
r4817 r4860 104 104 */ 105 105 pj_qos_params qos_params; 106 107 /** 108 * Specify options to be set on the transport. 109 * 110 * By default there is no options. 111 * 112 */ 113 pj_sockopt_params sockopt_params; 106 114 107 115 } pjsip_tcp_transport_cfg; -
pjproject/trunk/pjsip/include/pjsip/sip_transport_tls.h
r4506 r4860 206 206 pj_bool_t qos_ignore_error; 207 207 208 /** 209 * Specify options to be set on the transport. 210 * 211 * By default there is no options. 212 * 213 */ 214 pj_sockopt_params sockopt_params; 215 216 /** 217 * Specify if the transport should ignore any errors when setting the 218 * sockopt parameters. 219 * 220 * Default: PJ_TRUE 221 * 222 */ 223 pj_bool_t sockopt_ignore_error; 224 208 225 } pjsip_tls_setting; 209 226 … … 235 252 tls_opt->qos_type = PJ_QOS_TYPE_BEST_EFFORT; 236 253 tls_opt->qos_ignore_error = PJ_TRUE; 254 tls_opt->sockopt_ignore_error = PJ_TRUE; 237 255 } 238 256 -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r4793 r4860 2297 2297 pj_qos_params qos_params; 2298 2298 2299 /** 2300 * Specify options to be set on the transport. 2301 * 2302 * By default there is no options. 2303 * 2304 */ 2305 pj_sockopt_params sockopt_params; 2306 2299 2307 } pjsua_transport_config; 2300 2308 -
pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
r4817 r4860 61 61 pj_qos_type qos_type; 62 62 pj_qos_params qos_params; 63 pj_sockopt_params sockopt_params; 63 64 }; 64 65 … … 285 286 pj_memcpy(&listener->qos_params, &cfg->qos_params, 286 287 sizeof(cfg->qos_params)); 288 pj_memcpy(&listener->sockopt_params, &cfg->sockopt_params, 289 sizeof(cfg->sockopt_params)); 287 290 288 291 pj_ansi_strcpy(listener->factory.obj_name, "tcplis"); … … 316 319 } 317 320 } 321 322 /* Apply socket options, if specified */ 323 if (cfg->sockopt_params.cnt) 324 status = pj_sock_setsockopt_params(sock, &cfg->sockopt_params); 318 325 319 326 /* Bind address may be different than factory.local_addr because … … 918 925 2, listener->factory.obj_name, 919 926 "outgoing SIP TCP socket"); 927 928 /* Apply socket options, if specified */ 929 if (listener->sockopt_params.cnt) 930 status = pj_sock_setsockopt_params(sock, &listener->sockopt_params); 931 920 932 921 933 /* Bind to listener's address and any port */ … … 1036 1048 2, listener->factory.obj_name, 1037 1049 "incoming SIP TCP socket"); 1050 1051 /* Apply socket options, if specified */ 1052 if (listener->sockopt_params.cnt) 1053 status = pj_sock_setsockopt_params(sock, &listener->sockopt_params); 1038 1054 1039 1055 /* tcp_create() expect pj_sockaddr, so copy src_addr to temporary var, -
pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c
r4726 r4860 350 350 sizeof(ssock_param.qos_params)); 351 351 352 ssock_param.sockopt_ignore_error = 353 listener->tls_setting.sockopt_ignore_error; 354 /* Copy the sockopt */ 355 pj_memcpy(&ssock_param.sockopt_params, 356 &listener->tls_setting.sockopt_params, 357 sizeof(listener->tls_setting.sockopt_params)); 358 352 359 has_listener = PJ_FALSE; 353 360 … … 954 961 sizeof(ssock_param.qos_params)); 955 962 963 ssock_param.sockopt_ignore_error = 964 listener->tls_setting.sockopt_ignore_error; 965 /* Copy the sockopt */ 966 pj_memcpy(&ssock_param.sockopt_params, 967 &listener->tls_setting.sockopt_params, 968 sizeof(listener->tls_setting.sockopt_params)); 969 956 970 switch(listener->tls_setting.method) { 957 971 case PJSIP_TLSV1_METHOD: -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r4735 r4860 1965 1965 2, THIS_FILE, "SIP UDP socket"); 1966 1966 1967 /* Apply sockopt, if specified */ 1968 if (cfg->sockopt_params.cnt) 1969 status = pj_sock_setsockopt_params(sock, &cfg->sockopt_params); 1970 1967 1971 /* Bind socket */ 1968 1972 status = pj_sock_bind(sock, &bind_addr, pj_sockaddr_get_len(&bind_addr)); … … 2187 2191 sizeof(cfg->qos_params)); 2188 2192 2193 /* Copy the sockopt */ 2194 pj_memcpy(&tcp_cfg.sockopt_params, &cfg->sockopt_params, 2195 sizeof(tcp_cfg.sockopt_params)); 2196 2189 2197 /* Create the TCP transport */ 2190 2198 status = pjsip_tcp_transport_start3(pjsua_var.endpt, &tcp_cfg, &tcp); -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r4823 r4860 299 299 2, THIS_FILE, "RTP socket"); 300 300 301 /* Apply sockopt, if specified */ 302 if (cfg->sockopt_params.cnt) 303 status = pj_sock_setsockopt_params(sock[0], &cfg->sockopt_params); 304 301 305 /* Bind RTP socket */ 302 306 pj_sockaddr_set_port(&bound_addr, acc->next_rtp_port); … … 321 325 &cfg->qos_params, 322 326 2, THIS_FILE, "RTCP socket"); 327 328 /* Apply sockopt, if specified */ 329 if (cfg->sockopt_params.cnt) 330 status = pj_sock_setsockopt_params(sock[1], &cfg->sockopt_params); 323 331 324 332 /* Bind RTCP socket */
Note: See TracChangeset
for help on using the changeset viewer.