[master] 91a858401 Support VSB_tofile() partial writes

Dridi Boukelmoune dridi at varni.sh
Mon Oct 2 12:17:48 UTC 2023


On Mon, Oct 2, 2023 at 8:40 AM Nils Goroll <nils.goroll at uplex.de> wrote:
>
>
> 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);

Aren't we guaranteed to have r >= 0 here?

>  }
> _______________________________________________
> varnish-commit mailing list
> varnish-commit at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit


More information about the varnish-commit mailing list