diff options
-rw-r--r-- | include/ouroboros/cdap.h | 2 | ||||
-rw-r--r-- | include/ouroboros/dev.h | 1 | ||||
-rw-r--r-- | src/irmd/main.c | 2 | ||||
-rw-r--r-- | src/lib/cdap.c | 36 |
4 files changed, 24 insertions, 17 deletions
diff --git a/include/ouroboros/cdap.h b/include/ouroboros/cdap.h index da669feb..e26f192b 100644 --- a/include/ouroboros/cdap.h +++ b/include/ouroboros/cdap.h @@ -3,7 +3,7 @@ * * The Common Distributed Application Protocol * - * Sander Vrijders <[email protected]> + * Sander Vrijders <[email protected]> * Dimitri Staessens <[email protected]> * * This program is free software; you can redistribute it and/or modify diff --git a/include/ouroboros/dev.h b/include/ouroboros/dev.h index 897bc124..699973a3 100644 --- a/include/ouroboros/dev.h +++ b/include/ouroboros/dev.h @@ -48,7 +48,6 @@ int flow_alloc(char * dst_name, int flow_alloc_res(int fd); int flow_dealloc(int fd); -/* Wraps around fnctl */ int flow_cntl(int fd, int cmd, int oflags); ssize_t flow_write(int fd, void * buf, size_t count); ssize_t flow_read(int fd, void * buf, size_t count); diff --git a/src/irmd/main.c b/src/irmd/main.c index 2ea59eee..38e10cc5 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1936,7 +1936,7 @@ void * irm_flow_cleaner() pthread_rwlock_rdlock(&instance->state_lock); - if (&instance->state == IRMD_NULL) { + if (instance->state == IRMD_NULL) { pthread_rwlock_unlock(&instance->state_lock); return (void *) 0; } diff --git a/src/lib/cdap.c b/src/lib/cdap.c index 8967c8bd..4275bfc7 100644 --- a/src/lib/cdap.c +++ b/src/lib/cdap.c @@ -53,9 +53,8 @@ static ssize_t cdap_msg_to_buffer(cdap_t * msg, len = msg->n_value; *val = malloc(len * sizeof(**val)); - if (*val == NULL) { + if (*val == NULL) return -1; - } for (i = 0; i < len; i++) { if (msg->value[i].data == NULL) { @@ -76,20 +75,18 @@ static void * sdu_reader(void * o) struct cdap * instance = (struct cdap *) o; cdap_t * msg; uint8_t buf[BUF_SIZE]; - size_t len; + ssize_t len; ssize_t length; buffer_t * val; while (true) { len = flow_read(instance->fd, buf, BUF_SIZE); - if (len < 0) { + if (len < 0) return (void *) -1; - } msg = cdap__unpack(NULL, len, buf); - if (msg == NULL) { + if (msg == NULL) continue; - } switch (msg->opcode) { case OPCODE__READ: @@ -166,6 +163,7 @@ struct cdap * cdap_create(struct cdap_ops * ops, int fd) { struct cdap * instance = NULL; + int flags; if (ops == NULL || fd < 0 || ops->cdap_reply == NULL || @@ -177,6 +175,10 @@ struct cdap * cdap_create(struct cdap_ops * ops, ops->cdap_stop == NULL) return NULL; + flags = flow_cntl(fd, FLOW_F_GETFL, 0); + if (flags & FLOW_O_NONBLOCK) + return NULL; + instance = malloc(sizeof(*instance)); if (instance == NULL) return NULL; @@ -250,15 +252,23 @@ static int write_msg(struct cdap * instance, cdap_t * msg) { buffer_t buf; + int ret; buf.len = cdap__get_packed_size(msg); - if (buf.len == 0) { + if (buf.len == 0) + return -1; + + buf.data = malloc(BUF_SIZE); + if (buf.data == NULL) return -1; - } cdap__pack(msg, buf.data); - return flow_write(instance->fd, buf.data, buf.len); + ret = flow_write(instance->fd, buf.data, buf.len); + + free(buf.data); + + return ret; } static int buffer_to_cdap_msg(cdap_t * msg, @@ -268,9 +278,8 @@ static int buffer_to_cdap_msg(cdap_t * msg, int i; msg->value = malloc(len * sizeof(*msg->value)); - if (msg->value == NULL) { + if (msg->value == NULL) return -1; - } msg->n_value = len; for (i = 0; i < len; i++) { @@ -422,9 +431,8 @@ int cdap_send_reply(struct cdap * instance, msg.has_result = true; msg.result = result; - if (buffer_to_cdap_msg(&msg, val, len)) { + if (buffer_to_cdap_msg(&msg, val, len)) return -1; - } return write_msg(instance, &msg); } |