diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-12-21 11:18:28 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-12-21 11:18:28 +0000 |
commit | 2990ce9b390ec1e2bfa1c043c406878e8aff86dd (patch) | |
tree | 270e5e2bfa3cdb2fc795039fc45901d93290567e /src/libunixonacid/textmessage_receive.c | |
parent | 933e986a9207d2b61c5119e18603b44b924e7226 (diff) | |
download | skalibs-2990ce9b390ec1e2bfa1c043c406878e8aff86dd.tar.xz |
Big 2.6.3.0 reorganization
- Add libposixplz, update headers
- Add memmem and friends
- Add textmessage to libunixonacid
- Update some sysdeps tests
Diffstat (limited to 'src/libunixonacid/textmessage_receive.c')
-rw-r--r-- | src/libunixonacid/textmessage_receive.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libunixonacid/textmessage_receive.c b/src/libunixonacid/textmessage_receive.c new file mode 100644 index 0000000..1411f9a --- /dev/null +++ b/src/libunixonacid/textmessage_receive.c @@ -0,0 +1,40 @@ +/* ISC license. */ + +#include <sys/uio.h> +#include <stdint.h> +#include <errno.h> +#include <skalibs/uint32.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/buffer.h> +#include <skalibs/stralloc.h> +#include <skalibs/textmessage.h> + +int textmessage_receive (textmessage_receiver_t *tr, struct iovec *v) +{ + if (tr->indata.len == tr->wanted) + { + uint32_t u ; + char pack[4] ; + if (buffer_len(&tr->in) < 4) + { + ssize_t r = sanitize_read(buffer_fill(&tr->in)) ; + if (r <= 0) return r ; + if (buffer_len(&tr->in) < 4) return (errno = EWOULDBLOCK, 0) ; + } + buffer_getnofill(&tr->in, pack, 4) ; + uint32_unpack_big(pack, &u) ; + if (u > tr->max) return (errno = EMSGSIZE, -1) ; + if (!stralloc_ready(&tr->indata, u)) return -1 ; + tr->wanted = u ; + tr->indata.len = 0 ; + } + + { + int r = buffer_getall(&tr->in, tr->indata.s, tr->wanted, &tr->indata.len) ; + if (r <= 0) return r ; + } + + v->iov_base = tr->indata.s ; + v->iov_len = tr->indata.len ; + return 1 ; +} |