Skip to content

Commit

Permalink
Set default SSL sockopt param to have TCP_NODELAY for GnuTLS backend (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
sauwming authored Sep 20, 2023
1 parent cde87db commit 7ff31e3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion pjlib/include/pj/ssl_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,8 @@ typedef struct pj_ssl_sock_param
/**
* Specify options to be set on the transport.
*
* By default there is no options.
* For GnuTLS backend, by default TCP_NODELAY will be set. For other
* SSL backends, the default is no options.
*
*/
pj_sockopt_params sockopt_params;
Expand Down
12 changes: 12 additions & 0 deletions pjlib/src/pj/ssl_sock_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@ PJ_DEF(void) pj_ssl_sock_param_default(pj_ssl_sock_param *param)
param->async_cnt = 1;
param->concurrency = -1;
param->whole_data = PJ_TRUE;

#if (PJ_SSL_SOCK_IMP == PJ_SSL_SOCK_IMP_GNUTLS)
/* GnuTLS is allowed to send bigger chunks.*/
param->send_buffer_size = 65536;

{
/* For GnuTLS, TCP_NODELAY is needed to avoid polling delay. */
static pj_int32_t val = 1;
param->sockopt_params.cnt = 1;
param->sockopt_params.options[0].level = pj_SOL_TCP();
param->sockopt_params.options[0].optname = pj_TCP_NODELAY();
param->sockopt_params.options[0].optval = &val;
param->sockopt_params.options[0].optlen = sizeof(pj_int32_t);
}

#else
param->send_buffer_size = 8192;
#endif
Expand Down
3 changes: 2 additions & 1 deletion pjsip/include/pjsip/sip_transport_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ typedef struct pjsip_tls_setting
/**
* Specify options to be set on the transport.
*
* By default there is no options.
* By default, this is unset, which means that the underlying sockopt
* params as returned by #pj_ssl_sock_param_default() will be used.
*
*/
pj_sockopt_params sockopt_params;
Expand Down
16 changes: 10 additions & 6 deletions pjsip/src/pjsip/sip_transport_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,11 @@ static void set_ssock_param(pj_ssl_sock_param *ssock_param,
ssock_param->enable_renegotiation =
listener->tls_setting.enable_renegotiation;
/* Copy the sockopt */
pj_memcpy(&ssock_param->sockopt_params,
&listener->tls_setting.sockopt_params,
sizeof(listener->tls_setting.sockopt_params));
if (listener->tls_setting.sockopt_params.cnt > 0) {
pj_memcpy(&ssock_param->sockopt_params,
&listener->tls_setting.sockopt_params,
sizeof(listener->tls_setting.sockopt_params));
}

sip_ssl_method = listener->tls_setting.method;
sip_ssl_proto = listener->tls_setting.proto;
Expand Down Expand Up @@ -1233,9 +1235,11 @@ static pj_status_t lis_create_transport(pjsip_tpfactory *factory,

ssock_param.enable_renegotiation = listener->tls_setting.enable_renegotiation;
/* Copy the sockopt */
pj_memcpy(&ssock_param.sockopt_params,
&listener->tls_setting.sockopt_params,
sizeof(listener->tls_setting.sockopt_params));
if (listener->tls_setting.sockopt_params.cnt > 0) {
pj_memcpy(&ssock_param.sockopt_params,
&listener->tls_setting.sockopt_params,
sizeof(listener->tls_setting.sockopt_params));
}

sip_ssl_method = listener->tls_setting.method;
sip_ssl_proto = listener->tls_setting.proto;
Expand Down

0 comments on commit 7ff31e3

Please sign in to comment.