peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0197-net-EAGAIN-handling-for-net-socket.c-UDP.patch

5544c1
From a2374b78f298d5755e96468bb97e4d7b660ff9d6 Mon Sep 17 00:00:00 2001
5544c1
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
5544c1
Date: Mon, 20 Aug 2012 10:28:53 +0100
5544c1
Subject: [PATCH] net: EAGAIN handling for net/socket.c UDP
5544c1
5544c1
Implement asynchronous send for UDP (or other SOCK_DGRAM) sockets.  If
5544c1
send fails with EAGAIN we wait for the socket to become writable again.
5544c1
5544c1
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
5544c1
(cherry picked from commit 213fd5087e2e4e2da10ad266df0ba950cf7618bf)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 net/socket.c | 14 ++++++++++++--
5544c1
 1 file changed, 12 insertions(+), 2 deletions(-)
5544c1
5544c1
diff --git a/net/socket.c b/net/socket.c
5544c1
index 54e32f0..e5e4e8d 100644
5544c1
--- a/net/socket.c
5544c1
+++ b/net/socket.c
5544c1
@@ -102,9 +102,19 @@ static ssize_t net_socket_receive(NetClientState *nc, const uint8_t *buf, size_t
5544c1
 static ssize_t net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf, size_t size)
5544c1
 {
5544c1
     NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
5544c1
+    ssize_t ret;
5544c1
 
5544c1
-    return sendto(s->fd, (const void *)buf, size, 0,
5544c1
-                  (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
5544c1
+    do {
5544c1
+        ret = sendto(s->fd, buf, size, 0,
5544c1
+                     (struct sockaddr *)&s->dgram_dst,
5544c1
+                     sizeof(s->dgram_dst));
5544c1
+    } while (ret == -1 && errno == EINTR);
5544c1
+
5544c1
+    if (ret == -1 && errno == EAGAIN) {
5544c1
+        net_socket_write_poll(s, true);
5544c1
+        return 0;
5544c1
+    }
5544c1
+    return ret;
5544c1
 }
5544c1
 
5544c1
 static void net_socket_send(void *opaque)
5544c1
-- 
5544c1
1.7.12.1
5544c1