From 0cb8b1796728eb722098c75127bbfd133d7dc58d Mon Sep 17 00:00:00 2001
Message-Id: <0cb8b1796728eb722098c75127bbfd133d7dc58d.1311528042.git.blauwirbel@gmail.com>
In-Reply-To: <37fee275c24a189727be954a1485923382657eb2.1311528042.git.blauwirbel@gmail.com>
References: <37fee275c24a189727be954a1485923382657eb2.1311528042.git.blauwirbel@gmail.com>
From: Blue Swirl <blauwirbel@gmail.com>
Date: Sat, 23 Jul 2011 20:04:29 +0000
Subject: [PATCH 2/3] Wrap recv to avoid warnings

Avoid warnings like these by wrapping recv():
  CC    slirp/ip_icmp.o
/src/qemu/slirp/ip_icmp.c: In function 'icmp_receive':
/src/qemu/slirp/ip_icmp.c:418:5: error: passing argument 2 of 'recv' from incompatible pointer type [-Werror]
/usr/local/lib/gcc/i686-mingw32msvc/4.6.0/../../../../i686-mingw32msvc/include/winsock2.h:547:32: note: expected 'char *' but argument is of type 'struct icmp *'

Remove also casts used to avoid warnings.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 block/sheepdog.c     |    2 +-
 gdbstub.c            |    2 +-
 linux-user/syscall.c |    2 +-
 nbd.c                |    2 +-
 net/socket.c         |    4 ++--
 qemu-char.c          |    4 ++--
 qemu-common.h        |    6 ++++++
 savevm.c             |    2 +-
 slirp/ip_icmp.c      |    2 +-
 slirp/slirp.c        |    2 +-
 slirp/socket.c       |    4 ++--
 ui/vnc-tls.c         |    2 +-
 ui/vnc.c             |    2 +-
 13 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 77a4de5..e150ac0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -496,7 +496,7 @@ static ssize_t recvmsg(int s, struct msghdr *msg, int flags)
     }
     buf = qemu_malloc(size);
 
-    ret = recv(s, buf, size, flags);
+    ret = qemu_recv(s, buf, size, flags);
     if (ret < 0) {
         goto out;
     }
diff --git a/gdbstub.c b/gdbstub.c
index c085a5a..27b0cfa 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -319,7 +319,7 @@ static int get_char(GDBState *s)
     int ret;
 
     for(;;) {
-        ret = recv(s->fd, &ch, 1, 0);
+        ret = qemu_recv(s->fd, &ch, 1, 0);
         if (ret < 0) {
             if (errno == ECONNRESET)
                 s->fd = -1;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1dd7aad..73f9baa 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2004,7 +2004,7 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
         ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen));
     } else {
         addr = NULL; /* To keep compiler quiet.  */
-        ret = get_errno(recv(fd, host_msg, len, flags));
+        ret = get_errno(qemu_recv(fd, host_msg, len, flags));
     }
     if (!is_error(ret)) {
         if (target_addr) {
diff --git a/nbd.c b/nbd.c
index 0dcd86b..e7a585d 100644
--- a/nbd.c
+++ b/nbd.c
@@ -78,7 +78,7 @@ size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read)
         ssize_t len;
 
         if (do_read) {
-            len = recv(fd, buffer + offset, size - offset, 0);
+            len = qemu_recv(fd, buffer + offset, size - offset, 0);
         } else {
             len = send(fd, buffer + offset, size - offset, 0);
         }
diff --git a/net/socket.c b/net/socket.c
index bc1bf58..11fe5f3 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -76,7 +76,7 @@ static void net_socket_send(void *opaque)
     uint8_t buf1[4096];
     const uint8_t *buf;
 
-    size = recv(s->fd, (void *)buf1, sizeof(buf1), 0);
+    size = qemu_recv(s->fd, buf1, sizeof(buf1), 0);
     if (size < 0) {
         err = socket_error();
         if (err != EWOULDBLOCK)
@@ -138,7 +138,7 @@ static void net_socket_send_dgram(void *opaque)
     NetSocketState *s = opaque;
     int size;
 
-    size = recv(s->fd, (void *)s->buf, sizeof(s->buf), 0);
+    size = qemu_recv(s->fd, s->buf, sizeof(s->buf), 0);
     if (size < 0)
         return;
     if (size == 0) {
diff --git a/qemu-char.c b/qemu-char.c
index 2982bfd..8e8cf31 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1860,7 +1860,7 @@ static void udp_chr_read(void *opaque)
 
     if (s->max_size == 0)
         return;
-    s->bufcnt = recv(s->fd, (void *)s->buf, sizeof(s->buf), 0);
+    s->bufcnt = qemu_recv(s->fd, s->buf, sizeof(s->buf), 0);
     s->bufptr = s->bufcnt;
     if (s->bufcnt <= 0)
         return;
@@ -2078,7 +2078,7 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len)
 static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len)
 {
     TCPCharDriver *s = chr->opaque;
-    return recv(s->fd, buf, len, 0);
+    return qemu_recv(s->fd, buf, len, 0);
 }
 #endif
 
diff --git a/qemu-common.h b/qemu-common.h
index ba55719..391fadd 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -200,6 +200,12 @@ int qemu_eventfd(int pipefd[2]);
 int qemu_pipe(int pipefd[2]);
 #endif
 
+#ifdef _WIN32
+#define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
+#else
+#define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
+#endif
+
 /* Error handling.  */
 
 void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
diff --git a/savevm.c b/savevm.c
index 8139bc7..79db4cb 100644
--- a/savevm.c
+++ b/savevm.c
@@ -194,7 +194,7 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
     ssize_t len;
 
     do {
-        len = recv(s->fd, (void *)buf, size, 0);
+        len = qemu_recv(s->fd, buf, size, 0);
     } while (len == -1 && socket_error() == EINTR);
 
     if (len == -1)
diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 14a5312..4b43994 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -415,7 +415,7 @@ void icmp_receive(struct socket *so)
     icp = mtod(m, struct icmp *);
 
     id = icp->icmp_id;
-    len = recv(so->s, icp, m->m_len, 0);
+    len = qemu_recv(so->s, icp, m->m_len, 0);
     icp->icmp_id = id;
 
     m->m_data -= hlen;
diff --git a/slirp/slirp.c b/slirp/slirp.c
index faaa2f3..df787ea 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -522,7 +522,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
 	 	 	 */
 #ifdef PROBE_CONN
 			if (so->so_state & SS_ISFCONNECTING) {
-			  ret = recv(so->s, (char *)&ret, 0,0);
+                          ret = qemu_recv(so->s, &ret, 0,0);
 
 			  if (ret < 0) {
 			    /* XXX */
diff --git a/slirp/socket.c b/slirp/socket.c
index 9b8ae13..77b0c98 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -166,7 +166,7 @@ soread(struct socket *so)
 	nn = readv(so->s, (struct iovec *)iov, n);
 	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
 #else
-	nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
+	nn = qemu_recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
 #endif
 	if (nn <= 0) {
 		if (nn < 0 && (errno == EINTR || errno == EAGAIN))
@@ -191,7 +191,7 @@ soread(struct socket *so)
 	 */
 	if (n == 2 && nn == iov[0].iov_len) {
             int ret;
-            ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
+            ret = qemu_recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
             if (ret > 0)
                 nn += ret;
         }
diff --git a/ui/vnc-tls.c b/ui/vnc-tls.c
index dec626c..31f1467 100644
--- a/ui/vnc-tls.c
+++ b/ui/vnc-tls.c
@@ -89,7 +89,7 @@ static ssize_t vnc_tls_pull(gnutls_transport_ptr_t transport,
     int ret;
 
  retry:
-    ret = recv(vs->csock, data, len, 0);
+    ret = qemu_recv(vs->csock, data, len, 0);
     if (ret < 0) {
         if (errno == EINTR)
             goto retry;
diff --git a/ui/vnc.c b/ui/vnc.c
index 4425180..f1e27d9 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1199,7 +1199,7 @@ long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen)
         }
     } else
 #endif /* CONFIG_VNC_TLS */
-        ret = recv(vs->csock, (void *)data, datalen, 0);
+        ret = qemu_recv(vs->csock, data, datalen, 0);
     VNC_DEBUG("Read wire %p %zd -> %ld\n", data, datalen, ret);
     return vnc_client_io_error(vs, ret, socket_error());
 }
-- 
1.7.2.5
