skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit ed49b72c0a31b6034026948851edf11cfa990fa0
parent 334d7f09d8dec83b9399e2cc44490b3868cd0772
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Sun,  1 Feb 2015 12:06:52 +0000

 Add allreadwritev and friends

Diffstat:
Mpackage/deps.mak | 12+++++++++---
Msrc/include/skalibs/allreadwrite.h | 6++++++
Msrc/include/skalibs/functypes.h | 8++++++++
Msrc/libstddjb/allreadwrite.c | 1-
Msrc/libstddjb/buffer_write.c | 7++-----
5 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/package/deps.mak b/package/deps.mak @@ -3,7 +3,7 @@ # src/include/skalibs/alloc.h: src/include/skalibs/gccattributes.h -src/include/skalibs/allreadwrite.h: src/include/skalibs/functypes.h +src/include/skalibs/allreadwrite.h: src/include/skalibs/functypes.h src/include/skalibs/siovec.h src/include/skalibs/avlnode.h: src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/avltree.h: src/include/skalibs/avlnode.h src/include/skalibs/functypes.h src/include/skalibs/gensetdyn.h src/include/skalibs/avltreen.h: src/include/skalibs/avlnode.h src/include/skalibs/functypes.h src/include/skalibs/genset.h @@ -22,6 +22,7 @@ src/include/skalibs/djbunix.h: src/include/skalibs/env.h src/include/skalibs/env src/include/skalibs/env.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/envalloc.h: src/include/skalibs/genalloc.h src/include/skalibs/fmtscan.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint32.h +src/include/skalibs/functypes.h: src/include/skalibs/siovec.h src/include/skalibs/genalloc.h: src/include/skalibs/functypes.h src/include/skalibs/stralloc.h src/include/skalibs/genset.h: src/include/skalibs/functypes.h src/include/skalibs/gensetdyn.h: src/include/skalibs/functypes.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h @@ -193,8 +194,11 @@ src/libstddjb/absolutepath_tmp.o src/libstddjb/absolutepath_tmp.lo: src/libstddj src/libstddjb/alloc.o src/libstddjb/alloc.lo: src/libstddjb/alloc.c src/libstddjb/alloc-internal.h src/include/skalibs/alloc.h src/include/skalibs/sysdeps.h src/libstddjb/alloc_0.o src/libstddjb/alloc_0.lo: src/libstddjb/alloc_0.c src/libstddjb/alloc-internal.h src/include/skalibs/alloc.h src/include/skalibs/sysdeps.h src/libstddjb/allread.o src/libstddjb/allread.lo: src/libstddjb/allread.c src/include/skalibs/allreadwrite.h +src/libstddjb/allreadv.o src/libstddjb/allreadv.lo: src/libstddjb/allreadv.c src/include/skalibs/allreadwrite.h src/include/skalibs/siovec.h src/libstddjb/allreadwrite.o src/libstddjb/allreadwrite.lo: src/libstddjb/allreadwrite.c src/include/skalibs/allreadwrite.h +src/libstddjb/allreadwritev.o src/libstddjb/allreadwritev.lo: src/libstddjb/allreadwritev.c src/include/skalibs/allreadwrite.h src/include/skalibs/siovec.h src/libstddjb/allwrite.o src/libstddjb/allwrite.lo: src/libstddjb/allwrite.c src/include/skalibs/allreadwrite.h +src/libstddjb/allwritev.o src/libstddjb/allwritev.lo: src/libstddjb/allwritev.c src/include/skalibs/allreadwrite.h src/include/skalibs/siovec.h src/libstddjb/baprintf.o src/libstddjb/baprintf.lo: src/libstddjb/baprintf.c src/include/skalibs/bufalloc.h src/include/skalibs/lolstdio.h src/libstddjb/basename.o src/libstddjb/basename.lo: src/libstddjb/basename.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/bitarray_and.o src/libstddjb/bitarray_and.lo: src/libstddjb/bitarray_and.c src/include/skalibs/bitarray.h @@ -315,11 +319,13 @@ src/libstddjb/fd_ensure_open.o src/libstddjb/fd_ensure_open.lo: src/libstddjb/fd src/libstddjb/fd_move.o src/libstddjb/fd_move.lo: src/libstddjb/fd_move.c src/include/skalibs/djbunix.h src/libstddjb/fd_move2.o src/libstddjb/fd_move2.lo: src/libstddjb/fd_move2.c src/include/skalibs/djbunix.h src/libstddjb/fd_read.o src/libstddjb/fd_read.lo: src/libstddjb/fd_read.c src/include/skalibs/allreadwrite.h +src/libstddjb/fd_readsv.o src/libstddjb/fd_readsv.lo: src/libstddjb/fd_readsv.c src/include/skalibs/allreadwrite.h src/include/skalibs/siovec.h src/libstddjb/fd_readv.o src/libstddjb/fd_readv.lo: src/libstddjb/fd_readv.c src/include/skalibs/allreadwrite.h src/libstddjb/fd_recv.o src/libstddjb/fd_recv.lo: src/libstddjb/fd_recv.c src/include/skalibs/allreadwrite.h src/libstddjb/fd_send.o src/libstddjb/fd_send.lo: src/libstddjb/fd_send.c src/include/skalibs/allreadwrite.h src/libstddjb/fd_sync.o src/libstddjb/fd_sync.lo: src/libstddjb/fd_sync.c src/include/skalibs/djbunix.h src/libstddjb/fd_write.o src/libstddjb/fd_write.lo: src/libstddjb/fd_write.c src/include/skalibs/allreadwrite.h +src/libstddjb/fd_writesv.o src/libstddjb/fd_writesv.lo: src/libstddjb/fd_writesv.c src/include/skalibs/allreadwrite.h src/include/skalibs/siovec.h src/libstddjb/fd_writev.o src/libstddjb/fd_writev.lo: src/libstddjb/fd_writev.c src/include/skalibs/allreadwrite.h src/libstddjb/fmtscan_asc.o src/libstddjb/fmtscan_asc.lo: src/libstddjb/fmtscan_asc.c src/include/skalibs/fmtscan.h src/libstddjb/fmtscan_num.o src/libstddjb/fmtscan_num.lo: src/libstddjb/fmtscan_num.c src/include/skalibs/fmtscan.h @@ -501,7 +507,7 @@ src/libstddjb/skagetln_nofill.o src/libstddjb/skagetln_nofill.lo: src/libstddjb/ src/libstddjb/skagetlnsep.o src/libstddjb/skagetlnsep.lo: src/libstddjb/skagetlnsep.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/skalibs_tzisright.o src/libstddjb/skalibs_tzisright.lo: src/libstddjb/skalibs_tzisright.c src/libstddjb/djbtime-internal.h src/libstddjb/skasig_dfl.o src/libstddjb/skasig_dfl.lo: src/libstddjb/skasig_dfl.c src/include/skalibs/sig.h -src/libstddjb/skasigaction.o src/libstddjb/skasigaction.lo: src/libstddjb/skasigaction.c src/include/skalibs/sig.h src/include/skalibs/sysdeps.h +src/libstddjb/skasigaction.o src/libstddjb/skasigaction.lo: src/libstddjb/skasigaction.c src/include/skalibs/sig.h src/libstddjb/slurp.o src/libstddjb/slurp.lo: src/libstddjb/slurp.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/socket_accept4.o src/libstddjb/socket_accept4.lo: src/libstddjb/socket_accept4.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/sysdeps.h src/include/skalibs/uint16.h src/libstddjb/socket_accept4_u32.o src/libstddjb/socket_accept4_u32.lo: src/libstddjb/socket_accept4_u32.c src/include/skalibs/socket.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h @@ -737,7 +743,7 @@ src/libunixonacid/skaclient_sendmsgv.o src/libunixonacid/skaclient_sendmsgv.lo: src/libunixonacid/skaclient_sendv.o src/libunixonacid/skaclient_sendv.lo: src/libunixonacid/skaclient_sendv.c src/include/skalibs/siovec.h src/include/skalibs/skaclient.h src/include/skalibs/tai.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_server_ack.o src/libunixonacid/skaclient_server_ack.lo: src/libunixonacid/skaclient_server_ack.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/error.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/include/skalibs/webipc.h src/libunixonacid/skaclient_server_bidi_ack.o src/libunixonacid/skaclient_server_bidi_ack.lo: src/libunixonacid/skaclient_server_bidi_ack.c src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h -src/libunixonacid/skaclient_server_init.o src/libunixonacid/skaclient_server_init.lo: src/libunixonacid/skaclient_server_init.c src/include/skalibs/skaclient.h src/include/skalibs/tai.h src/include/skalibs/unixmessage.h +src/libunixonacid/skaclient_server_init.o src/libunixonacid/skaclient_server_init.lo: src/libunixonacid/skaclient_server_init.c src/include/skalibs/allreadwrite.h src/include/skalibs/skaclient.h src/include/skalibs/tai.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_start.o src/libunixonacid/skaclient_start.lo: src/libunixonacid/skaclient_start.c src/include/skalibs/kolbak.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/include/skalibs/tai.h src/include/skalibs/uint32.h src/libunixonacid/skaclient_start_async.o src/libunixonacid/skaclient_start_async.lo: src/libunixonacid/skaclient_start_async.c src/include/skalibs/error.h src/include/skalibs/kolbak.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/include/skalibs/uint32.h src/include/skalibs/unixmessage.h src/include/skalibs/webipc.h src/libunixonacid/skaclient_start_cb.o src/libunixonacid/skaclient_start_cb.lo: src/libunixonacid/skaclient_start_cb.c src/include/skalibs/bytestr.h src/include/skalibs/error.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h diff --git a/src/include/skalibs/allreadwrite.h b/src/include/skalibs/allreadwrite.h @@ -6,11 +6,13 @@ #include <sys/types.h> #include <sys/uio.h> #include <skalibs/functypes.h> +#include <skalibs/siovec.h> extern int sanitize_read (int) ; extern int unsanitize_read (int) ; extern unsigned int allreadwrite (iofunc_t_ref, int, char *, unsigned int) ; +extern unsigned int allreadwritev (iovfunc_t_ref, int, siovec_t const *, unsigned int) ; extern int fd_read (int, char *, unsigned int) ; extern int fd_write (int, char const *, unsigned int) ; @@ -20,8 +22,12 @@ extern int fd_send (int, char const *, unsigned int, unsigned int) ; extern unsigned int allread (int, char *, unsigned int) ; extern unsigned int allwrite (int, char const *, unsigned int) ; +extern unsigned int allreadv (int, siovec_t const *, unsigned int) ; +extern unsigned int allwritev (int, siovec_t const *, unsigned int) ; extern int fd_readv (int, struct iovec const *, unsigned int) ; +extern int fd_readsv (int, siovec_t const *, unsigned int) ; extern int fd_writev (int, struct iovec const *, unsigned int) ; +extern int fd_writesv (int, siovec_t const *, unsigned int) ; #endif diff --git a/src/include/skalibs/functypes.h b/src/include/skalibs/functypes.h @@ -3,6 +3,8 @@ #ifndef FUNCTYPES_H #define FUNCTYPES_H +#include <skalibs/siovec.h> + typedef int uintcmpfunc_t (unsigned int, unsigned int, void *) ; typedef uintcmpfunc_t *uintcmpfunc_t_ref ; @@ -27,7 +29,13 @@ typedef uinitfunc_t *uinitfunc_t_ref ; typedef int iofunc_t (int, char *, unsigned int) ; typedef iofunc_t *iofunc_t_ref ; +typedef int iovfunc_t (int, siovec_t const *, unsigned int) ; +typedef iovfunc_t *iovfunc_t_ref ; + typedef unsigned int alliofunc_t (int, char *, unsigned int) ; typedef alliofunc_t *alliofunc_t_ref ; +typedef unsigned int alliovfunc_t (int, siovec_t const *, unsigned int) ; +typedef alliovfunc_t *alliovfunc_t_ref ; + #endif diff --git a/src/libstddjb/allreadwrite.c b/src/libstddjb/allreadwrite.c @@ -9,7 +9,6 @@ unsigned int allreadwrite (iofunc_t_ref op, int fd, register char *buf, register while (len) { register int w = (*op)(fd, buf, len) ; - if (!w) errno = EPIPE ; if (w <= 0) break ; written += w ; buf += w ; diff --git a/src/libstddjb/buffer_write.c b/src/libstddjb/buffer_write.c @@ -1,14 +1,11 @@ /* ISC license. */ -#include <sys/types.h> -#include <sys/uio.h> #include <skalibs/allreadwrite.h> #include <skalibs/siovec.h> #include <skalibs/buffer.h> int buffer_write (int fd, siovec_t const *v, unsigned int n) { - struct iovec iov[n] ; - iovec_from_siovec(iov, v, n) ; - return fd_writev(fd, iov, n) ; + unsigned int w = allreadwritev(&fd_writesv, fd, v, n) ; + return w ? (int)w : -1 ; }