summaryrefslogtreecommitdiff
path: root/src/lib/dev.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-05-20 17:22:04 +0200
committerdimitri staessens <[email protected]>2016-05-20 17:47:45 +0200
commitd32d7eae209f3ee09a690cc9adb6ea277e0d17aa (patch)
tree301199d037c9c74bd683a2937fb49fc12e692cf6 /src/lib/dev.c
parent303034090a9e8da6b096c1e61553dacaf359f187 (diff)
downloadouroboros-d32d7eae209f3ee09a690cc9adb6ea277e0d17aa.tar.gz
ouroboros-d32d7eae209f3ee09a690cc9adb6ea277e0d17aa.zip
lib: allow parallel connections
dev.c: read now only reads an SDU if is is for the correct port_id shm_ap_rbuff: added a function peek() that returns the port_id of the tail.
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r--src/lib/dev.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c
index c365a17b..fab37bbf 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -588,18 +588,21 @@ ssize_t flow_read(int fd, void * buf, size_t count)
rw_lock_rdlock(&_ap_instance->flows_lock);
if (_ap_instance->flows[fd].oflags & FLOW_O_NONBLOCK) {
- e = shm_ap_rbuff_read(_ap_instance->rb);
- } else {
-
- /* FIXME: this will throw away packets for other fd's */
- while (e == NULL ||
- e->port_id != _ap_instance->flows[fd].port_id) {
- e = shm_ap_rbuff_read(_ap_instance->rb);
+ 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;
}
+ } else { /* block */
+ while (shm_ap_rbuff_peek(_ap_instance->rb)
+ != _ap_instance->flows[fd].port_id)
+ ;
}
rw_lock_unlock(&_ap_instance->flows_lock);
+ e = shm_ap_rbuff_read(_ap_instance->rb);
if (e == NULL) {
rw_lock_unlock(&_ap_instance->data_lock);
return -1;