Skip to content

Commit

Permalink
async: added async_task_group_route(routename, groupname) function
Browse files Browse the repository at this point in the history
- similar to async_task_route() that allows to specify the group of
  async task processes
  • Loading branch information
miconda committed Feb 15, 2022
1 parent 546639b commit 812e77d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
47 changes: 43 additions & 4 deletions src/modules/async/async_mod.c
Expand Up @@ -56,6 +56,7 @@ static int w_async_ms_route(sip_msg_t *msg, char *rt, char *sec);
static int fixup_async_route(void **param, int param_no);

static int w_async_task_route(sip_msg_t *msg, char *rt, char *p2);
static int w_async_task_group_route(sip_msg_t *msg, char *rt, char *gr);
static int fixup_async_task_route(void **param, int param_no);

/* tm */
Expand All @@ -73,6 +74,8 @@ static cmd_export_t cmds[]={
0, REQUEST_ROUTE|FAILURE_ROUTE},
{"async_task_route", (cmd_function)w_async_task_route, 1, fixup_async_task_route,
0, REQUEST_ROUTE|FAILURE_ROUTE},
{"async_task_group_route", (cmd_function)w_async_task_group_route, 2, fixup_async_task_route,
0, REQUEST_ROUTE|FAILURE_ROUTE},
{0, 0, 0, 0, 0, 0}
};

Expand Down Expand Up @@ -426,7 +429,7 @@ static int fixup_async_route(void **param, int param_no)
/**
*
*/
int ki_async_task_route(sip_msg_t *msg, str *rn)
int ki_async_task_group_route(sip_msg_t *msg, str *rn, str *gn)
{
cfg_action_t *act = NULL;
int ri;
Expand All @@ -453,7 +456,7 @@ int ki_async_task_route(sip_msg_t *msg, str *rn)
}
}

if(async_send_task(msg, act, rn) < 0)
if(async_send_task(msg, act, rn, gn) < 0)
return -1;
/* force exit in config */
return 0;
Expand All @@ -462,7 +465,15 @@ int ki_async_task_route(sip_msg_t *msg, str *rn)
/**
*
*/
static int w_async_task_route(sip_msg_t *msg, char *rt, char *sec)
int ki_async_task_route(sip_msg_t *msg, str *rn)
{
return ki_async_task_group_route(msg, rn, NULL);
}

/**
*
*/
static int w_async_task_route(sip_msg_t *msg, char *rt, char *p2)
{
str rn;

Expand All @@ -476,6 +487,29 @@ static int w_async_task_route(sip_msg_t *msg, char *rt, char *sec)
return ki_async_task_route(msg, &rn);
}

/**
*
*/
static int w_async_task_group_route(sip_msg_t *msg, char *rt, char *gr)
{
str rn;
str gn;

if(msg == NULL)
return -1;

if(fixup_get_svalue(msg, (gparam_t *)rt, &rn) != 0) {
LM_ERR("no async route block name\n");
return -1;
}
if(fixup_get_svalue(msg, (gparam_t *)gr, &gn) != 0) {
LM_ERR("no async group name\n");
return -1;
}

return ki_async_task_group_route(msg, &rn, &gn);
}

/**
*
*/
Expand All @@ -487,7 +521,7 @@ static int fixup_async_task_route(void **param, int param_no)
return -1;
}

if(param_no == 1) {
if(param_no == 1 || param_no == 2) {
if(fixup_spve_null(param, 1) < 0)
return -1;
return 0;
Expand Down Expand Up @@ -515,6 +549,11 @@ static sr_kemi_t sr_kemi_async_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("async"), str_init("task_group_route"),
SR_KEMIP_INT, ki_async_task_group_route,
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},

{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};
Expand Down
15 changes: 11 additions & 4 deletions src/modules/async/async_sleep.c
Expand Up @@ -451,7 +451,7 @@ int async_ms_sleep(sip_msg_t *msg, int milliseconds, cfg_action_t *act, str *cbn
/**
*
*/
int async_send_task(sip_msg_t *msg, cfg_action_t *act, str *cbname)
int async_send_task(sip_msg_t *msg, cfg_action_t *act, str *cbname, str *gname)
{
async_task_t *at;
tm_cell_t *t = 0;
Expand Down Expand Up @@ -501,9 +501,16 @@ int async_send_task(sip_msg_t *msg, cfg_action_t *act, str *cbname)
atp->cbname_len = cbname->len;
}

if (async_task_push(at)<0) {
shm_free(at);
return -1;
if (gname!=NULL && gname->len>0) {
if (async_task_group_push(gname, at)<0) {
shm_free(at);
return -1;
}
} else {
if (async_task_push(at)<0) {
shm_free(at);
return -1;
}
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/async/async_sleep.h
Expand Up @@ -48,6 +48,6 @@ int async_destroy_ms_timer_list(void);
int async_ms_sleep(sip_msg_t *msg, int milliseconds, cfg_action_t *act, str *cbname);
void async_mstimer_exec(unsigned int ticks, void *param);

int async_send_task(sip_msg_t *msg, cfg_action_t *act, str *cbname);
int async_send_task(sip_msg_t *msg, cfg_action_t *act, str *cbname, str *gname);

#endif

0 comments on commit 812e77d

Please sign in to comment.