diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-10-30 10:36:08 +0100 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-10-30 10:36:08 +0100 |
commit | 5d01776443c0a500ffbc79a36745b07b8628bd62 (patch) | |
tree | 60117ebc2d1612d503c8d1e26630a08fc67b17ef /src/lib/dev.c | |
parent | 298f78d426cdf8bcd9c8890f117d0236bde20bc4 (diff) | |
download | ouroboros-5d01776443c0a500ffbc79a36745b07b8628bd62.tar.gz ouroboros-5d01776443c0a500ffbc79a36745b07b8628bd62.zip |
lib: Have flow_event_wait return non-zero value
Flow_event_wait will either return -EINVAL, -ETIMEDOUT or a positive
integer indicating the number of SDUs in the fqueue. This allows to
call the function as the condition for a non-terminating while loop.
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r-- | src/lib/dev.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index ec1cd696..4b97428e 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -1002,12 +1002,16 @@ int flow_event_wait(struct flow_set * set, assert(!fq->next); ret = shm_flow_set_wait(ai.fqset, set->idx, fq->fqueue, timeout); - if (ret == -ETIMEDOUT) + if (ret == -ETIMEDOUT) { + fq->fqsize = 0; return -ETIMEDOUT; + } fq->fqsize = ret; - return 0; + assert(ret); + + return ret; } /* ipcp-dev functions */ @@ -1295,6 +1299,12 @@ int ipcp_flow_write(int fd, struct shm_du_buff * sdb) pthread_rwlock_rdlock(&ai.data_lock); pthread_rwlock_rdlock(&ai.flows_lock); + if (ai.flows[fd].port_id < 0) { + pthread_rwlock_unlock(&ai.flows_lock); + pthread_rwlock_unlock(&ai.data_lock); + return -ENOTALLOC; + } + if ((ai.flows[fd].oflags & FLOW_O_ACCMODE) == FLOW_O_RDONLY) { pthread_rwlock_unlock(&ai.flows_lock); pthread_rwlock_unlock(&ai.data_lock); @@ -1356,7 +1366,11 @@ int local_flow_write(int fd, size_t idx) pthread_rwlock_rdlock(&ai.data_lock); pthread_rwlock_rdlock(&ai.flows_lock); - assert(ai.flows[fd].tx_rb); + if (ai.flows[fd].port_id < 0) { + pthread_rwlock_unlock(&ai.flows_lock); + pthread_rwlock_unlock(&ai.data_lock); + return -ENOTALLOC; + } shm_rbuff_write(ai.flows[fd].tx_rb, idx); |