Module: kamailio
Branch: master
Commit: ccdd2edbeea51f9141654b48d396abe381cd2318
URL:
https://github.com/kamailio/kamailio/commit/ccdd2edbeea51f9141654b48d396abe…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-04-04T08:00:51+02:00
evapi: move clients structure to shm for access from internal workers
---
Modified: src/modules/evapi/evapi_dispatch.c
Modified: src/modules/evapi/evapi_dispatch.h
Modified: src/modules/evapi/evapi_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ccdd2edbeea51f9141654b48d396abe…
Patch:
https://github.com/kamailio/kamailio/commit/ccdd2edbeea51f9141654b48d396abe…
---
diff --git a/src/modules/evapi/evapi_dispatch.c b/src/modules/evapi/evapi_dispatch.c
index f2aef08abf..35aa62ce69 100644
--- a/src/modules/evapi/evapi_dispatch.c
+++ b/src/modules/evapi/evapi_dispatch.c
@@ -40,6 +40,7 @@
#include "../../core/receive.h"
#include "../../core/kemi.h"
#include "../../core/fmsg.h"
+#include "../../core/mem/shm.h"
#include "evapi_dispatch.h"
@@ -185,6 +186,27 @@ evapi_env_t* evapi_queue_get(void)
}
+/**
+ *
+ */
+int evapi_clients_init(void)
+{
+ int i;
+
+ _evapi_clients = (evapi_client_t*)shm_malloc(sizeof(evapi_client_t)
+ * (EVAPI_MAX_CLIENTS+1));
+ if(_evapi_clients==NULL) {
+ LM_ERR("failed to allocate client structures\n");
+ return -1;
+ }
+ memset(_evapi_clients, 0, sizeof(evapi_client_t) * EVAPI_MAX_CLIENTS);
+ for(i=0; i<EVAPI_MAX_CLIENTS; i++) {
+ _evapi_clients[i].sock = -1;
+ }
+ return 0;
+}
+
+
/**
*
*/
@@ -728,20 +750,14 @@ int evapi_run_dispatcher(char *laddr, int lport)
struct ev_io io_notify;
int yes_true = 1;
int fflags = 0;
- int i;
LM_DBG("starting dispatcher processing\n");
- _evapi_clients = (evapi_client_t*)malloc(sizeof(evapi_client_t)
- * (EVAPI_MAX_CLIENTS+1));
if(_evapi_clients==NULL) {
- LM_ERR("failed to allocate client structures\n");
+ LM_ERR("client structures not initialized\n");
exit(-1);
}
- memset(_evapi_clients, 0, sizeof(evapi_client_t) * EVAPI_MAX_CLIENTS);
- for(i=0; i<EVAPI_MAX_CLIENTS; i++) {
- _evapi_clients[i].sock = -1;
- }
+
loop = ev_default_loop(0);
if(loop==NULL) {
@@ -834,7 +850,8 @@ int evapi_run_worker(int prank)
while(1) {
renv = evapi_queue_get();
if(renv != NULL) {
- LM_DBG("processing task: %p\n", renv);
+ LM_DBG("processing task: %p [%.*s]\n", renv,
+ renv->msg.len, ZSW(renv->msg.s));
evapi_run_cfg_route(renv, _evapi_rts.msg_received,
&_evapi_rts.msg_received_name);
shm_free(renv);
diff --git a/src/modules/evapi/evapi_dispatch.h b/src/modules/evapi/evapi_dispatch.h
index c96bcbf275..44f8cb4a86 100644
--- a/src/modules/evapi/evapi_dispatch.h
+++ b/src/modules/evapi/evapi_dispatch.h
@@ -53,6 +53,8 @@ int pv_set_evapi(sip_msg_t *msg, pv_param_t *param, int op,
int evapi_cfg_close(sip_msg_t *msg);
int evapi_set_tag(sip_msg_t* msg, str* stag);
+int evapi_clients_init(void);
+
int evapi_queue_init(void);
#endif
diff --git a/src/modules/evapi/evapi_mod.c b/src/modules/evapi/evapi_mod.c
index 708159ba3a..f2a0f1e44b 100644
--- a/src/modules/evapi/evapi_mod.c
+++ b/src/modules/evapi/evapi_mod.c
@@ -163,6 +163,10 @@ static int mod_init(void)
_evapi_bind_addr = _evapi_bind_param;
}
+ if(evapi_clients_init() < 0) {
+ LM_ERR("failed to init client structures\n");
+ return -1;
+ }
if(evapi_queue_init() < 0) {
LM_ERR("failed to init faked internal message queue\n");
return -1;