diff options
author | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2012-08-20 10:28:53 +0100 |
---|---|---|
committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2012-10-11 21:44:18 -0500 |
commit | 9d72a090b2f68201701b10b765c8b3eac596b3bc (patch) | |
tree | 09dfd90c732198a963997b5172cfa1674b0d7052 | |
parent | ab52df7712e0efe3bee32ccfed79729cb9dec9f8 (diff) |
net: EAGAIN handling for net/socket.c UDP
Implement asynchronous send for UDP (or other SOCK_DGRAM) sockets. If
send fails with EAGAIN we wait for the socket to become writable again.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
(cherry picked from commit 213fd5087e2e4e2da10ad266df0ba950cf7618bf)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
-rw-r--r-- | net/socket.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/net/socket.c b/net/socket.c index 54e32f0965..e5e4e8da99 100644 --- a/net/socket.c +++ b/net/socket.c @@ -102,9 +102,19 @@ static ssize_t net_socket_receive(NetClientState *nc, const uint8_t *buf, size_t static ssize_t net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf, size_t size) { NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc); + ssize_t ret; - return sendto(s->fd, (const void *)buf, size, 0, - (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst)); + do { + ret = sendto(s->fd, buf, size, 0, + (struct sockaddr *)&s->dgram_dst, + sizeof(s->dgram_dst)); + } while (ret == -1 && errno == EINTR); + + if (ret == -1 && errno == EAGAIN) { + net_socket_write_poll(s, true); + return 0; + } + return ret; } static void net_socket_send(void *opaque) |