#include <stdio.h>
#include <stdarg.h>
+#include <sys/time.h>
#include <glib.h>
#include "config.h"
dbus_pending_call_unref (pending);
}
+static gint
+time_elapsed (struct timeval *origin)
+{
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ return (tv.tv_sec - origin->tv_sec) * 1000 + (tv.tv_usec - origin->tv_usec) / 1000;
+}
+
DBusMessage *
dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
{
SpiReentrantCallClosure closure;
const char *unique_name = dbus_bus_get_unique_name (bus);
const char *destination = dbus_message_get_destination (message);
+ struct timeval tv;
if (unique_name && destination &&
strcmp (destination, unique_name) != 0)
dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
closure.reply = NULL;
+ gettimeofday (&tv, NULL);
while (!closure.reply)
{
if (!dbus_connection_read_write_dispatch (bus, dbind_timeout))
return NULL;
+if (time_elapsed (&tv) > dbind_timeout)
+ return NULL;
}
return closure.reply;