[sr-dev] git:master:cd1a59f2: evapi: Listening socket will be bound with SO_REUSEADDR option so that rebinding does not have to wait for TIME_WAIT connections to clear.

Alex Balashov abalashov at evaristesys.com
Sun Jan 18 23:08:52 CET 2015


Module: kamailio
Branch: master
Commit: cd1a59f223e2806ca4c16ab4a8dc1e0ff2b219d1
URL: https://github.com/kamailio/kamailio/commit/cd1a59f223e2806ca4c16ab4a8dc1e0ff2b219d1

Author: Alex Balashov <abalashov at evaristesys.com>
Committer: Alex Balashov <abalashov at evaristesys.com>
Date: 2015-01-18T17:08:18-05:00

evapi: Listening socket will be bound with SO_REUSEADDR option so that rebinding does not have to wait for TIME_WAIT connections to clear.

---

Modified: modules/evapi/evapi_dispatch.c

---

Diff:  https://github.com/kamailio/kamailio/commit/cd1a59f223e2806ca4c16ab4a8dc1e0ff2b219d1.diff
Patch: https://github.com/kamailio/kamailio/commit/cd1a59f223e2806ca4c16ab4a8dc1e0ff2b219d1.patch

---

diff --git a/modules/evapi/evapi_dispatch.c b/modules/evapi/evapi_dispatch.c
index 6ee7e3d..1ba1c0b 100644
--- a/modules/evapi/evapi_dispatch.c
+++ b/modules/evapi/evapi_dispatch.c
@@ -434,6 +434,7 @@ int evapi_run_dispatcher(char *laddr, int lport)
 	struct hostent *h = NULL;
 	struct ev_io io_server;
 	struct ev_io io_notify;
+	int yes_true = 1;
 
 	LM_DBG("starting dispatcher processing\n");
 
@@ -469,6 +470,18 @@ int evapi_run_dispatcher(char *laddr, int lport)
 	evapi_srv_addr.sin_port   = htons((short)lport);
 	evapi_srv_addr.sin_addr  = *(struct in_addr*)h->h_addr;
 
+	/* Set SO_REUSEADDR option on listening socket so that we don't
+	 * have to wait for connections in TIME_WAIT to go away before 
+	 * re-binding.
+	 */
+
+	if(setsockopt(evapi_srv_sock, SOL_SOCKET, SO_REUSEADDR, 
+		&yes_true, sizeof(int)) < 0) {
+		LM_ERR("cannot set SO_REUSEADDR option on descriptor\n");
+		close(evapi_srv_sock);
+		return -1;
+	}
+
 	if (bind(evapi_srv_sock, (struct sockaddr*)&evapi_srv_addr,
 				sizeof(evapi_srv_addr)) < 0) {
 		LM_ERR("cannot bind to local address and port [%s:%d]\n", laddr, lport);




More information about the sr-dev mailing list