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 | |
| 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')
| -rw-r--r-- | src/include/skalibs/unix-timed.h | 12 | ||||
| -rw-r--r-- | src/libunixonacid/buffer_timed_getv.c | 32 | ||||
| -rw-r--r-- | src/libunixonacid/buffer_timed_putv.c | 22 | ||||
| -rw-r--r-- | src/libunixonacid/timed_read.c | 34 | ||||
| -rw-r--r-- | src/libunixonacid/timed_readv.c | 38 |
5 files changed, 137 insertions, 1 deletions
diff --git a/src/include/skalibs/unix-timed.h b/src/include/skalibs/unix-timed.h index be79056..7243370 100644 --- a/src/include/skalibs/unix-timed.h +++ b/src/include/skalibs/unix-timed.h @@ -20,16 +20,26 @@ extern int timed_flush (void *, init_func_ref, init_func_ref, init_func_ref, tai extern ssize_t timed_get (void *, init_func_ref, get_func_ref, tain const *, tain *) ; #define timed_get_g (b, getfd, get, deadline) timed_get(b, getfd, get, (deadline), &STAMP) +extern size_t timed_read (int, char *, size_t, tain const *, tain *) ; +#define timed_read_g(fd, s, len, deadline) timed_read(fd, s, len, (deadline), &STAMP) +extern size_t timed_readv (int, struct iovec *, unsigned int, tain const *, tain *) ; +#define timed_readv_g(fd, v, vlen, deadline) timed_readv(fd, v, vlen, (deadline), &STAMP) + extern ssize_t buffer_timed_fill (buffer *, tain const *, tain *) ; #define buffer_timed_fill_g(b, deadline) buffer_timed_fill(b, (deadline), &STAMP) extern int bufalloc_timed_flush (bufalloc *, tain const *, tain *) ; #define bufalloc_timed_flush_g(ba, deadline) bufalloc_timed_flush(ba, (deadline), &STAMP) extern int buffer_timed_flush (buffer *, tain const *, tain *) ; #define buffer_timed_flush_g(b, deadline) buffer_timed_flush(b, (deadline), &STAMP) + extern size_t buffer_timed_get (buffer *, char *, size_t, tain const *, tain *) ; -#define buffer_timed_get_g(b, buf, buflen, deadline) buffer_timed_get(b, buf, buflen, (deadline), &STAMP) +#define buffer_timed_get_g(b, s, len, deadline) buffer_timed_get(b, s, len, (deadline), &STAMP) +extern size_t buffer_timed_getv (buffer *, struct iovec *, unsigned int, tain const *, tain *) ; +#define buffer_timed_getv_g(b, v, vlen, deadline) buffer_timed_getv(b, v, vlen, (deadline), &STAMP) extern size_t buffer_timed_put (buffer *, char const *, size_t, tain const *, tain *) ; #define buffer_timed_put_g(b, s, len, deadline) buffer_timed_put(b, s, len, (deadline), &STAMP) +extern size_t buffer_timed_putv (buffer *, struct iovec const *, unsigned int, tain const *, tain *) ; +#define buffer_timed_putv_g(b, v, vlen, deadline) buffer_timed_putv(b, v, vlen, (deadline), &STAMP) extern size_t buffer_timed_puts (buffer *, char const *, tain const *, tain *) ; #define buffer_timed_puts_g(b, s, deadline) buffer_timed_puts(b, s, (deadline), &STAMP) diff --git a/src/libunixonacid/buffer_timed_getv.c b/src/libunixonacid/buffer_timed_getv.c new file mode 100644 index 0000000..ee1de79 --- /dev/null +++ b/src/libunixonacid/buffer_timed_getv.c @@ -0,0 +1,32 @@ +/* ISC license. */ + +#include <sys/uio.h> + +#include <skalibs/functypes.h> +#include <skalibs/buffer.h> +#include <skalibs/unix-timed.h> + +struct blah_s +{ + buffer *b ; + struct iovec *v ; + unsigned int n ; + size_t w ; +} ; + +static int getfd (struct blah_s *blah) +{ + return buffer_fd(blah->b) ; +} + +static ssize_t get (struct blah_s *blah) +{ + return buffer_getvall(blah->b, blah->v, blah->n, &blah->w) ; +} + +size_t buffer_timed_getv (buffer *b, struct iovec *v, unsigned int n, tain const *deadline, tain *stamp) +{ + struct blah_s blah = { .b = b, .v = v, .n = n, .w = 0 } ; + timed_get(&blah, (init_func_ref)&getfd, (get_func_ref)&get, deadline, stamp) ; + return blah.w ; +} diff --git a/src/libunixonacid/buffer_timed_putv.c b/src/libunixonacid/buffer_timed_putv.c new file mode 100644 index 0000000..0dfd56a --- /dev/null +++ b/src/libunixonacid/buffer_timed_putv.c @@ -0,0 +1,22 @@ +/* ISC license. */ + +#include <sys/uio.h> + +#include <skalibs/buffer.h> +#include <skalibs/siovec.h> +#include <skalibs/unix-timed.h> + +size_t buffer_timed_putv (buffer *b, struct iovec const *v, unsigned int vlen, tain const *deadline, tain *stamp) +{ + if (!vlen) return 0 ; + size_t tot = siovec_len(v, vlen), w = 0 ; + struct iovec vv[vlen] ; + for (unsigned int i = 0 ; i < vlen ; i++) vv[i] = v[i] ; + while (w < tot) + { + size_t r = buffer_putvnoflush(b, vv, vlen) ; + w += r ; siovec_seek(vv, vlen, r) ; + if (!buffer_timed_flush(b, deadline, stamp)) break ; + } + return w ; +} diff --git a/src/libunixonacid/timed_read.c b/src/libunixonacid/timed_read.c new file mode 100644 index 0000000..0c9a5cf --- /dev/null +++ b/src/libunixonacid/timed_read.c @@ -0,0 +1,34 @@ +/* ISC license. */ + +#include <unistd.h> + +#include <skalibs/functypes.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/unix-timed.h> + +struct blah_s +{ + int fd ; + char *s ; + size_t len ; + 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_read(blah->fd, blah->s + blah->w, blah->len - blah->w) ; + if (r > 0) blah->w += r ; + return r ; +} + +size_t timed_read (int fd, char *s, size_t len, tain const *deadline, tain *stamp) +{ + struct blah_s blah = { .fd = fd, .s = s, .len = len, .w = 0 } ; + timed_get(&blah, (init_func_ref)&getfd, (get_func_ref)&get, deadline, stamp) ; + return blah.w ; +} 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 ; +} |
