From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPYdO-0003VM-1F for qemu-devel@nongnu.org; Tue, 09 Apr 2013 09:30:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPYdJ-0001j8-EZ for qemu-devel@nongnu.org; Tue, 09 Apr 2013 09:30:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPYdJ-0001j1-58 for qemu-devel@nongnu.org; Tue, 09 Apr 2013 09:30:45 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r39DUb3q010432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Apr 2013 09:30:44 -0400 From: Juan Quintela In-Reply-To: <1364402192-18169-7-git-send-email-pbonzini@redhat.com> (Paolo Bonzini's message of "Wed, 27 Mar 2013 17:36:32 +0100") References: <1364402192-18169-1-git-send-email-pbonzini@redhat.com> <1364402192-18169-7-git-send-email-pbonzini@redhat.com> Date: Tue, 09 Apr 2013 15:30:28 +0200 Message-ID: <87y5crbzm3.fsf@elfo.elfo> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 6/6] qemu-file: do not use stdio for qemu_fdopen Reply-To: quintela@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: owasserm@redhat.com, qemu-devel@nongnu.org Paolo Bonzini 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 Reviewed-by: Juan Quintela > +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.