From d32d7eae209f3ee09a690cc9adb6ea277e0d17aa Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Fri, 20 May 2016 17:22:04 +0200 Subject: 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. --- src/lib/dev.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/lib/dev.c') 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; -- cgit v1.2.3