From a6e8978fd9b5786607438689f8cd8b8efb8ef77e Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 3 Aug 2016 00:19:06 +0200 Subject: lib: dev: Add select-like call This adds a flow_select() call that will sleep until an SDU can be read on a flow. It returns the file descriptor for which an SDU is ready. It takes as optional argument a timespec struct to specify a timeout. --- src/lib/dev.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/lib/dev.c') diff --git a/src/lib/dev.c b/src/lib/dev.c index f13c8423..22e77169 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -130,17 +130,14 @@ void ap_fini(void) free(_ap_instance); } -#if 0 static int port_id_to_fd(int port_id) { int i; for (i = 0; i < AP_MAX_FLOWS; ++i) - if (_ap_instance->flows[i].port_id == port_id - && _ap_instance->flows[i].state != FLOW_NULL) + if (_ap_instance->flows[i].port_id == port_id) return i; return -1; } -#endif int flow_accept(char ** ae_name) { @@ -523,6 +520,14 @@ ssize_t flow_write(int fd, void * buf, size_t count) return 0; } +int flow_select(const struct timespec * timeout) +{ + int port_id = shm_ap_rbuff_peek(_ap_instance->rb, timeout); + if (port_id < 0) + return port_id; + return port_id_to_fd(port_id); +} + ssize_t flow_read(int fd, void * buf, size_t count) { int idx = -1; -- cgit v1.2.3