summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2013-04-26 06:01:43 +0000
committerBenny Prijono <bennylp@teluu.com>2013-04-26 06:01:43 +0000
commit794a79431f46ba8a6c5316c082c064b1b768586a (patch)
tree6f176e0204a84a4ea29578c15c833903eb745818 /pjlib
parent688fdf10f000a6190b31eee6fc183decda5005aa (diff)
Fixed #1661: Option to use SO_REUSEADDR for TCP and TLS listeners and use it by default on non-Windows platforms
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4506 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/include/pj/ssl_sock.h8
-rw-r--r--pjlib/src/pj/ssl_sock_ossl.c12
2 files changed, 20 insertions, 0 deletions
diff --git a/pjlib/include/pj/ssl_sock.h b/pjlib/include/pj/ssl_sock.h
index 534c9144..bfad5af2 100644
--- a/pjlib/include/pj/ssl_sock.h
+++ b/pjlib/include/pj/ssl_sock.h
@@ -711,6 +711,14 @@ typedef struct pj_ssl_sock_param
pj_str_t server_name;
/**
+ * Specify if SO_REUSEADDR should be used for listening socket. This
+ * option will only be used with accept() operation.
+ *
+ * Default is PJ_FALSE.
+ */
+ pj_bool_t reuse_addr;
+
+ /**
* QoS traffic type to be set on this transport. When application wants
* to apply QoS tagging to the transport, it's preferable to set this
* field rather than \a qos_param fields since this is more portable.
diff --git a/pjlib/src/pj/ssl_sock_ossl.c b/pjlib/src/pj/ssl_sock_ossl.c
index b774c674..b5098d22 100644
--- a/pjlib/src/pj/ssl_sock_ossl.c
+++ b/pjlib/src/pj/ssl_sock_ossl.c
@@ -2377,6 +2377,18 @@ PJ_DEF(pj_status_t) pj_ssl_sock_start_accept (pj_ssl_sock_t *ssock,
if (status != PJ_SUCCESS)
goto on_error;
+ /* Apply SO_REUSEADDR */
+ if (ssock->param.reuse_addr) {
+ int enabled = 1;
+ status = pj_sock_setsockopt(ssock->sock, pj_SOL_SOCKET(),
+ pj_SO_REUSEADDR(),
+ &enabled, sizeof(enabled));
+ if (status != PJ_SUCCESS) {
+ PJ_PERROR(4,(ssock->pool->obj_name, status,
+ "Warning: error applying SO_REUSEADDR"));
+ }
+ }
+
/* Apply QoS, if specified */
status = pj_sock_apply_qos2(ssock->sock, ssock->param.qos_type,
&ssock->param.qos_params, 2,