diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-03 00:19:06 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-03 00:29:34 +0200 |
commit | a6e8978fd9b5786607438689f8cd8b8efb8ef77e (patch) | |
tree | 3c2e0982771540ab9b5a061a1645a8a36568bacf /src/lib/dev.c | |
parent | d409fd569683d8f0e8c8f65d4820087dbf7c0786 (diff) | |
download | ouroboros-a6e8978fd9b5786607438689f8cd8b8efb8ef77e.tar.gz ouroboros-a6e8978fd9b5786607438689f8cd8b8efb8ef77e.zip |
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.
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r-- | src/lib/dev.c | 13 |
1 files changed, 9 insertions, 4 deletions
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; |