summaryrefslogtreecommitdiffstats
path: root/bus
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-15 02:19:02 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-15 02:19:02 +0000
commit4c95a9782c65f88e2904c44abeb734a1b00f6353 (patch)
treed81b0c3a3497a031cb642dc5126750a36a6651ff /bus
parentf468907fb09e8198c4cce7e8f2ddeae8b5476b9e (diff)
2003-03-14 Havoc Pennington <hp@redhat.com>
* dbus/dbus-memory.c: add a "detect buffer overwrites on free" cheesy hack * dbus/dbus-transport-debug.c: rework this a good bit to be less complicated. hopefully still works. * dbus/dbus-server-debug.c (handle_new_client): remove timeout manually * glib/dbus-gmain.c (timeout_handler): don't remove timeout after running it * dbus/dbus-message.c (dbus_message_copy): rename from dbus_message_new_from_message, fix it up to copy all the message fields, add test case * bus/dispatch.c (bus_dispatch_test): add some more test code, not quite passing yet
Diffstat (limited to 'bus')
-rw-r--r--bus/bus.c5
-rw-r--r--bus/connection.c11
-rw-r--r--bus/dispatch.c45
-rw-r--r--bus/loop.c29
-rw-r--r--bus/test-main.c6
5 files changed, 76 insertions, 20 deletions
diff --git a/bus/bus.c b/bus/bus.c
index e376ae4d..b717cacc 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -46,7 +46,7 @@ server_watch_callback (DBusWatch *watch,
{
BusContext *context = data;
- dbus_server_handle_watch (context->server, watch, condition);
+ dbus_server_handle_watch (context->server, watch, condition);
}
static dbus_bool_t
@@ -64,6 +64,7 @@ remove_server_watch (DBusWatch *watch,
bus_loop_remove_watch (watch, server_watch_callback, context);
}
+
static void
server_timeout_callback (DBusTimeout *timeout,
void *data)
@@ -95,7 +96,7 @@ new_connection_callback (DBusServer *server,
if (!bus_connections_setup_connection (context->connections, new_connection))
_dbus_verbose ("No memory to setup new connection\n");
- /* on OOM, we won't have ref'd the connection so it will die */
+ /* on OOM, we won't have ref'd the connection so it will die. */
}
BusContext*
diff --git a/bus/connection.c b/bus/connection.c
index f0463392..700ca46d 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -143,7 +143,8 @@ connection_watch_callback (DBusWatch *watch,
dbus_connection_handle_watch (connection, watch, condition);
- while (dbus_connection_dispatch_message (connection));
+ while (dbus_connection_dispatch_message (connection))
+ ;
dbus_connection_unref (connection);
}
@@ -166,7 +167,15 @@ static void
connection_timeout_callback (DBusTimeout *timeout,
void *data)
{
+ DBusConnection *connection = data;
+
+ dbus_connection_ref (connection);
+
dbus_timeout_handle (timeout);
+
+ while (dbus_connection_dispatch_message (connection))
+ ;
+ dbus_connection_unref (connection);
}
static dbus_bool_t
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 04d68ecc..928e4387 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -28,6 +28,7 @@
#include "utils.h"
#include "bus.h"
#include "test.h"
+#include "loop.h"
#include <dbus/dbus-internals.h>
#include <string.h>
@@ -172,12 +173,15 @@ bus_dispatch (DBusConnection *connection,
_dbus_assert (message_name != NULL); /* DBusMessageLoader is supposed to check this */
+ _dbus_verbose ("DISPATCH: %s to %s\n",
+ message_name, service_name ? service_name : "peer");
+
/* If service_name is NULL, this is a message to the bus daemon, not intended
* to actually go "on the bus"; e.g. a peer-to-peer ping. Handle these
* immediately, especially disconnection messages.
*/
if (service_name == NULL)
- {
+ {
if (strcmp (message_name, DBUS_MESSAGE_LOCAL_DISCONNECT) == 0)
bus_connection_disconnected (connection);
@@ -374,12 +378,15 @@ bus_dispatch_remove_connection (DBusConnection *connection)
#ifdef DBUS_BUILD_TESTS
static void
-run_test_bus (BusContext *context)
+flush_bus (BusContext *context)
{
-
-
+ while (bus_loop_iterate (FALSE))
+ ;
}
+/* returns TRUE if the correct thing happens,
+ * but the correct thing may include OOM errors.
+ */
static dbus_bool_t
check_hello_message (BusContext *context,
DBusConnection *connection)
@@ -391,11 +398,28 @@ check_hello_message (BusContext *context,
DBUS_MESSAGE_HELLO);
if (message == NULL)
- _dbus_assert_not_reached ("no memory");
+ return TRUE;
if (!dbus_connection_send (connection, message, &serial))
- _dbus_assert_not_reached ("no memory");
+ return TRUE;
+
+ dbus_message_unref (message);
+
+ flush_bus (context);
+ message = dbus_connection_pop_message (connection);
+ if (message == NULL)
+ {
+ _dbus_warn ("Did not receive a reply to %s %d on %p\n",
+ DBUS_MESSAGE_HELLO, serial, connection);
+ return FALSE;
+ }
+
+ _dbus_verbose ("Received %s on %p\n",
+ dbus_message_get_name (message), connection);
+
+ dbus_message_unref (message);
+
return TRUE;
}
@@ -410,8 +434,6 @@ bus_dispatch_test (const DBusString *test_data_dir)
DBusConnection *baz;
DBusResultCode result;
- return TRUE; /* FIXME */
-
dbus_error_init (&error);
context = bus_context_new ("debug:name=test-server",
activation_dirs,
@@ -431,7 +453,12 @@ bus_dispatch_test (const DBusString *test_data_dir)
if (baz == NULL)
_dbus_assert_not_reached ("could not alloc connection");
-
+ if (!check_hello_message (context, foo))
+ _dbus_assert_not_reached ("hello message failed");
+ if (!check_hello_message (context, bar))
+ _dbus_assert_not_reached ("hello message failed");
+ if (!check_hello_message (context, baz))
+ _dbus_assert_not_reached ("hello message failed");
return TRUE;
}
diff --git a/bus/loop.c b/bus/loop.c
index 72bf99e4..10614745 100644
--- a/bus/loop.c
+++ b/bus/loop.c
@@ -262,8 +262,8 @@ bus_loop_remove_timeout (DBusTimeout *timeout,
timeout, function, data);
}
-/* Returns TRUE if we dispatch any callbacks, which is just used in
- * test code as a debug hack
+/* Returns TRUE if we have any timeouts or ready file descriptors,
+ * which is just used in test code as a debug hack
*/
dbus_bool_t
@@ -283,7 +283,12 @@ bus_loop_iterate (dbus_bool_t block)
fds = NULL;
watches_for_fds = NULL;
-
+
+#if 0
+ _dbus_verbose (" iterate %d timeouts %d watches\n",
+ timeout_count, watch_count);
+#endif
+
if (callbacks == NULL)
{
bus_loop_quit ();
@@ -343,7 +348,9 @@ bus_loop_iterate (dbus_bool_t block)
{
unsigned long tv_sec;
unsigned long tv_usec;
-
+
+ retval = TRUE;
+
_dbus_get_current_time (&tv_sec, &tv_usec);
link = _dbus_list_get_first_link (&callbacks);
@@ -445,16 +452,23 @@ bus_loop_iterate (dbus_bool_t block)
(tv_sec - tcb->last_tv_sec) * 1000 +
(tv_usec - tcb->last_tv_usec) / 1000;
+#if 0
+ _dbus_verbose (" interval = %lu elapsed = %lu\n",
+ interval, elapsed);
+#endif
+
if (interval <= elapsed)
{
/* Save last callback time and fire this timeout */
tcb->last_tv_sec = tv_sec;
tcb->last_tv_usec = tv_usec;
-
+
+#if 0
+ _dbus_verbose (" invoking timeout\n");
+#endif
+
(* tcb->function) (tcb->timeout,
cb->data);
-
- retval = TRUE;
}
}
@@ -504,6 +518,7 @@ bus_loop_iterate (dbus_bool_t block)
(* wcb->function) (wcb->watch,
condition,
((Callback*)wcb)->data);
+
retval = TRUE;
}
}
diff --git a/bus/test-main.c b/bus/test-main.c
index 503d996d..26e9110d 100644
--- a/bus/test-main.c
+++ b/bus/test-main.c
@@ -53,10 +53,14 @@ main (int argc, char **argv)
if (!bus_dispatch_test (&test_data_dir))
die ("dispatch");
+
+ printf ("Success\n");
return 0;
#else /* DBUS_BUILD_TESTS */
-
+
+ printf ("Not compiled with test support\n");
+
return 0;
#endif
}