From 5ffcd383030fdb6495e75324437d0c9924a4ff88 Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Fri, 27 Feb 2015 18:13:53 +0200 Subject: [PATCH] fixed timed message sending. --- lib/connection.c | 9 +++++++-- lib/message.c | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/connection.c b/lib/connection.c index 70ba5c3..4b94228 100644 --- a/lib/connection.c +++ b/lib/connection.c @@ -83,7 +83,7 @@ static int __conn_read(conn_t *co, void *buf, size_t buf_len) int rfd = SSL_get_fd(co->ssl), r; fd_set readset; - fprintf(stderr, "\tListening ... on %s\n", co->uuid); + //fprintf(stderr, "\tListening ... on %s\n", co->uuid); /* get prepare to select */ FD_ZERO(&readset); FD_SET(rfd, &readset); @@ -1256,7 +1256,12 @@ static int __default_msg_return(void *cctx, sexp_t *sx) usrtc_delete(chan->msgs_tree, &(smsg->pendingq_node)); pthread_rwlock_unlock(&(chan->msglock)); } - pthread_mutex_unlock(&(smsg->wait)); + if(smsg->flags & ESXMSG_PENDING) pthread_mutex_unlock(&(smsg->wait)); + else { + /* nobody want it */ + destroy_sexp(smsg->initial_sx); + __destroy_msg(smsg); + } } __finish: diff --git a/lib/message.c b/lib/message.c index 0dac07c..39818bf 100644 --- a/lib/message.c +++ b/lib/message.c @@ -225,8 +225,10 @@ static int __msg_reply(sxmsg_t *msg, sexp_t *sx, struct timespec *tio, int opcod else pthread_mutex_timedlock(&(msg->wait), tio); } - if(tio && (msg->flags & ESXMSG_PENDING)) + if(tio && (msg->flags & ESXMSG_PENDING)) { + msg->flags &= ~ESXMSG_PENDING; /* we will not wait for it */ return SXOTIMEDOUT; + } r = msg->opcode;