From patchwork Fri Sep 14 08:46:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 183852 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 C347E2C0080 for ; Fri, 14 Sep 2012 19:15:07 +1000 (EST) Received: from localhost ([::1]:42599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRZN-00064V-4Y for incoming@patchwork.ozlabs.org; Fri, 14 Sep 2012 04:48:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRYu-00058k-W8 for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TCRYp-0000wW-76 for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:44 -0400 Received: from mail-we0-f173.google.com ([74.125.82.173]:47609) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRYo-0000sO-TB for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:39 -0400 Received: by mail-we0-f173.google.com with SMTP id z53so2182085wey.4 for ; Fri, 14 Sep 2012 01:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=r2fIO1vcqF+uuj8/Lt3WlbuGguddDjDFGWqcsuI2Y1Y=; b=X/DZ+uIDp+CdeyC1Cd/fg0PASMoiqNY8TkAZNhcGZZoSmT/Oz24Vy0hUcQh0KXITgx 5tQOCTmJDusQGkCYHdCJg3RrZqsuN3Msd0zNmI1FeuApxxQZTc26f6uUiezFvuHzI5FC C2GwQXfMqrwVb7DKlBLccVOxCSyigeY2taKMaQX9eNgaiy2phi7DXK7uxoyMB0z+V9Et +vr+ojb4zjxF7SoOWd6a0dLpx56OSp3IjSY/NEcKhqWNjNBXKcbwbz77Oohr8HA2pwW8 gKSpej9TyVsw1/pb0tQgL8tHF8bsJS/dLPRTHpSSmhv5t0mSOhGcFRYbP4a+G5IJyw+V Z5Gg== Received: by 10.180.14.74 with SMTP id n10mr4404917wic.17.1347612458529; Fri, 14 Sep 2012 01:47:38 -0700 (PDT) Received: from localhost ([109.224.133.37]) by mx.google.com with ESMTPS id v3sm17856288wiw.7.2012.09.14.01.47.37 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Sep 2012 01:47:37 -0700 (PDT) From: Stefan Hajnoczi To: Anthony Liguori Date: Fri, 14 Sep 2012 09:46:59 +0100 Message-Id: <1347612420-5704-13-git-send-email-stefanha@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1347612420-5704-1-git-send-email-stefanha@gmail.com> References: <1347612420-5704-1-git-send-email-stefanha@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.173 Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 12/13] 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 From: Stefan Hajnoczi 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 7bff536..aabf0a4 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)