diff options
author | Dimitri Staessens <[email protected]> | 2018-03-11 14:28:49 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2018-03-12 10:32:24 +0100 |
commit | 9bf0d277416c342a8a9e0b2017b2b10f1d093245 (patch) | |
tree | ea940f7f3337d5543aff9e1d2ef04f6b544ad899 /src/lib/dev.c | |
parent | 6a4151baa8231cdaf746761fd8dc4aacb895c9e5 (diff) | |
download | ouroboros-9bf0d277416c342a8a9e0b2017b2b10f1d093245.tar.gz ouroboros-9bf0d277416c342a8a9e0b2017b2b10f1d093245.zip |
lib: Implement timeout on blocking write
This completes the implementation of the SNDTIMEO for a blocking
write.
Fixes #6.
Signed-off-by: Dimitri Staessens <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r-- | src/lib/dev.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index 2e128d59..3564c293 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -808,10 +808,12 @@ ssize_t flow_write(int fd, const void * buf, size_t count) { - struct flow * flow; - ssize_t idx; - int ret; - int flags; + struct flow * flow; + ssize_t idx; + int ret; + int flags; + struct timespec abs; + struct timespec * abstime = NULL; if (buf == NULL) return 0; @@ -821,6 +823,8 @@ ssize_t flow_write(int fd, flow = &ai.flows[fd]; + clock_gettime(PTHREAD_COND_CLOCK, &abs); + pthread_rwlock_rdlock(&ai.lock); if (flow->port_id < 0) { @@ -828,6 +832,11 @@ ssize_t flow_write(int fd, return -ENOTALLOC; } + if (ai.flows[fd].snd_timesout) { + ts_add(&abs, &flow->snd_timeo, &abs); + abstime = &abs; + } + flags = flow->oflags; pthread_rwlock_unlock(&ai.lock); @@ -846,7 +855,8 @@ ssize_t flow_write(int fd, DU_BUFF_HEADSPACE, DU_BUFF_TAILSPACE, buf, - count); + count, + abstime); if (idx < 0) return idx; @@ -879,7 +889,6 @@ ssize_t flow_read(int fd, uint8_t * sdu; struct shm_rbuff * rb; struct shm_du_buff * sdb; - struct timespec now; struct timespec abs; struct timespec * abstime = NULL; struct flow * flow; @@ -890,7 +899,7 @@ ssize_t flow_read(int fd, flow = &ai.flows[fd]; - clock_gettime(PTHREAD_COND_CLOCK, &now); + clock_gettime(PTHREAD_COND_CLOCK, &abs); pthread_rwlock_rdlock(&ai.lock); @@ -903,7 +912,7 @@ ssize_t flow_read(int fd, noblock = flow->oflags & FLOWFRNOBLOCK; if (ai.flows[fd].rcv_timesout) { - ts_add(&now, &flow->rcv_timeo, &abs); + ts_add(&abs, &flow->rcv_timeo, &abs); abstime = &abs; } @@ -1349,7 +1358,8 @@ int ipcp_sdb_reserve(struct shm_du_buff ** sdb, DU_BUFF_HEADSPACE, DU_BUFF_TAILSPACE, NULL, - len); + len, + NULL); if (idx < 0) return -1; |