From 5d41a4aa5a3324a2326142300da3b853bb14b070 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 29 Dec 2014 19:47:54 -0200 Subject: [PATCH] And move the sending of other types of D-Bus messages to the thread With this, we now know that all messages sent are sent from the same thread. This simplifies greatly the handling of the socket. Task-number: QTBUG-43585 Change-Id: Ic5d393bfd36e48a193fcffff13b73758087344ed Reviewed-by: Albert Astals Cid Reviewed-by: Alex Blasche --- src/dbus/qdbusconnection_p.h | 2 +- src/dbus/qdbusintegrator.cpp | 25 ++++++++++++++----------- src/dbus/qdbusthreaddebug_p.h | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index 3becc7cbc3..f653c427e7 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -272,7 +272,7 @@ private slots: signals: void dispatchStatusChanged(); - void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout); + void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout = -1); void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message); void newServerConnection(QDBusConnectionPrivate *newConnection); diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 77f27e6fb1..d5eaf39021 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -1874,13 +1874,9 @@ bool QDBusConnectionPrivate::send(const QDBusMessage& message) } q_dbus_message_set_no_reply(msg, true); // the reply would not be delivered to anything - qDBusDebug() << this << "sending message (no reply):" << message; - checkThread(); - QDBusDispatchLocker locker(SendMessageAction, this); - bool isOk = q_dbus_connection_send(connection, msg, 0); - q_dbus_message_unref(msg); - return isOk; + emit messageNeedsSending(Q_NULLPTR, msg); + return true; } // small helper to note long running blocking dbus calls. @@ -2089,10 +2085,15 @@ void QDBusConnectionPrivate::sendInternal(QDBusPendingCallPrivate *pcall, void * QDBusError error; DBusPendingCall *pending = 0; DBusMessage *msg = static_cast(message); - checkThread(); + bool isNoReply = !pcall; + Q_ASSERT(isNoReply == !!q_dbus_message_get_no_reply(msg)); - QDBusDispatchLocker locker(SendWithReplyAsyncAction, this); - if (q_dbus_connection_send_with_reply(connection, msg, &pending, timeout)) { + checkThread(); + QDBusDispatchLocker locker(SendMessageAction, this); + + if (isNoReply && q_dbus_connection_send(connection, msg, Q_NULLPTR)) { + // success + } else if (!isNoReply && q_dbus_connection_send_with_reply(connection, msg, &pending, timeout)) { if (pending) { q_dbus_message_unref(msg); @@ -2113,8 +2114,10 @@ void QDBusConnectionPrivate::sendInternal(QDBusPendingCallPrivate *pcall, void * } q_dbus_message_unref(msg); - pcall->replyMessage = QDBusMessage::createError(error); - processFinishedCall(pcall); + if (pcall) { + pcall->replyMessage = QDBusMessage::createError(error); + processFinishedCall(pcall); + } } bool QDBusConnectionPrivate::connectSignal(const QString &service, diff --git a/src/dbus/qdbusthreaddebug_p.h b/src/dbus/qdbusthreaddebug_p.h index 60b6acd38d..eace25478d 100644 --- a/src/dbus/qdbusthreaddebug_p.h +++ b/src/dbus/qdbusthreaddebug_p.h @@ -83,7 +83,7 @@ enum ThreadAction { HandleObjectCallPostEventAction = 22, HandleObjectCallSemaphoreAction = 23, DoDispatchAction = 24, - SendWithReplyAsyncAction = 25, + // unused: 25, MessageResultReceivedAction = 26, ActivateSignalAction = 27, PendingCallBlockAction = 28,