From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libunixonacid/timed_get.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/libunixonacid/timed_get.c (limited to 'src/libunixonacid/timed_get.c') diff --git a/src/libunixonacid/timed_get.c b/src/libunixonacid/timed_get.c new file mode 100644 index 0000000..0a02382 --- /dev/null +++ b/src/libunixonacid/timed_get.c @@ -0,0 +1,22 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include + +int timed_get (void *b, initfunc_t *getfd, initfunc_t *get, tain_t const *deadline, tain_t *stamp) +{ + iopause_fd x = { .fd = (*getfd)(b), .events = IOPAUSE_READ, .revents = 0 } ; + register int r = (*get)(b) ; + while (!r) + { + r = iopause_stamp(&x, 1, deadline, stamp) ; + if (!r) return (errno = ETIMEDOUT, -1) ; + else if (r > 0 && x.revents & (IOPAUSE_READ | IOPAUSE_EXCEPT)) + r = (*get)(b) ; + } + return unsanitize_read(r) ; +} -- cgit v1.3.1