From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P . Berrange" <berrange@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
peterx@redhat.com, "Markus Armbruster" <armbru@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: [Qemu-devel] [PATCH v3 3/6] qio: store gsources for net listeners
Date: Mon, 5 Mar 2018 14:43:21 +0800 [thread overview]
Message-ID: <20180305064324.9238-4-peterx@redhat.com> (raw)
In-Reply-To: <20180305064324.9238-1-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>
---
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-05 6:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-05 6:43 [Qemu-devel] [PATCH v3 0/6] qio: general non-default GMainContext support Peter Xu
2018-03-05 6:43 ` [Qemu-devel] [PATCH v3 1/6] qio: rename qio_task_thread_result Peter Xu
2018-03-05 6:43 ` [Qemu-devel] [PATCH v3 2/6] qio: introduce qio_channel_add_watch_{full|source} Peter Xu
2018-03-05 6:43 ` Peter Xu [this message]
2018-03-05 6:43 ` [Qemu-devel] [PATCH v3 4/6] qio: non-default context for threaded qtask Peter Xu
2018-03-05 6:43 ` [Qemu-devel] [PATCH v3 5/6] qio: non-default context for async conn Peter Xu
2018-03-05 6:43 ` [Qemu-devel] [PATCH v3 6/6] qio: non-default context for TLS handshake Peter Xu
2018-03-06 10:29 ` [Qemu-devel] [PATCH v3 0/6] qio: general non-default GMainContext support Daniel P. Berrangé
2018-03-06 10:55 ` Peter Xu
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=20180305064324.9238-4-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.