From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
qemu-block@nongnu.org, "Eric Blake" <eblake@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Peter Xu" <peterx@redhat.com>
Subject: [Qemu-devel] [PULL 3/6] qio: store gsources for net listeners
Date: Wed, 7 Mar 2018 11:25:29 +0000 [thread overview]
Message-ID: <20180307112532.24248-4-berrange@redhat.com> (raw)
In-Reply-To: <20180307112532.24248-1-berrange@redhat.com>
From: Peter Xu <peterx@redhat.com>
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 <peterx@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
include/io/net-listener.h | 22 ++++++++++++++++--
io/net-listener.c | 58 +++++++++++++++++++++++++++++------------------
2 files changed, 56 insertions(+), 24 deletions(-)
diff --git a/include/io/net-listener.h b/include/io/net-listener.h
index 56d6da7a76..8081ac58a2 100644
--- a/include/io/net-listener.h
+++ b/include/io/net-listener.h
@@ -53,7 +53,7 @@ struct QIONetListener {
char *name;
QIOChannelSocket **sioc;
- gulong *io_tag;
+ GSource **io_source;
size_t nsioc;
bool connected;
@@ -120,17 +120,35 @@ void qio_net_listener_add(QIONetListener *listener,
QIOChannelSocket *sioc);
/**
- * 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. If %NULL,
+ * the default context will be used.
*
* 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 de38dfae99..555e8acaa4 100644
--- a/io/net-listener.c
+++ b/io/net-listener.c
@@ -118,29 +118,32 @@ void qio_net_listener_add(QIONetListener *listener,
listener->sioc = g_renew(QIOChannelSocket *, listener->sioc,
listener->nsioc + 1);
- listener->io_tag = g_renew(gulong, listener->io_tag, listener->nsioc + 1);
+ listener->io_source = g_renew(typeof(listener->io_source[0]),
+ listener->io_source,
+ listener->nsioc + 1);
listener->sioc[listener->nsioc] = sioc;
- listener->io_tag[listener->nsioc] = 0;
+ listener->io_source[listener->nsioc] = NULL;
object_ref(OBJECT(sioc));
listener->connected = true;
if (listener->io_func != NULL) {
object_ref(OBJECT(listener));
- listener->io_tag[listener->nsioc] = qio_channel_add_watch(
+ listener->io_source[listener->nsioc] = qio_channel_add_watch_source(
QIO_CHANNEL(listener->sioc[listener->nsioc]), G_IO_IN,
qio_net_listener_channel_func,
- listener, (GDestroyNotify)object_unref);
+ listener, (GDestroyNotify)object_unref, NULL);
}
listener->nsioc++;
}
-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)
{
size_t i;
@@ -152,23 +155,32 @@ void qio_net_listener_set_client_func(QIONetListener *listener,
listener->io_notify = notify;
for (i = 0; i < listener->nsioc; i++) {
- if (listener->io_tag[i]) {
- g_source_remove(listener->io_tag[i]);
- listener->io_tag[i] = 0;
+ if (listener->io_source[i]) {
+ g_source_destroy(listener->io_source[i]);
+ g_source_unref(listener->io_source[i]);
+ listener->io_source[i] = NULL;
}
}
if (listener->io_func != NULL) {
for (i = 0; i < listener->nsioc; i++) {
object_ref(OBJECT(listener));
- listener->io_tag[i] = qio_channel_add_watch(
+ listener->io_source[i] = qio_channel_add_watch_source(
QIO_CHANNEL(listener->sioc[i]), G_IO_IN,
qio_net_listener_channel_func,
- listener, (GDestroyNotify)object_unref);
+ listener, (GDestroyNotify)object_unref, context);
}
}
}
+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);
+}
struct QIONetListenerClientWaitData {
QIOChannelSocket *sioc;
@@ -211,9 +223,10 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetListener *listener)
size_t i;
for (i = 0; i < listener->nsioc; i++) {
- if (listener->io_tag[i]) {
- g_source_remove(listener->io_tag[i]);
- listener->io_tag[i] = 0;
+ if (listener->io_source[i]) {
+ g_source_destroy(listener->io_source[i]);
+ g_source_unref(listener->io_source[i]);
+ listener->io_source[i] = NULL;
}
}
@@ -241,10 +254,10 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetListener *listener)
if (listener->io_func != NULL) {
for (i = 0; i < listener->nsioc; i++) {
object_ref(OBJECT(listener));
- listener->io_tag[i] = qio_channel_add_watch(
+ listener->io_source[i] = qio_channel_add_watch_source(
QIO_CHANNEL(listener->sioc[i]), G_IO_IN,
qio_net_listener_channel_func,
- listener, (GDestroyNotify)object_unref);
+ listener, (GDestroyNotify)object_unref, NULL);
}
}
@@ -260,9 +273,10 @@ void qio_net_listener_disconnect(QIONetListener *listener)
}
for (i = 0; i < listener->nsioc; i++) {
- if (listener->io_tag[i]) {
- g_source_remove(listener->io_tag[i]);
- listener->io_tag[i] = 0;
+ if (listener->io_source[i]) {
+ g_source_destroy(listener->io_source[i]);
+ g_source_unref(listener->io_source[i]);
+ listener->io_source[i] = NULL;
}
qio_channel_close(QIO_CHANNEL(listener->sioc[i]), NULL);
}
@@ -285,7 +299,7 @@ static void qio_net_listener_finalize(Object *obj)
for (i = 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);
}
--
2.14.3
next prev parent reply other threads:[~2018-03-07 11:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-07 11:25 [Qemu-devel] [PULL 0/6] Qio next patches Daniel P. Berrangé
2018-03-07 11:25 ` [Qemu-devel] [PULL 1/6] qio: rename qio_task_thread_result Daniel P. Berrangé
2018-03-07 11:25 ` [Qemu-devel] [PULL 2/6] qio: introduce qio_channel_add_watch_{full|source} Daniel P. Berrangé
2018-03-07 11:25 ` Daniel P. Berrangé [this message]
2018-03-07 11:25 ` [Qemu-devel] [PULL 4/6] qio: non-default context for threaded qtask Daniel P. Berrangé
2018-03-07 11:25 ` [Qemu-devel] [PULL 5/6] qio: non-default context for async conn Daniel P. Berrangé
2018-03-07 11:25 ` [Qemu-devel] [PULL 6/6] qio: non-default context for TLS handshake Daniel P. Berrangé
2018-03-08 12:56 ` [Qemu-devel] [PULL 0/6] Qio next patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180307112532.24248-4-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).