qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 6/6] qemu-file: do not use stdio for qemu_fdopen


From: Juan Quintela
Subject: Re: [Qemu-devel] [PATCH 6/6] qemu-file: do not use stdio for qemu_fdopen
Date: Tue, 09 Apr 2013 15:30:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Paolo Bonzini <address@hidden> wrote:
> This uses system calls directly for Unix file descriptors, so that the
> efficient writev_buffer can be used.  Pay attention to the possibility
> of partial writes in writev.
>
> Signed-off-by: Paolo Bonzini <address@hidden>

Reviewed-by: Juan Quintela <address@hidden>

> +static ssize_t unix_writev_buffer(void *opaque, struct iovec *iov, int 
> iovcnt)
> +{
> +    QEMUFileSocket *s = opaque;
> +    ssize_t len, offset;
> +    ssize_t size = iov_size(iov, iovcnt);
> +    ssize_t total = 0;
> +
> +    assert(iovcnt > 0);
> +    offset = 0;
> +    while (size > 0) {
> +        /* Find the next start position; skip all full-sized vector elements 
>  */
> +        while (offset >= iov[0].iov_len) {
> +            offset -= iov[0].iov_len;
> +            iov++, iovcnt--;
> +        }
> +
> +        /* skip `offset' bytes from the (now) first element, undo it on exit 
> */
> +        assert(iovcnt > 0);
> +        iov[0].iov_base += offset;
> +        iov[0].iov_len -= offset;
> +
> +        do {
> +            len = writev(s->fd, iov, iovcnt);
> +        } while (len == -1 && errno == EINTR);
> +        if (len == -1) {
> +            return -errno;
> +        }
> +
> +        /* Undo the changes above */
> +        iov[0].iov_base -= offset;
> +        iov[0].iov_len += offset;
> +
> +        /* Prepare for the next iteration */
> +        offset += len;
> +        total += len;
> +        size -= len;
> +    }
> +
> +    return total;
> +}

This code is very similar to the one in the iov_send_recv(),  but I
can't think on a trivial way to share it :p

Later,  Juan.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]