From patchwork Tue May 19 10:51:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 473685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CDF0B140D4E for ; Tue, 19 May 2015 12:54:01 +1000 (AEST) Received: from localhost ([::1]:43660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuXfL-0008HU-Si for incoming@patchwork.ozlabs.org; Mon, 18 May 2015 22:53:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuXdF-0003vl-RQ for qemu-devel@nongnu.org; Mon, 18 May 2015 22:51:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuXdE-0001ic-U5 for qemu-devel@nongnu.org; Mon, 18 May 2015 22:51:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51779) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuXdE-0001iT-O4; Mon, 18 May 2015 22:51:48 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4J2pdMP018717 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 18 May 2015 22:51:39 -0400 Received: from cpc-pc.redhat.com (vpn1-5-200.pek2.redhat.com [10.72.5.200]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4J2p7Rm009902; Mon, 18 May 2015 22:51:34 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 19 May 2015 10:51:02 +0000 Message-Id: <1432032670-15124-6-git-send-email-famz@redhat.com> In-Reply-To: <1432032670-15124-1-git-send-email-famz@redhat.com> References: <1432032670-15124-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , Jason Wang , Vincenzo Maffione , "Vassili Karpov \(malc\)" , Gerd Hoffmann , Stefan Hajnoczi , Amit Shah , Paolo Bonzini , Giuseppe Lettieri , Luigi Rizzo Subject: [Qemu-devel] [PATCH v3 05/13] net/socket: Drop net_socket_can_send 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 This callback is called by main loop before polling s->fd, if it returns false, the fd will not be polled in this iteration. This is redundant with checks inside read callback. After this patch, the data will be sent to peer when it arrives. If the device can't receive, it will be queued to incoming_queue, and when the device status changes, this queue will be flushed. If the peer is not ready, disable the read poll until send completes. Signed-off-by: Fam Zheng --- net/socket.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/net/socket.c b/net/socket.c index c30e03f..82fa175 100644 --- a/net/socket.c +++ b/net/socket.c @@ -51,18 +51,9 @@ typedef struct NetSocketState { static void net_socket_accept(void *opaque); static void net_socket_writable(void *opaque); -/* Only read packets from socket when peer can receive them */ -static int net_socket_can_send(void *opaque) -{ - NetSocketState *s = opaque; - - return qemu_can_send_packet(&s->nc); -} - static void net_socket_update_fd_handler(NetSocketState *s) { - qemu_set_fd_handler2(s->fd, - s->read_poll ? net_socket_can_send : NULL, + qemu_set_fd_handler2(s->fd, NULL, s->read_poll ? s->send_fn : NULL, s->write_poll ? net_socket_writable : NULL, s); @@ -142,6 +133,15 @@ static ssize_t net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf, return ret; } +static void net_socket_send_completed(NetClientState *nc, ssize_t len) +{ + NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc); + + if (!s->read_poll) { + net_socket_read_poll(s, true); + } +} + static void net_socket_send(void *opaque) { NetSocketState *s = opaque; @@ -211,9 +211,13 @@ static void net_socket_send(void *opaque) buf += l; size -= l; if (s->index >= s->packet_len) { - qemu_send_packet(&s->nc, s->buf, s->packet_len); s->index = 0; s->state = 0; + if (qemu_send_packet_async(&s->nc, s->buf, size, + net_socket_send_completed) == 0) { + net_socket_read_poll(s, false); + break; + } } break; } @@ -234,7 +238,10 @@ static void net_socket_send_dgram(void *opaque) net_socket_write_poll(s, false); return; } - qemu_send_packet(&s->nc, s->buf, size); + if (qemu_send_packet_async(&s->nc, s->buf, size, + net_socket_send_completed) == 0) { + net_socket_read_poll(s, false); + } } static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr *localaddr)