Paolo Bonzini <pbonz...@redhat.com> 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 <pbonz...@redhat.com>
Reviewed-by: Juan Quintela <quint...@redhat.com> > +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.