From patchwork Tue Feb 5 18:28:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 10798169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7DAE01805 for ; Tue, 5 Feb 2019 19:20:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 707F42C1AA for ; Tue, 5 Feb 2019 19:20:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E7BA2C940; Tue, 5 Feb 2019 19:20:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EDA492C93C for ; Tue, 5 Feb 2019 19:20:35 +0000 (UTC) Received: from localhost ([127.0.0.1]:38472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr6Gp-0005Ix-78 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Feb 2019 14:20:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr5T5-00051q-JL for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:29:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gr5T3-0005V0-Ra for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:29:11 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:34762) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gr5T1-0005S1-A5 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:29:07 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id DF0F1C0FF; Tue, 5 Feb 2019 19:29:05 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YkKfEglcYP_8; Tue, 5 Feb 2019 19:29:04 +0100 (CET) Received: from function (unknown [188.164.201.34]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 1FD27C11E; Tue, 5 Feb 2019 19:28:54 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1gr5Sj-0007ne-I0; Tue, 05 Feb 2019 19:28:49 +0100 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 5 Feb 2019 20:28:28 +0200 Message-Id: <20190205182848.29887-13-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190205182848.29887-1-samuel.thibault@ens-lyon.org> References: <20190205182848.29887-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv3 12/32] slirp: replace qemu_set_nonblock() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Replace qemu_set_nonblock() with slirp_set_nonblock() qemu_set_nonblock() does some event registration with the main loop. Add a new callback register_poll_fd() for that reason. Always build the fd-register stub, to avoid #if WIN32. Signed-off-by: Marc-André Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 6 ++++++ slirp/libslirp.h | 2 ++ slirp/misc.c | 3 ++- slirp/tcp_subr.c | 6 ++++-- slirp/util.c | 14 ++++++++++++++ slirp/util.h | 1 + stubs/Makefile.objs | 2 +- 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index c24a779425..6f756a4dcc 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -186,6 +186,11 @@ static void net_slirp_timer_mod(void *timer, int64_t expire_timer) timer_mod(timer, expire_timer); } +static void net_slirp_register_poll_fd(int fd) +{ + qemu_fd_register(fd); +} + static const SlirpCb slirp_cb = { .output = net_slirp_output, .guest_error = net_slirp_guest_error, @@ -193,6 +198,7 @@ static const SlirpCb slirp_cb = { .timer_new = net_slirp_timer_new, .timer_free = net_slirp_timer_free, .timer_mod = net_slirp_timer_mod, + .register_poll_fd = net_slirp_register_poll_fd, }; static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 3e75dadfa3..70e99139bf 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -27,6 +27,8 @@ typedef struct SlirpCb { void (*timer_free)(void *timer); /* Modify a timer to expire at @expire_time */ void (*timer_mod)(void *timer, int64_t expire_time); + /* Register a fd for future polling */ + void (*register_poll_fd)(int fd); } SlirpCb; diff --git a/slirp/misc.c b/slirp/misc.c index 32ec02a525..4ee20a10e4 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -163,7 +163,8 @@ fork_exec(struct socket *so, const char *ex) slirp_socket_set_fast_reuse(so->s); opt = 1; slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - qemu_set_nonblock(so->s); + slirp_set_nonblock(so->s); + so->slirp->cb->register_poll_fd(so->s); return 1; } diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 3567f320ff..8087ffc047 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -412,7 +412,8 @@ int tcp_fconnect(struct socket *so, unsigned short af) int opt, s=so->s; struct sockaddr_storage addr; - qemu_set_nonblock(s); + slirp_set_nonblock(s); + so->slirp->cb->register_poll_fd(so->s); slirp_socket_set_fast_reuse(s); opt = 1; slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); @@ -484,7 +485,8 @@ void tcp_connect(struct socket *inso) tcp_close(sototcpcb(so)); /* This will sofree() as well */ return; } - qemu_set_nonblock(s); + slirp_set_nonblock(s); + so->slirp->cb->register_poll_fd(so->s); slirp_socket_set_fast_reuse(s); opt = 1; slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); diff --git a/slirp/util.c b/slirp/util.c index b1a36b27bc..59f6713c8b 100644 --- a/slirp/util.c +++ b/slirp/util.c @@ -43,6 +43,20 @@ int inet_aton(const char *cp, struct in_addr *ia) } #endif +void slirp_set_nonblock(int fd) +{ +#ifndef _WIN32 + int f; + f = fcntl(fd, F_GETFL); + assert(f != -1); + f = fcntl(fd, F_SETFL, f | O_NONBLOCK); + assert(f != -1); +#else + unsigned long opt = 1; + ioctlsocket(fd, FIONBIO, &opt); +#endif +} + static void slirp_set_cloexec(int fd) { #ifndef _WIN32 diff --git a/slirp/util.h b/slirp/util.h index fe6f1fbb62..4f6e80c3ed 100644 --- a/slirp/util.h +++ b/slirp/util.h @@ -68,6 +68,7 @@ int inet_aton(const char *cp, struct in_addr *ia); #endif int slirp_socket(int domain, int type, int protocol); +void slirp_set_nonblock(int fd); static inline int slirp_socket_set_nodelay(int fd) { diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 5dd0aeeec6..cda0efa4e8 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -33,7 +33,7 @@ stub-obj-y += trace-control.o stub-obj-y += uuid.o stub-obj-y += vm-stop.o stub-obj-y += vmstate.o -stub-obj-$(CONFIG_WIN32) += fd-register.o +stub-obj-y += fd-register.o stub-obj-y += qmp_memory_device.o stub-obj-y += target-monitor-defs.o stub-obj-y += target-get-monitor-def.o