|
|
|
@ -997,117 +997,6 @@ static int __create_reg_msg_mould(sxmsg_t **msg, chnl_t *ch, ulong_t mid)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: check and continue
|
|
|
|
|
static int __default_msg_pulse(void *cctx, sexp_t *sx)
|
|
|
|
|
{
|
|
|
|
|
conn_t *co = (conn_t *)cctx;
|
|
|
|
|
usrtc_node_t *node = NULL;
|
|
|
|
|
chnl_t *chan = NULL;
|
|
|
|
|
int r = 0;
|
|
|
|
|
sexp_t *lsx = NULL, *sx_iter = NULL;
|
|
|
|
|
sexp_t *sx_sublist = NULL, *sx_value = NULL;
|
|
|
|
|
ulong_t chnl_id = -1;
|
|
|
|
|
ulong_t msg_id = -1;
|
|
|
|
|
sexp_t *msg = NULL;
|
|
|
|
|
sxmsg_t *smsg = NULL;
|
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
|
|
/* get parameters from the message */
|
|
|
|
|
if(sexp_list_cdr(sx, &lsx)) return ESXRCBADPROT;
|
|
|
|
|
if(!SEXP_IS_LIST(lsx)) return ESXRCBADPROT;
|
|
|
|
|
|
|
|
|
|
/* find channel id */
|
|
|
|
|
SEXP_ITERATE_LIST(lsx, sx_iter, idx) {
|
|
|
|
|
if(SEXP_IS_LIST(sx_iter)) {
|
|
|
|
|
sx_sublist = sx_iter;
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
if(SEXP_IS_TYPE(sx_iter, SEXP_BASIC)) {
|
|
|
|
|
if(strcmp(sx_iter->val, ":chid")) {
|
|
|
|
|
continue; // ignore it
|
|
|
|
|
}
|
|
|
|
|
sx_value = sx_iter->next;
|
|
|
|
|
if(!sx_value || !SEXP_IS_TYPE(sx_value, SEXP_BASIC)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
chnl_id = atol(sx_value->val);
|
|
|
|
|
} else continue; // ignore it
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lsx = sx_sublist;
|
|
|
|
|
/* find message id */
|
|
|
|
|
SEXP_ITERATE_LIST(lsx, sx_iter, idx) {
|
|
|
|
|
if(SEXP_IS_LIST(sx_iter)) {
|
|
|
|
|
msg = sx_iter;
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
if(SEXP_IS_TYPE(sx_iter, SEXP_BASIC)) {
|
|
|
|
|
if(strcmp(sx_iter->val, ":msgid")) {
|
|
|
|
|
continue; // ignore
|
|
|
|
|
}
|
|
|
|
|
sx_value = sx_iter->next;
|
|
|
|
|
if(!sx_value || !SEXP_IS_TYPE(sx_value, SEXP_BASIC)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
msg_id = atol(sx_value->val);
|
|
|
|
|
} else continue; // ignore it
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(msg_id < 0 || chnl_id < 0) {
|
|
|
|
|
return ESXRCBADPROT;
|
|
|
|
|
}
|
|
|
|
|
/* find channel */
|
|
|
|
|
if(!(node = usrtc_lookup(co->chnl_tree, &chnl_id))) return ENOENT;
|
|
|
|
|
else chan = (chnl_t *)usrtc_node_getdata(node);
|
|
|
|
|
/* lookup for the message */
|
|
|
|
|
pthread_rwlock_rdlock(&(chan->msglock));
|
|
|
|
|
if(!(node = usrtc_lookup(chan->msgs_tree, &msg_id))) {
|
|
|
|
|
pthread_rwlock_unlock(&(chan->msglock));
|
|
|
|
|
/* here, rpc lookup has no sense, just put this job to the queue */
|
|
|
|
|
/* btw, we're need to create a message first */
|
|
|
|
|
r = __create_reg_msg_mould(&smsg, chan, msg_id);
|
|
|
|
|
if(r) return r;
|
|
|
|
|
|
|
|
|
|
/* assign the message */
|
|
|
|
|
smsg->opcode = 0;
|
|
|
|
|
smsg->payload = (void *)msg;
|
|
|
|
|
|
|
|
|
|
/* assign initial S-expression structure */
|
|
|
|
|
smsg->initial_sx = sx;
|
|
|
|
|
|
|
|
|
|
/* put the message to the search tree */
|
|
|
|
|
pthread_rwlock_wrlock(&(chan->msglock));
|
|
|
|
|
usrtc_insert(chan->msgs_tree, &(smsg->pendingq_node), &(smsg->mid));
|
|
|
|
|
pthread_rwlock_unlock(&(chan->msglock));
|
|
|
|
|
} else {
|
|
|
|
|
//printf(">>>>>>>>>>>>>>>>>>>msg_id = %lu\n", msg_id);
|
|
|
|
|
pthread_rwlock_unlock(&(chan->msglock));
|
|
|
|
|
smsg = (sxmsg_t *)usrtc_node_getdata(node);
|
|
|
|
|
msg_return(smsg, EEXIST);
|
|
|
|
|
return EEXIST;
|
|
|
|
|
}
|
|
|
|
|
/* put job to the queue and give up */
|
|
|
|
|
r = pth_queue_add(co->rqueue, (void *)smsg, USR_MSG);
|
|
|
|
|
if(r) { /* cannot put job to the queue */
|
|
|
|
|
pthread_rwlock_wrlock(&(chan->msglock));
|
|
|
|
|
usrtc_delete(chan->msgs_tree, &(smsg->pendingq_node));
|
|
|
|
|
pthread_rwlock_unlock(&(chan->msglock));
|
|
|
|
|
__destroy_msg(smsg);
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//msg_return(smsg, r);
|
|
|
|
|
|
|
|
|
|
/* put to the IN queue */
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __default_msg_pulse_ret(void *cctx, sexp_t *sx)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __default_msg(void *cctx, sexp_t *sx)
|
|
|
|
|
{
|
|
|
|
|
conn_t *co = (conn_t *)cctx;
|
|
|
|
@ -1535,8 +1424,6 @@ static int __init_systemrpc_tree(usrtc_t *rtree)
|
|
|
|
|
if(__insert_rpc_function(rtree, "ch-close", __default_ch_close)) goto __fail;
|
|
|
|
|
if(__insert_rpc_function(rtree, "ch-close-ret", __default_ch_close_ret)) goto __fail;
|
|
|
|
|
/* messaging functions */
|
|
|
|
|
if(__insert_rpc_function(rtree, "ch-msg-pulse", __default_msg_pulse)) goto __fail;
|
|
|
|
|
if(__insert_rpc_function(rtree, "ch-msg-pulse-ret", __default_msg_pulse_ret)) goto __fail;
|
|
|
|
|
if(__insert_rpc_function(rtree, "ch-msg", __default_msg)) goto __fail;
|
|
|
|
|
if(__insert_rpc_function(rtree, "ch-msg-rete", __default_msg_return)) goto __fail;
|
|
|
|
|
if(__insert_rpc_function(rtree, "ch-msg-rapid", __default_msg_rapid)) goto __fail;
|
|
|
|
@ -1785,27 +1672,6 @@ static void *__msg_queue_thread(void *ctx)
|
|
|
|
|
pthread_mutex_unlock(&(msg->wait));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else { /* pulse messages */
|
|
|
|
|
/* here we're shouldn't process reply procedure */
|
|
|
|
|
snprintf(buf, 4096, "(ch-msg-pulse (:chid %lu (:msgid %lu ", ch->cid,
|
|
|
|
|
msg->mid);
|
|
|
|
|
len = strlen(buf); /* FIXME: code double shit ! */
|
|
|
|
|
tb += len*sizeof(char);
|
|
|
|
|
if(print_sexp(tb, 4096 - (len + 4*sizeof(char)), sx) == -1) {
|
|
|
|
|
msg->opcode = ENOMEM;
|
|
|
|
|
/* we don't need to wake up anybody */
|
|
|
|
|
if(msg->flags & ESXMSG_TIMEDOUT) {
|
|
|
|
|
/* clean up all the shit:
|
|
|
|
|
* 1. remove from message tree
|
|
|
|
|
* 2. destroy message itself
|
|
|
|
|
*/
|
|
|
|
|
destroy_sexp(msg->initial_sx);
|
|
|
|
|
msg->initial_sx = NULL;
|
|
|
|
|
msg->payload = NULL;
|
|
|
|
|
__destroy_msg(msg);
|
|
|
|
|
} else
|
|
|
|
|
pthread_mutex_unlock(&(msg->wait));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = strlen(tb);
|
|
|
|
|