|
|
|
@ -145,33 +145,124 @@ int sxmsg_send_pp(chnl_t *channel, const char *data, size_t datalen, sxmsg_t **o
|
|
|
|
|
/* send a pulse message */
|
|
|
|
|
int sxmsg_pulse(conn_t *co, const char *data, size_t datalen)
|
|
|
|
|
{
|
|
|
|
|
return SNE_FAILED;
|
|
|
|
|
sxmsg_t *msg = malloc(sizeof(sxmsg_t));
|
|
|
|
|
sntllv2_head_t *head;
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
/* a little bit of paranoid tests */
|
|
|
|
|
if(!msg) return SNE_ENOMEM;
|
|
|
|
|
else memset(msg, 0, sizeof(sxmsg_t));
|
|
|
|
|
|
|
|
|
|
/* prepare it */
|
|
|
|
|
head = &msg->mhead;
|
|
|
|
|
head->attr = 0;
|
|
|
|
|
head->attr = SXMSG_PULSE | SXMSG_LINK;
|
|
|
|
|
head->opcode = SNE_RAPIDMSG;
|
|
|
|
|
head->payload_length = datalen;
|
|
|
|
|
msg->payload = (void *)data;
|
|
|
|
|
|
|
|
|
|
r = _sntll_writemsg(co, msg);
|
|
|
|
|
|
|
|
|
|
free(msg);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the same but will be postponed */
|
|
|
|
|
int sxmsg_pulse_pp(conn_t *co, const char *data, size_t datalen)
|
|
|
|
|
static inline int __sxmsg_reply(sxmsg_t *msg, const char *data,
|
|
|
|
|
size_t datalen, int pp)
|
|
|
|
|
{
|
|
|
|
|
return SNE_FAILED;
|
|
|
|
|
chnl_t *ch;
|
|
|
|
|
conn_t *co;
|
|
|
|
|
sntllv2_head_t *head;
|
|
|
|
|
ppmsg_t *ppm;
|
|
|
|
|
int r, i;
|
|
|
|
|
pthread_t self = pthread_self();
|
|
|
|
|
|
|
|
|
|
/* a little bit of paranoid tests */
|
|
|
|
|
if(!msg) return SNE_FAILED;
|
|
|
|
|
if(!(ch = msg->pch)) return SNE_FAILED;
|
|
|
|
|
if(!(co = ch->connection)) return SNE_FAILED;
|
|
|
|
|
|
|
|
|
|
/* test for blocking */
|
|
|
|
|
for(i = 0; i < 8; i++)
|
|
|
|
|
if(pthread_equal(self, co->thrd_poll[i])) return SNE_WOULDBLOCK;
|
|
|
|
|
|
|
|
|
|
/* prepare it */
|
|
|
|
|
head = &msg->mhead;
|
|
|
|
|
head->attr = 0;
|
|
|
|
|
head->attr |= SXMSG_REPLYREQ;
|
|
|
|
|
head->opcode = SNE_REPLYREQ;
|
|
|
|
|
head->payload_length = datalen;
|
|
|
|
|
msg->payload = (void *)data;
|
|
|
|
|
|
|
|
|
|
if(!pp) {
|
|
|
|
|
r = _sntll_writemsg(co, msg);
|
|
|
|
|
if(r != SNE_SUCCESS) return r;
|
|
|
|
|
} else {
|
|
|
|
|
if(!(ppm = malloc(sizeof(ppmsg_t)))) return SNE_ENOMEM;
|
|
|
|
|
list_init_node(&ppm->node);
|
|
|
|
|
ppm->msg = msg;
|
|
|
|
|
|
|
|
|
|
/* under locking here */
|
|
|
|
|
pthread_mutex_lock(&co->write_pending_lock);
|
|
|
|
|
list_add2tail(&co->write_pending, &ppm->node); /* push it to the FIFO */
|
|
|
|
|
pthread_mutex_unlock(&co->write_pending_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&msg->wait); /* wait */
|
|
|
|
|
|
|
|
|
|
r = head->opcode;
|
|
|
|
|
|
|
|
|
|
if((head->attr & SXMSG_CLOSED) && !head->payload_length) { /* dialog closed and no data exists */
|
|
|
|
|
pthread_mutex_unlock(&msg->wait); /* we able to invalidate it */
|
|
|
|
|
pthread_mutex_destroy(&msg->wait);
|
|
|
|
|
free(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sxmsg_reply(sxmsg_t *msg, const char *data, size_t datalen)
|
|
|
|
|
{
|
|
|
|
|
return SNE_FAILED;
|
|
|
|
|
return __sxmsg_reply(msg, data, datalen, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sxmsg_reply_pp(sxmsg_t *msg, const char *data, size_t datalen)
|
|
|
|
|
{
|
|
|
|
|
return SNE_FAILED;
|
|
|
|
|
return __sxmsg_reply(msg, data, datalen, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sxmsg_rreply(sxmsg_t *msg, const char *data, size_t datalen)
|
|
|
|
|
int sxmsg_rreply(sxmsg_t *msg, size_t datalen)
|
|
|
|
|
{
|
|
|
|
|
return SNE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
chnl_t *ch;
|
|
|
|
|
conn_t *co;
|
|
|
|
|
sntllv2_head_t *head;
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
int sxmsg_rreply_pp(sxmsg_t *msg, const char *data, size_t datalen)
|
|
|
|
|
{
|
|
|
|
|
return SNE_FAILED;
|
|
|
|
|
/* a little bit of paranoid tests */
|
|
|
|
|
if(!msg) return SNE_FAILED;
|
|
|
|
|
if(!(ch = msg->pch)) return SNE_FAILED;
|
|
|
|
|
if(!(co = ch->connection)) return SNE_FAILED;
|
|
|
|
|
|
|
|
|
|
/* prepare it */
|
|
|
|
|
head = &msg->mhead;
|
|
|
|
|
head->attr = 0;
|
|
|
|
|
head->attr |= SXMSG_CLOSED;
|
|
|
|
|
head->opcode = SNE_RAPIDMSG;
|
|
|
|
|
head->payload_length = datalen;
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&co->idx_msg_lock);
|
|
|
|
|
idx_free(&co->idx_msg, head->msgid);
|
|
|
|
|
co->messages[head->msgid] = NULL;
|
|
|
|
|
pthread_mutex_unlock(&co->idx_msg_lock);
|
|
|
|
|
|
|
|
|
|
r = _sntll_writemsg(co, msg);
|
|
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&msg->wait); /* we able to invalidate it */
|
|
|
|
|
pthread_mutex_destroy(&msg->wait);
|
|
|
|
|
free(msg);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int __sxmsg_return(sxmsg_t *msg, int opcode, int pp)
|
|
|
|
|