From 29560adcc79a259a0be3511c056ee7453aa26c04 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 13 Mar 2003 00:56:43 +0000 Subject: 2003-03-12 Havoc Pennington Mega-patch that gets the message bus daemon initially handling out-of-memory. Work still needed. Also lots of random moving stuff to DBusError instead of ResultCode. * dbus/dbus-list.c (_dbus_list_length_is_one): new function * dbus/dbus-connection.c (dbus_connection_send_with_reply_and_block): use DBusError * dbus/dbus-bus.c: adapt to API changes, make it use DBusError not DBusResultCode * dbus/dbus-connection.c (dbus_connection_send): drop the result code here, as the only failure possible is OOM. * bus/connection.c (bus_connection_disconnect): rename bus_connection_disconnected as it's a notification only * bus/driver.c (bus_driver_handle_acquire_service): don't free "name" on get_args failure, should be done by get_args; don't disconnect client for bad args, just return an error. (bus_driver_handle_service_exists): ditto * bus/services.c (bus_services_list): NULL-terminate returned array * bus/driver.c (bus_driver_send_service_lost) (bus_driver_send_service_acquired): send messages from driver to a specific client to the client's unique name, not to the broadcast service. * dbus/dbus-message.c (decode_header_data): reject messages that contain no name field (_dbus_message_get_client_serial): rename to dbus_message_get_serial and make public (_dbus_message_set_serial): rename from set_client_serial (_dbus_message_set_reply_serial): make public (_dbus_message_get_reply_serial): make public * bus/connection.c (bus_connection_foreach): allow stopping iteration by returning FALSE from foreach function. * dbus/dbus-connection.c (dbus_connection_send_preallocated) (dbus_connection_free_preallocated_send) (dbus_connection_preallocate_send): new API for sending a message without possibility of malloc failure. (dbus_connection_send_message): rename to just dbus_connection_send (and same for whole function family) * dbus/dbus-errors.c (dbus_error_free): make this reinit the error * dbus/dbus-sysdeps.c (_dbus_exit): new function * bus/activation.c: handle/return errors * dbus/dbus-errors.h: add more DBUS_ERROR #define * dbus/dbus-sysdeps.c (_dbus_directory_open) (_dbus_file_get_contents) (_dbus_directory_get_next_file): use DBusError instead of DBusResultCode (_dbus_result_from_errno): move to this file --- glib/test-dbus-glib.c | 20 ++++++++++++++------ glib/test-thread-client.c | 9 +++++---- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'glib') diff --git a/glib/test-dbus-glib.c b/glib/test-dbus-glib.c index fe9cd6b9..b5c44024 100644 --- a/glib/test-dbus-glib.c +++ b/glib/test-dbus-glib.c @@ -7,13 +7,13 @@ main (int argc, char **argv) { DBusConnection *connection; DBusResultCode result; - DBusMessage *message, *reply; - + DBusMessage *message, *reply; GMainLoop *loop; + DBusError error; if (argc < 2) { - fprintf (stderr, "Give the server address as an argument\n"); + g_printerr ("Give the server address as an argument\n"); return 1; } @@ -22,8 +22,8 @@ main (int argc, char **argv) connection = dbus_connection_open (argv[1], &result); if (connection == NULL) { - fprintf (stderr, "Failed to open connection to %s: %s\n", argv[1], - dbus_result_to_string (result)); + g_printerr ("Failed to open connection to %s: %s\n", argv[1], + dbus_result_to_string (result)); return 1; } @@ -31,7 +31,15 @@ main (int argc, char **argv) message = dbus_message_new ("org.freedesktop.DBus", "org.freedesktop.DBus.Hello"); - reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, &result); + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); + if (reply == NULL) + { + g_printerr ("Error on hello message: %s\n", error.message); + dbus_error_free (&error); + return 1; + } + g_print ("reply name: %s\n", dbus_message_get_name (reply)); g_main_loop_run (loop); diff --git a/glib/test-thread-client.c b/glib/test-thread-client.c index ca78dbb8..23ec3f33 100644 --- a/glib/test-thread-client.c +++ b/glib/test-thread-client.c @@ -37,12 +37,13 @@ thread_func (gpointer data) } g_free (str); - if (!dbus_connection_send_message (connection, - message, - NULL, NULL)) + if (!dbus_connection_send (connection, + message, + NULL)) { - g_print ("thread %d: send message failerd\n", threadnr); + g_print ("thread %d: send message failed\n", threadnr); } + dbus_message_unref (message); counter ++; -- cgit