|
|
|
@ -174,7 +174,9 @@ static int __message_send(chnl_t *ch, sexp_t *sx, sxmsg_t **msg, struct timespec
|
|
|
|
|
__destroy_msg(m);
|
|
|
|
|
} else {
|
|
|
|
|
*msg = m;
|
|
|
|
|
r = SXOREPLYREQ;
|
|
|
|
|
if(m->opcode == ESXNOCONNECT)
|
|
|
|
|
r = m->opcode;
|
|
|
|
|
else r = SXOREPLYREQ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -252,7 +254,6 @@ int msg_reply_timed(sxmsg_t *msg, sexp_t *sx, struct timespec *tio)
|
|
|
|
|
return __msg_reply(msg, sx, tio, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: continue. Implement wait for delivery and queue addition
|
|
|
|
|
/*
|
|
|
|
|
* How message sending works:
|
|
|
|
|
* 1. Create a message structure assigned to the channel,
|
|
|
|
@ -260,7 +261,8 @@ int msg_reply_timed(sxmsg_t *msg, sexp_t *sx, struct timespec *tio)
|
|
|
|
|
* 3. Put the message to the queue
|
|
|
|
|
* 4. Wait for job execution
|
|
|
|
|
*/
|
|
|
|
|
static int __message_send_pulse(chnl_t *ch, sexp_t *sx, struct timespec *tio)
|
|
|
|
|
static int __message_send_pulse(chnl_t *ch, sexp_t *sx, struct timespec *tio,
|
|
|
|
|
int nowait)
|
|
|
|
|
{
|
|
|
|
|
int r = 0;
|
|
|
|
|
sxmsg_t *m = NULL;
|
|
|
|
@ -290,12 +292,15 @@ static int __message_send_pulse(chnl_t *ch, sexp_t *sx, struct timespec *tio)
|
|
|
|
|
r = pth_queue_add(co->mqueue, (void *)m, USR_MSG);
|
|
|
|
|
if(r) return r; /* FIXME: better give up */
|
|
|
|
|
|
|
|
|
|
if(m->flags & ESXMSG_PENDING) {
|
|
|
|
|
if(!tio) pthread_mutex_lock(&(m->wait));
|
|
|
|
|
else pthread_mutex_timedlock(&(m->wait), tio);
|
|
|
|
|
if(!nowait) {
|
|
|
|
|
if(m->flags & ESXMSG_PENDING) {
|
|
|
|
|
if(!tio) pthread_mutex_lock(&(m->wait));
|
|
|
|
|
else pthread_mutex_timedlock(&(m->wait), tio);
|
|
|
|
|
}
|
|
|
|
|
if(tio && (m->flags & ESXMSG_PENDING))
|
|
|
|
|
return SXOTIMEDOUT;
|
|
|
|
|
}
|
|
|
|
|
if(tio && (m->flags & ESXMSG_PENDING))
|
|
|
|
|
return SXOTIMEDOUT;
|
|
|
|
|
|
|
|
|
|
if(!m->payload) {
|
|
|
|
|
r = m->opcode;
|
|
|
|
|
/* first remove the message from tree */
|
|
|
|
@ -316,15 +321,15 @@ static int __message_send_pulse(chnl_t *ch, sexp_t *sx, struct timespec *tio)
|
|
|
|
|
|
|
|
|
|
int msg_send_pulse(chnl_t *ch, sexp_t *sx)
|
|
|
|
|
{
|
|
|
|
|
return __message_send_pulse(ch, sx, NULL);
|
|
|
|
|
return __message_send_pulse(ch, sx, NULL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_send_pulse_timed(chnl_t *ch, sexp_t *sx, struct timespec *tio)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
return __message_send_pulse(ch, sx, tio, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_send_pulse_nowait(chnl_t *ch, sexp_t *sx)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
return __message_send_pulse(ch, sx, NULL, 1);
|
|
|
|
|
}
|
|
|
|
|