Make sure to handle pending messages at start up if a dbus service

is invoked by the dbus daemon.
Prior to this fix, when a service was started by the dbus daemon,
the first dbus call sent to it was being held back till the next
dbus call was performed, resulting in a long timeout for the first
unhandled call and a delayed answer.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/29/head
Michele Calgaro 2 years ago
parent d05b026328
commit 96f7e60908
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -401,8 +401,9 @@ bool TQT_DBusConnection::requestName(const TQString &name, int modeFlags)
dbusFlags |= DBUS_NAME_FLAG_REPLACE_EXISTING;
dbus_bus_request_name(d->connection, name.utf8(), dbusFlags, &d->error);
return !d->handleError();
bool res = !d->handleError();
res &= d->handleUnreadMessages();
return res;
}
#include "tqdbusconnection.moc"

@ -85,6 +85,7 @@ public:
bool handleSignal(DBusMessage *msg);
bool handleObjectCall(DBusMessage *message);
bool handleError();
bool handleUnreadMessages();
void emitPendingCallReply(const TQT_DBusMessage& message);

@ -82,9 +82,9 @@ static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data)
TQT_DBusConnectionPrivate *d = static_cast<TQT_DBusConnectionPrivate *>(data);
for (TQValueList<DBusTimeout*>::iterator it = d->pendingTimeouts.begin();
it != d->pendingTimeouts.end();) {
if ((*it) == timeout) {
it = d->pendingTimeouts.erase(it);
}
if ((*it) == timeout) {
it = d->pendingTimeouts.erase(it);
}
else
++it;
}
@ -339,6 +339,29 @@ bool TQT_DBusConnectionPrivate::handleError()
return lastError.isValid();
}
bool TQT_DBusConnectionPrivate::handleUnreadMessages()
{
bool res = true;
WatcherHash::iterator it = watchers.begin();
while (it != watchers.end())
{
WatcherList &list = *it;
WatcherList::iterator listIt = list.begin();
while (listIt != list.end())
{
Watcher watcher = *listIt;
if (watcher.read)
{
socketRead(watcher.read->socket());
res &= (!handleError());
}
++listIt;
}
++it;
}
return res;
}
void TQT_DBusConnectionPrivate::emitPendingCallReply(const TQT_DBusMessage& message)
{
emit dbusPendingCallReply(message);
@ -565,8 +588,6 @@ void TQT_DBusConnectionPrivate::setConnection(DBusConnection *dbc)
qDBusToggleWatch, this, 0);
dbus_connection_set_timeout_functions(connection, qDBusAddTimeout, qDBusRemoveTimeout,
qDBusToggleTimeout, this, 0);
// dbus_bus_add_match(connection, "type='signal',interface='com.trolltech.dbus.Signal'", &error);
// dbus_bus_add_match(connection, "type='signal'", &error);
dbus_bus_add_match(connection, "type='signal'", &error);
if (handleError()) {
@ -579,7 +600,7 @@ void TQT_DBusConnectionPrivate::setConnection(DBusConnection *dbc)
TQCString filter;
filter += "destination='";
filter += service;
filter += "\'";
filter += "'";
dbus_bus_add_match(connection, filter.data(), &error);
if (handleError()) {

Loading…
Cancel
Save