From 0b587354bde8f4c27fe5aa7adfb63a86b4637403 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 4 Sep 2015 23:47:07 +0200 Subject: m fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsclient/inbound.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/libmdsclient/inbound.c b/src/libmdsclient/inbound.c index 401f959..e2831a6 100644 --- a/src/libmdsclient/inbound.c +++ b/src/libmdsclient/inbound.c @@ -112,8 +112,8 @@ libmds_message_t* libmds_message_duplicate(libmds_message_t* restrict this, libm rc->buffer_size = this->buffer_off; rc->buffer = ((char*)rc) + sizeof(libmds_message_t) / sizeof(char); - rc->headers = (char**)(void*)(rc->buffer + this->buffer_off); - rc->payload = rc->buffer + (size_t)(this->payload - this->buffer); + rc->headers = rc->header_count ? (char**)(void*)(rc->buffer + this->buffer_off) : NULL; + rc->payload = rc->payload_size ? (rc->buffer + (size_t)(this->payload - this->buffer)) : NULL; for (i = 0; i < n; i++) rc->headers[i] = rc->buffer + (size_t)(this->headers[i] - this->buffer); @@ -671,8 +671,9 @@ static inline libmds_message_t* mspool_poll(libmds_mspool_t* restrict this) /* Fetch message. */ assert(this->tail < this->head); msg = this->messages[this->tail++]; + this->spooled_bytes -= msg->flattened; - /* Unblock spooler. */ + /* Unblock spooler, takes effect when this->lock is unlocked. */ if (this->please_post) { if (sem_post(&(this->wait_semaphore)) < 0) @@ -683,9 +684,14 @@ static inline libmds_message_t* mspool_poll(libmds_mspool_t* restrict this) /* Unlock. */ if (sem_post(&(this->lock)) < 0) - return sem_post(&(this->semaphore)), this->messages[--(this->tail)] = msg, NULL; + goto fail; return msg; + fail: + sem_post(&(this->semaphore)); + this->messages[--(this->tail)] = msg; + this->spooled_bytes += msg->flattened; + return NULL; } -- cgit v1.2.3-70-g09d2