[glib] GDBusServer: Make ::new-connection return whether the connection was claimed
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GDBusServer: Make ::new-connection return whether the connection was claimed
- Date: Thu, 9 Sep 2010 18:03:50 +0000 (UTC)
commit ee945d8f621609086a8777ca4226cb93308c12e4
Author: David Zeuthen <davidz redhat com>
Date: Thu Sep 9 14:00:46 2010 -0400
GDBusServer: Make ::new-connection return whether the connection was claimed
Otherwise things probably won't work in a garbage-collected world
(consider the trivial GC that never collects garbage).
This commit breaks GDBusServer ABI. No known released software is
using this code.
Signed-off-by: David Zeuthen <davidz redhat com>
gio/gdbusserver.c | 34 ++++++++++++++++++++++------------
gio/gio-marshal.list | 1 +
gio/tests/gdbus-example-peer.c | 4 +++-
gio/tests/gdbus-peer.c | 12 +++++++++---
4 files changed, 35 insertions(+), 16 deletions(-)
---
diff --git a/gio/gdbusserver.c b/gio/gdbusserver.c
index d957d22..299aca3 100644
--- a/gio/gdbusserver.c
+++ b/gio/gdbusserver.c
@@ -122,8 +122,8 @@ struct _GDBusServerClass
/*< public >*/
/* Signals */
- void (*new_connection) (GDBusServer *server,
- GDBusConnection *connection);
+ gboolean (*new_connection) (GDBusServer *server,
+ GDBusConnection *connection);
};
enum
@@ -391,10 +391,12 @@ g_dbus_server_class_init (GDBusServerClass *klass)
* g_dbus_connection_get_peer_credentials() to figure out what
* identity (if any), was authenticated.
*
- * If you want to accept the connection, simply ref the @connection
- * object. Then call g_dbus_connection_close() and unref it when you
- * are done with it. A typical thing to do when accepting a
- * connection is to listen to the #GDBusConnection::closed signal.
+ * If you want to accept the connection, take a reference to the
+ * @connection object and return %TRUE. When you are done with the
+ * connection call g_dbus_connection_close() and give up your
+ * reference. Note that the other peer may disconnect at any time -
+ * a typical thing to do when accepting a connection is to listen to
+ * the #GDBusConnection::closed signal.
*
* If #GDBusServer:flags contains %G_DBUS_SERVER_FLAGS_RUN_IN_THREAD
* then the signal is emitted in a new thread dedicated to the
@@ -407,16 +409,19 @@ g_dbus_server_class_init (GDBusServerClass *klass)
* that it's suitable to call g_dbus_connection_register_object() or
* similar from the signal handler.
*
+ * Returns: %TRUE to claim @connection, %FALSE to let other handlers
+ * run.
+ *
* Since: 2.26
*/
_signals[NEW_CONNECTION_SIGNAL] = g_signal_new ("new-connection",
G_TYPE_DBUS_SERVER,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GDBusServerClass, new_connection),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
+ g_signal_accumulator_true_handled,
+ NULL, /* accu_data */
+ _gio_marshal_BOOLEAN__OBJECT,
+ G_TYPE_BOOLEAN,
1,
G_TYPE_DBUS_CONNECTION);
}
@@ -922,12 +927,17 @@ static gboolean
emit_new_connection_in_idle (gpointer user_data)
{
EmitIdleData *data = user_data;
+ gboolean claimed;
+ claimed = FALSE;
g_signal_emit (data->server,
_signals[NEW_CONNECTION_SIGNAL],
0,
- data->connection);
- g_dbus_connection_start_message_processing (data->connection);
+ data->connection,
+ &claimed);
+
+ if (claimed)
+ g_dbus_connection_start_message_processing (data->connection);
g_object_unref (data->connection);
return FALSE;
diff --git a/gio/gio-marshal.list b/gio/gio-marshal.list
index b1c519a..e85aefc 100644
--- a/gio/gio-marshal.list
+++ b/gio/gio-marshal.list
@@ -21,3 +21,4 @@ VOID:STRING,STRING,VARIANT
VOID:STRING
VOID:STRING,STRING
VOID:STRING,BOOLEAN
+BOOL:OBJECT
diff --git a/gio/tests/gdbus-example-peer.c b/gio/tests/gdbus-example-peer.c
index 7df1942..cb54a13 100644
--- a/gio/tests/gdbus-example-peer.c
+++ b/gio/tests/gdbus-example-peer.c
@@ -121,7 +121,7 @@ static const GDBusInterfaceVTable interface_vtable =
/* ---------------------------------------------------------------------------------------------------- */
-static void
+static gboolean
on_new_connection (GDBusServer *server,
GDBusConnection *connection,
gpointer user_data)
@@ -152,6 +152,8 @@ on_new_connection (GDBusServer *server,
NULL, /* user_data_free_func */
NULL); /* GError** */
g_assert (registration_id > 0);
+
+ return TRUE;
}
/* ---------------------------------------------------------------------------------------------------- */
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index 1387744..4a6cbc8 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -283,7 +283,7 @@ on_authorize_authenticated_peer (GDBusAuthObserver *observer,
}
/* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
-static void
+static gboolean
on_new_connection (GDBusServer *server,
GDBusConnection *connection,
gpointer user_data)
@@ -311,6 +311,8 @@ on_new_connection (GDBusServer *server,
g_assert (reg_id > 0);
g_main_loop_quit (loop);
+
+ return TRUE;
}
static gpointer
@@ -943,7 +945,7 @@ static const GDBusInterfaceVTable dmp_interface_vtable =
/* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
-static void
+static gboolean
dmp_on_new_connection (GDBusServer *server,
GDBusConnection *connection,
gpointer user_data)
@@ -984,6 +986,8 @@ dmp_on_new_connection (GDBusServer *server,
NULL,
&error);
g_dbus_node_info_unref (node);
+
+ return TRUE;
}
static gpointer
@@ -1101,7 +1105,7 @@ nonce_tcp_on_authorize_authenticated_peer (GDBusAuthObserver *observer,
}
/* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
-static void
+static gboolean
nonce_tcp_on_new_connection (GDBusServer *server,
GDBusConnection *connection,
gpointer user_data)
@@ -1111,6 +1115,8 @@ nonce_tcp_on_new_connection (GDBusServer *server,
g_ptr_array_add (data->current_connections, g_object_ref (connection));
g_main_loop_quit (loop);
+
+ return TRUE;
}
static gpointer
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]