diff mbox

[PATCHv2,5/7] Export qemu_sendv_recvv() and use it in qemu_sendv() and qemu_recvv()

Message ID 1331430564-32745-6-git-send-email-mjt@msgid.tls.msk.ru
State New
Headers show

Commit Message

Michael Tokarev March 11, 2012, 1:49 a.m. UTC
Rename do_sendv_recvv() to qemu_sendv_recvv(),
change its last arg (do_send) from int to bool,
export it in qemu-common.h, and made the two
callers of it (qemu_sendv() and qemu_recvv())
to be trivial #defines just adding 5th arg.

qemu_sendv_recvv() will be used later.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 cutils.c      |   15 ++-------------
 qemu-common.h |   14 ++++++++++++--
 2 files changed, 14 insertions(+), 15 deletions(-)

Comments

Paolo Bonzini March 11, 2012, 3 p.m. UTC | #1
Il 11/03/2012 02:49, Michael Tokarev ha scritto:
> Rename do_sendv_recvv() to qemu_sendv_recvv(),
> change its last arg (do_send) from int to bool,
> export it in qemu-common.h, and made the two
> callers of it (qemu_sendv() and qemu_recvv())
> to be trivial #defines just adding 5th arg.

GCC is smart and knows how to do tail calls in many cases.  Thus, I
don't see very much the point of this patch.

Paolo
Michael Tokarev March 11, 2012, 3:22 p.m. UTC | #2
On 11.03.2012 19:00, Paolo Bonzini wrote:
> Il 11/03/2012 02:49, Michael Tokarev ha scritto:
>> Rename do_sendv_recvv() to qemu_sendv_recvv(),
>> change its last arg (do_send) from int to bool,
>> export it in qemu-common.h, and made the two
>> callers of it (qemu_sendv() and qemu_recvv())
>> to be trivial #defines just adding 5th arg.
> 
> GCC is smart and knows how to do tail calls in many cases.  Thus, I
> don't see very much the point of this patch.

The point is to allow qemu_sendv_recvv() to be used
directly, see the next patch
 [PATCHv2 6/7] cleanup qemu_co_sendv(), qemu_co_recvv() and friends
for an example, and see my previous attempt to address
all this with bdrv_* methods where reads and writes
are implemented in common functions and are split
back on layer boundary, just to go to a common
routine on the next layer.  Or worse yet, repeating
exactly the same code like in this 6/7 patch for
qemu_co_recvv() and qemu_co_sendv().

It is not about tail calls at all.

Thanks,

/mjt
diff mbox

Patch

diff --git a/cutils.c b/cutils.c
index b3b9cfb..b6f8eb8 100644
--- a/cutils.c
+++ b/cutils.c
@@ -419,8 +419,8 @@  int qemu_parse_fd(const char *param)
  * The first `offset' bytes in the iovec buffer are skipped and next
  * `bytes' bytes are used.
  */
-static int do_sendv_recvv(int sockfd, struct iovec *iov, size_t offset, size_t bytes,
-                          int do_sendv)
+int qemu_sendv_recvv(int sockfd, struct iovec *iov, size_t offset, size_t bytes,
+		     bool do_sendv)
 {
     int ret, iovlen;
     size_t diff;
@@ -499,14 +499,3 @@  static int do_sendv_recvv(int sockfd, struct iovec *iov, size_t offset, size_t b
     last_iov->iov_len += diff;
     return ret;
 }
-
-int qemu_recvv(int sockfd, struct iovec *iov, size_t offset, size_t bytes)
-{
-    return do_sendv_recvv(sockfd, iov, offset, bytes, 0);
-}
-
-int qemu_sendv(int sockfd, struct iovec *iov, size_t offset, size_t bytes)
-{
-    return do_sendv_recvv(sockfd, iov, offset, bytes, 1);
-}
-
diff --git a/qemu-common.h b/qemu-common.h
index bb75dd3..b8190e9 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -199,8 +199,18 @@  int qemu_pipe(int pipefd[2]);
 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
 #endif
 
-int qemu_recvv(int sockfd, struct iovec *iov, size_t offset, size_t bytes);
-int qemu_sendv(int sockfd, struct iovec *iov, size_t offset, size_t bytes);
+/**
+ * Send or receive data from/to an (optionally partial) iovec.
+ * Instead of processing whole iovector, this routine can process
+ * not more than a specified number of bytes, and start not at
+ * the beginning of iovec but at byte position `offset'.
+ */
+int qemu_sendv_recvv(int sockfd, struct iovec *iov,
+		     size_t offset, size_t bytes, bool do_sendv);
+#define qemu_recvv(sockfd, iov, offset, bytes) \
+  qemu_sendv_recvv(sockfd, iov, offset, bytes, false)
+#define qemu_sendv(sockfd, iov, offset, bytes) \
+  qemu_sendv_recvv(sockfd, iov, offset, bytes, true)
 
 /* Error handling.  */