diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2025-03-01 08:51:50 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2025-03-01 08:51:50 +0000 |
| commit | 9c781a2be58c60101aa96a9606117693204cc1a4 (patch) | |
| tree | 6738cfa96b6f015444246f016920df6581f37477 /src/libunixonacid/timed_readv.c | |
| parent | b6e920192eee90fa2d403a6616129149c8daba97 (diff) | |
| download | skalibs-9c781a2be58c60101aa96a9606117693204cc1a4.tar.gz | |
Add timed_read[v], buffer_timed_[get|put]v
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libunixonacid/timed_readv.c')
| -rw-r--r-- | src/libunixonacid/timed_readv.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libunixonacid/timed_readv.c b/src/libunixonacid/timed_readv.c new file mode 100644 index 0000000..606a70f --- /dev/null +++ b/src/libunixonacid/timed_readv.c @@ -0,0 +1,38 @@ +/* ISC license. */ + +#include <sys/uio.h> + +#include <skalibs/functypes.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/siovec.h> +#include <skalibs/unix-timed.h> + +struct blah_s +{ + int fd ; + struct iovec *v ; + unsigned int vlen ; + size_t w ; +} ; + +static int getfd (struct blah_s *blah) +{ + return blah->fd ; +} + +static ssize_t get (struct blah_s *blah) +{ + ssize_t r = fd_readv(blah->fd, blah->v, blah->vlen) ; + if (r > 0) { blah->w += r ; siovec_seek(blah->v, blah->vlen, r) ; } + return r ; +} + +size_t timed_readv (int fd, struct iovec *v, unsigned int vlen, tain const *deadline, tain *stamp) +{ + if (!vlen || !siovec_len(v, vlen)) return 0 ; + struct iovec vv[vlen] ; + struct blah_s blah = { .fd = fd, .v = vv, .vlen = vlen, .w = 0 } ; + for (unsigned int i = 0 ; i < vlen ; i++) vv[i] = v[i] ; + timed_get(&blah, (init_func_ref)&getfd, (get_func_ref)&get, deadline, stamp) ; + return blah.w ; +} |
