From patchwork Tue Aug 21 15:52:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 179084 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 A31D12C0097 for ; Wed, 22 Aug 2012 01:53:07 +1000 (EST) Received: from localhost ([::1]:40922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3qlN-0003qR-No for incoming@patchwork.ozlabs.org; Tue, 21 Aug 2012 11:53:05 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3ql5-0003mT-Mi for qemu-devel@nongnu.org; Tue, 21 Aug 2012 11:52:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3ql4-0000hN-EN for qemu-devel@nongnu.org; Tue, 21 Aug 2012 11:52:47 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:33442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3ql4-0000hA-5Z for qemu-devel@nongnu.org; Tue, 21 Aug 2012 11:52:46 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 21 Aug 2012 16:52:45 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 21 Aug 2012 16:52:42 +0100 Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by b06cxnps3074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7LFqZ5Q33685570 for ; Tue, 21 Aug 2012 15:52:35 GMT Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7LFqftV029124 for ; Tue, 21 Aug 2012 09:52:41 -0600 Received: from localhost (sig-9-146-161-2.uk.ibm.com [9.146.161.2]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7LFqeoC029108; Tue, 21 Aug 2012 09:52:41 -0600 From: Stefan Hajnoczi To: Date: Tue, 21 Aug 2012 16:52:30 +0100 Message-Id: <1345564351-14693-3-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1345564351-14693-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1345564351-14693-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12082115-2966-0000-0000-0000050DA224 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.109 Cc: Peter Maydell , Stefan Hajnoczi , Paolo Bonzini Subject: [Qemu-devel] [PATCH v2 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)