From nobody Wed Oct 22 13:01:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519794556725934.2971040703516; Tue, 27 Feb 2018 21:09:16 -0800 (PST) Received: from localhost ([::1]:42236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqtzP-0000vk-F3 for importer@patchew.org; Wed, 28 Feb 2018 00:09:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqtxM-00084u-7F for qemu-devel@nongnu.org; Wed, 28 Feb 2018 00:07:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqtxL-0000jA-1U for qemu-devel@nongnu.org; Wed, 28 Feb 2018 00:07:08 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54548 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eqtxK-0000ia-SS for qemu-devel@nongnu.org; Wed, 28 Feb 2018 00:07:06 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8485A40FB647 for ; Wed, 28 Feb 2018 05:07:06 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-95.pek2.redhat.com [10.72.12.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47A1E2024CA6; Wed, 28 Feb 2018 05:07:03 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 28 Feb 2018 13:06:25 +0800 Message-Id: <20180228050633.7410-7-peterx@redhat.com> In-Reply-To: <20180228050633.7410-1-peterx@redhat.com> References: <20180228050633.7410-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 28 Feb 2018 05:07:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 28 Feb 2018 05:07:06 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 06/14] qio: store gsources for net listeners 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Originally we were storing the GSources tag IDs. That'll be not enough if we are going to support non-default gcontext for QIO code. Switch to GSources without changing anything real. Now we still always pass in NULL, which means the default gcontext. Signed-off-by: Peter Xu --- include/io/net-listener.h | 21 ++++++++++++++-- io/net-listener.c | 62 +++++++++++++++++++++++++++++--------------= ---- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/include/io/net-listener.h b/include/io/net-listener.h index 56d6da7a76..566be283b3 100644 --- a/include/io/net-listener.h +++ b/include/io/net-listener.h @@ -53,7 +53,7 @@ struct QIONetListener { =20 char *name; QIOChannelSocket **sioc; - gulong *io_tag; + GSource **io_source; size_t nsioc; =20 bool connected; @@ -120,17 +120,34 @@ void qio_net_listener_add(QIONetListener *listener, QIOChannelSocket *sioc); =20 /** - * qio_net_listener_set_client_func: + * qio_net_listener_set_client_func_full: * @listener: the network listener object * @func: the callback function * @data: opaque data to pass to @func * @notify: callback to free @data + * @context: the context that the sources will be bound to * * Register @func to be invoked whenever a new client * connects to the listener. @func will be invoked * passing in the QIOChannelSocket instance for the * client. */ +void qio_net_listener_set_client_func_full(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify, + GMainContext *context); + +/** + * qio_net_listener_set_client_func: + * @listener: the network listener object + * @func: the callback function + * @data: opaque data to pass to @func + * @notify: callback to free @data + * + * Wrapper of qio_net_listener_set_client_func_full(), only that the + * sources will always be bound to default main context. + */ void qio_net_listener_set_client_func(QIONetListener *listener, QIONetListenerClientFunc func, gpointer data, diff --git a/io/net-listener.c b/io/net-listener.c index 3e9ac51b0e..7f07a81fed 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -106,12 +106,15 @@ int qio_net_listener_open_sync(QIONetListener *listen= er, } } =20 -static guint qio_net_listener_source_add(QIONetListener *listener, - QIOChannelSocket *sioc) +static GSource *qio_net_listener_source_add(QIONetListener *listener, + QIOChannelSocket *sioc, + GMainContext *context) { - return qio_channel_add_watch(QIO_CHANNEL(sioc), G_IO_IN, - qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref); + return qio_channel_add_watch_full(QIO_CHANNEL(sioc), G_IO_IN, + qio_net_listener_channel_func, + listener, + (GDestroyNotify)object_unref, + context); } =20 static void qio_net_listener_sources_clear(QIONetListener *listener) @@ -119,23 +122,25 @@ static void qio_net_listener_sources_clear(QIONetList= ener *listener) size_t i; =20 for (i =3D 0; i < listener->nsioc; i++) { - if (listener->io_tag[i]) { - g_source_remove(listener->io_tag[i]); - listener->io_tag[i] =3D 0; + if (listener->io_source[i]) { + g_source_destroy(listener->io_source[i]); + g_source_unref(listener->io_source[i]); + listener->io_source[i] =3D NULL; } } } =20 -static void qio_net_listener_sources_update(QIONetListener *listener) +static void qio_net_listener_sources_update(QIONetListener *listener, + GMainContext *context) { size_t i; =20 if (listener->io_func !=3D NULL) { for (i =3D 0; i < listener->nsioc; i++) { - assert(listener->io_tag[i] =3D=3D 0); + assert(listener->io_source[i] =3D=3D NULL); object_ref(OBJECT(listener)); - listener->io_tag[i] =3D qio_net_listener_source_add( - listener, listener->sioc[i]); + listener->io_source[i] =3D qio_net_listener_source_add( + listener, listener->sioc[i], context); } } } @@ -151,27 +156,30 @@ void qio_net_listener_add(QIONetListener *listener, =20 listener->sioc =3D g_renew(QIOChannelSocket *, listener->sioc, listener->nsioc + 1); - listener->io_tag =3D g_renew(gulong, listener->io_tag, listener->nsioc= + 1); + listener->io_source =3D g_renew(typeof(listener->io_source[0]), + listener->io_source, + listener->nsioc + 1); listener->sioc[listener->nsioc] =3D sioc; - listener->io_tag[listener->nsioc] =3D 0; + listener->io_source[listener->nsioc] =3D NULL; =20 object_ref(OBJECT(sioc)); listener->connected =3D true; =20 if (listener->io_func !=3D NULL) { object_ref(OBJECT(listener)); - listener->io_tag[listener->nsioc] =3D qio_net_listener_source_add( - listener, listener->sioc[listener->nsioc]); + listener->io_source[listener->nsioc] =3D qio_net_listener_source_a= dd( + listener, listener->sioc[listener->nsioc], NULL); } =20 listener->nsioc++; } =20 =20 -void qio_net_listener_set_client_func(QIONetListener *listener, - QIONetListenerClientFunc func, - gpointer data, - GDestroyNotify notify) +void qio_net_listener_set_client_func_full(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify, + GMainContext *context) { if (listener->io_notify) { listener->io_notify(listener->io_data); @@ -181,9 +189,17 @@ void qio_net_listener_set_client_func(QIONetListener *= listener, listener->io_notify =3D notify; =20 qio_net_listener_sources_clear(listener); - qio_net_listener_sources_update(listener); + qio_net_listener_sources_update(listener, context); } =20 +void qio_net_listener_set_client_func(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify) +{ + qio_net_listener_set_client_func_full(listener, func, data, + notify, NULL); +} =20 struct QIONetListenerClientWaitData { QIOChannelSocket *sioc; @@ -248,7 +264,7 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetLi= stener *listener) g_main_loop_unref(loop); g_main_context_unref(ctxt); =20 - qio_net_listener_sources_update(listener); + qio_net_listener_sources_update(listener, NULL); =20 return data.sioc; } @@ -285,7 +301,7 @@ static void qio_net_listener_finalize(Object *obj) for (i =3D 0; i < listener->nsioc; i++) { object_unref(OBJECT(listener->sioc[i])); } - g_free(listener->io_tag); + g_free(listener->io_source); g_free(listener->sioc); g_free(listener->name); } --=20 2.14.3