[sr-dev] git:5.0:b543496e: evapi: dispatcher worker to send event data directly

Victor Seva linuxmaniac at torreviejawireless.org
Wed Nov 29 13:58:37 CET 2017


Module: kamailio
Branch: 5.0
Commit: b543496e9e33639684e88fc28fda7cca61ada239
URL: https://github.com/kamailio/kamailio/commit/b543496e9e33639684e88fc28fda7cca61ada239

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date: 2017-11-29T13:53:01+01:00

evapi: dispatcher worker to send event data directly

- instead of trying to send over internal socket, which is open only for
  reading in this process

(cherry picked from commit 95bd694e75c250d8b26cac071bff2e48e0eb9062)

---

Modified: src/modules/evapi/evapi_dispatch.c
Modified: src/modules/evapi/evapi_mod.c

---

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

---

diff --git a/src/modules/evapi/evapi_dispatch.c b/src/modules/evapi/evapi_dispatch.c
index f4d6ae3375..47fc6a0052 100644
--- a/src/modules/evapi/evapi_dispatch.c
+++ b/src/modules/evapi/evapi_dispatch.c
@@ -44,6 +44,8 @@
 static int _evapi_notify_sockets[2];
 static int _evapi_netstring_format = 1;
 
+extern int _evapi_dispatcher_pid;
+
 #define EVAPI_IPADDR_SIZE	64
 #define EVAPI_TAG_SIZE	64
 #define CLIENT_BUFFER_SIZE	32768
@@ -230,6 +232,7 @@ void evapi_close_notify_sockets_child(void)
 {
 	LM_DBG("closing the notification socket used by children\n");
 	close(_evapi_notify_sockets[1]);
+	_evapi_notify_sockets[1] = -1;
 }
 
 /**
@@ -239,6 +242,7 @@ void evapi_close_notify_sockets_parent(void)
 {
 	LM_DBG("closing the notification socket used by parent\n");
 	close(_evapi_notify_sockets[0]);
+	_evapi_notify_sockets[0] = -1;
 }
 
 /**
@@ -701,11 +705,21 @@ int _evapi_relay(str *evdata, str *ctag, int unicast)
 		emsg->unicast = unicast;
 	}
 
-	LM_DBG("sending [%p] [%.*s] (%d)\n", emsg, emsg->data.len, emsg->data.s, emsg->data.len);
-	len = write(_evapi_notify_sockets[1], &emsg, sizeof(evapi_msg_t*));
-	if(len<=0) {
-		LM_ERR("failed to pass the pointer to evapi dispatcher\n");
-		return -1;
+	LM_DBG("sending [%p] [%.*s] (%d)\n", emsg, emsg->data.len, emsg->data.s,
+			emsg->data.len);
+	if(_evapi_notify_sockets[1]!=-1) {
+		len = write(_evapi_notify_sockets[1], &emsg, sizeof(evapi_msg_t*));
+		if(len<=0) {
+			shm_free(emsg);
+			LM_ERR("failed to pass the pointer to evapi dispatcher\n");
+			return -1;
+		}
+	} else {
+		cfg_update();
+		LM_DBG("dispatching [%p] [%.*s] (%d)\n", emsg,
+				emsg->data.len, emsg->data.s, emsg->data.len);
+		evapi_dispatch_notify(emsg);
+		shm_free(emsg);
 	}
 	return 0;
 }
diff --git a/src/modules/evapi/evapi_mod.c b/src/modules/evapi/evapi_mod.c
index e9a8163948..e9f2da98af 100644
--- a/src/modules/evapi/evapi_mod.c
+++ b/src/modules/evapi/evapi_mod.c
@@ -50,8 +50,9 @@ static int   _evapi_bind_port = 8448;
 static char *_evapi_bind_param = NULL;
 static int   _evapi_netstring_format_param = 1;
 
+int _evapi_dispatcher_pid = -1;
+
 static tm_api_t tmb;
-static int   _evapi_dispatcher_pid = -1;
 
 static int  mod_init(void);
 static int  child_init(int);




More information about the sr-dev mailing list