From patchwork Mon Aug 20 13:27:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 178817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 683E72C00B0 for ; Tue, 21 Aug 2012 00:08:34 +1000 (EST) Received: from localhost ([::1]:48434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3S0x-0005wg-H5 for incoming@patchwork.ozlabs.org; Mon, 20 Aug 2012 09:27:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3S0h-0005it-MK for qemu-devel@nongnu.org; Mon, 20 Aug 2012 09:27:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3S0b-0004hi-SR for qemu-devel@nongnu.org; Mon, 20 Aug 2012 09:27:15 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:42830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3S0b-0004hJ-Jd for qemu-devel@nongnu.org; Mon, 20 Aug 2012 09:27:09 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Aug 2012 14:27:08 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Aug 2012 14:27:07 +0100 Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7KDR0U020447394 for ; Mon, 20 Aug 2012 13:27:00 GMT Received: from d06av11.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7KDR6ds009147 for ; Mon, 20 Aug 2012 07:27:06 -0600 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.145]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7KDR6fQ009141; Mon, 20 Aug 2012 07:27:06 -0600 From: Stefan Hajnoczi To: Date: Mon, 20 Aug 2012 14:27:00 +0100 Message-Id: <1345469221-15992-3-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1345469221-15992-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1345469221-15992-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12082013-0542-0000-0000-000002C6DE8E X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.113 Cc: Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 2/3] net: EAGAIN handling for net/socket.c UDP X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- net/socket.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/socket.c b/net/socket.c index 54e32f0..e5e4e8d 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)