[master] 91a858401 Support VSB_tofile() partial writes
Nils Goroll
nils.goroll at uplex.de
Mon Oct 2 08:40:09 UTC 2023
commit 91a858401e713baf33b3364bd2b9a81f914b14d3
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Thu Sep 28 16:10:53 2023 +0200
Support VSB_tofile() partial writes
most of all, this will make a helpful errno value available to the
caller.
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index aed1182c8..cb2b5eab1 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -670,11 +670,23 @@ VSB_indent(struct vsb *s, int i)
int
VSB_tofile(const struct vsb *s, int fd)
{
+ const char *p;
ssize_t r;
+ size_t sz;
assert_VSB_integrity(s);
assert_VSB_state(s, VSB_FINISHED);
assert(s->s_len >= 0);
- r = write(fd, s->s_buf, s->s_len);
- return (r == s->s_len ? 0 : -1);
+ r = 0;
+ p = s->s_buf;
+ sz = (typeof(sz))s->s_len;
+ while (sz > 0) {
+ r = write(fd, p, sz);
+ if (r < 0)
+ return (-1);
+ assert(r <= sz);
+ p += r;
+ sz -= r;
+ }
+ return (r >= 0 ? 0 : -1);
}
More information about the varnish-commit
mailing list