Skip to content

Commit

Permalink
evapi: move clients structure to shm for access from internal workers
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 4, 2023
1 parent 789deca commit ccdd2ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/modules/evapi/evapi_dispatch.c
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
}


/**
*
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/evapi/evapi_dispatch.h
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/modules/evapi/evapi_mod.c
Expand Up @@ -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;
Expand Down

0 comments on commit ccdd2ed

Please sign in to comment.