textmessage_putv.c (617B)
1 /* ISC license. */ 2 3 #include <sys/uio.h> 4 #include <errno.h> 5 #include <stdint.h> 6 #include <skalibs/uint32.h> 7 #include <skalibs/bufalloc.h> 8 #include <skalibs/siovec.h> 9 #include <skalibs/textmessage.h> 10 11 int textmessage_putv (textmessage_sender *ts, struct iovec const *v, unsigned int n) 12 { 13 size_t len = siovec_len(v, n) ; 14 char pack[4] ; 15 struct iovec vv[n+1] ; 16 if (len > TEXTMESSAGE_MAXLEN) return (errno = EINVAL, 0) ; 17 vv[0].iov_base = pack ; 18 vv[0].iov_len = 4 ; 19 for (unsigned int i = 0 ; i < n ; i++) vv[i+1] = v[i] ; 20 uint32_pack_big(pack, (uint32_t)len) ; 21 return bufalloc_putv(&ts->out, vv, n+1) ; 22 }