diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-05-22 14:53:22 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-05-22 15:04:20 +0200 |
commit | dfe5a46fb5315112d1173ac983ffc416dc3ecf18 (patch) | |
tree | fe6459aadc00e81ef1252392dc07e009e3e8888e /src/lib/dev.c | |
parent | 745cc666e34d7e0c29822615987ce02832ac5a8c (diff) | |
download | ouroboros-dfe5a46fb5315112d1173ac983ffc416dc3ecf18.tar.gz ouroboros-dfe5a46fb5315112d1173ac983ffc416dc3ecf18.zip |
lib, ipcpd, irmd: fixes deallocation and fast path
The fast path has been rewritten to have certainty to read the correct
flow. Deallocation will not release port_id's or fd's until they are
explicitly released locally.
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r-- | src/lib/dev.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index d332a27f..1332b014 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -300,6 +300,7 @@ int flow_accept(int fd, rw_lock_rdlock(&_ap_instance->data_lock); rw_lock_wrlock(&_ap_instance->flows_lock); + cfd = bmp_allocate(_ap_instance->fds); if (!bmp_is_id_valid(_ap_instance->fds, cfd)) { rw_lock_unlock(&_ap_instance->flows_lock); @@ -588,37 +589,39 @@ ssize_t flow_write(int fd, void * buf, size_t count) ssize_t flow_read(int fd, void * buf, size_t count) { - struct rb_entry * e = NULL; + int idx = -1; int n; uint8_t * sdu; rw_lock_rdlock(&_ap_instance->data_lock); rw_lock_rdlock(&_ap_instance->flows_lock); + if (_ap_instance->flows[fd].port_id < 0) { + rw_lock_unlock(&_ap_instance->flows_lock); + rw_lock_unlock(&_ap_instance->data_lock); + return -1; + } + if (_ap_instance->flows[fd].oflags & FLOW_O_NONBLOCK) { - if (shm_ap_rbuff_peek(_ap_instance->rb) - != _ap_instance->flows[fd].port_id) { - rw_lock_unlock(&_ap_instance->flows_lock); - rw_lock_unlock(&_ap_instance->data_lock); - return -1; - } + idx = shm_ap_rbuff_read_port(_ap_instance->rb, + _ap_instance->flows[fd].port_id); } else { /* block */ - while (shm_ap_rbuff_peek(_ap_instance->rb) - != _ap_instance->flows[fd].port_id) + while ((idx = shm_ap_rbuff_read_port( + _ap_instance->rb, + _ap_instance->flows[fd].port_id)) < 0) ; } rw_lock_unlock(&_ap_instance->flows_lock); - e = shm_ap_rbuff_read(_ap_instance->rb); - if (e == NULL) { + if (idx < 0) { rw_lock_unlock(&_ap_instance->data_lock); return -1; } n = shm_du_map_read_sdu(&sdu, _ap_instance->dum, - e->index); + idx); if (n < 0) { rw_lock_unlock(&_ap_instance->data_lock); return -1; @@ -626,7 +629,7 @@ ssize_t flow_read(int fd, void * buf, size_t count) memcpy(buf, sdu, MIN(n, count)); - shm_release_du_buff(_ap_instance->dum, e->index); + shm_release_du_buff(_ap_instance->dum, idx); rw_lock_unlock(&_ap_instance->data_lock); |