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

Daniel-Constantin Mierla miconda at gmail.com
Wed Feb 4 18:10:56 CET 2015


Module: kamailio
Branch: 4.2
Commit: 008b03ae8361ca06da9042b479c10e760391da72
URL: https://github.com/kamailio/kamailio/commit/008b03ae8361ca06da9042b479c10e760391da72

Author: Alex Balashov <abalashov at evaristesys.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-02-04T18:05:01+01: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.

(cherry picked from commit cd1a59f223e2806ca4c16ab4a8dc1e0ff2b219d1)

---

Modified: modules/evapi/evapi_dispatch.c

---

Diff:  https://github.com/kamailio/kamailio/commit/008b03ae8361ca06da9042b479c10e760391da72.diff
Patch: https://github.com/kamailio/kamailio/commit/008b03ae8361ca06da9042b479c10e760391da72.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