Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2021-05-28 15:04:19 +0300
committerHannah von Reth <hannah.vonreth@owncloud.com>2021-05-28 15:04:19 +0300
commit6f7624d60d6472375a64bee897ec868237a243aa (patch)
treebc95327cb97c4a3efd932a6e420d8c4cd4b00c00 /src
parent2ef7cf39623f69be8f833ad1cb0126c81471a6fc (diff)
parent7c145e169ced19c8bbd09bbadeca457e64522f39 (diff)
Merge remote-tracking branch 'origin/2.8'
Diffstat (limited to 'src')
-rw-r--r--src/gui/socketapi/socketapi.cpp40
-rw-r--r--src/gui/socketapi/socketapi.h7
2 files changed, 17 insertions, 30 deletions
diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp
index ab641b492..5d0aca98a 100644
--- a/src/gui/socketapi/socketapi.cpp
+++ b/src/gui/socketapi/socketapi.cpp
@@ -297,15 +297,22 @@ void SocketApi::slotNewConnection()
{
// Note that on macOS this is not actually a line-based QIODevice, it's a SocketApiSocket which is our
// custom message based macOS IPC.
- QIODevice *socket = _localServer.nextPendingConnection();
+ SocketApiSocket *socket = _localServer.nextPendingConnection();
if (!socket) {
return;
}
qCInfo(lcSocketApi) << "New connection" << socket;
- connect(socket, &QIODevice::readyRead, this, &SocketApi::slotReadSocket);
- connect(socket, SIGNAL(disconnected()), this, SLOT(onLostConnection()));
- connect(socket, &QObject::destroyed, this, &SocketApi::slotSocketDestroyed);
+ connect(socket, &SocketApiSocket::readyRead, this, &SocketApi::slotReadSocket);
+ connect(socket, &SocketApiSocket::disconnected, this, [socket] {
+ qCInfo(lcSocketApi) << "Lost connection " << socket;
+ // will trigger destroyed in the next execution of the main loop
+ // a direct removal can cause issues when iterating on _listeners
+ socket->deleteLater();
+ });
+ connect(socket, &SocketApiSocket::destroyed, this, [socket, this] {
+ _listeners.remove(socket);
+ });
OC_ASSERT(socket->readAll().isEmpty());
auto listener = QSharedPointer<SocketListener>::create(socket);
@@ -318,25 +325,9 @@ void SocketApi::slotNewConnection()
}
}
-void SocketApi::onLostConnection()
-{
- qCInfo(lcSocketApi) << "Lost connection " << sender();
- sender()->deleteLater();
-
- auto socket = qobject_cast<QIODevice *>(sender());
- OC_ASSERT(socket);
- _listeners.remove(socket);
-}
-
-void SocketApi::slotSocketDestroyed(QObject *obj)
-{
- QIODevice *socket = static_cast<QIODevice *>(obj);
- _listeners.remove(socket);
-}
-
void SocketApi::slotReadSocket()
{
- QIODevice *socket = qobject_cast<QIODevice *>(sender());
+ SocketApiSocket *socket = qobject_cast<SocketApiSocket *>(sender());
OC_ENFORCE(socket);
// Find the SocketListener
@@ -419,7 +410,7 @@ void SocketApi::slotReadSocket()
OC_ASSERT(thread() == QThread::currentThread())
staticMetaObject.method(indexOfMethod)
.invoke(this, Qt::DirectConnection, Q_ARG(QString, argument.toString()),
- Q_ARG(SocketListener *, listener.data()));
+ Q_ARG(SocketListener*, listener.data()));
}
}
}
@@ -433,10 +424,7 @@ void SocketApi::slotRegisterPath(const QString &alias)
Folder *f = FolderMan::instance()->folder(alias);
if (f) {
- const QString message = buildRegisterPathMessage(removeTrailingSlash(f->path()));
- for (const auto &listener : qAsConst(_listeners)) {
- listener->sendMessage(message);
- }
+ broadcastMessage(buildRegisterPathMessage(removeTrailingSlash(f->path())));
}
_registeredAliases.insert(alias);
diff --git a/src/gui/socketapi/socketapi.h b/src/gui/socketapi/socketapi.h
index 61e915468..84229b1dd 100644
--- a/src/gui/socketapi/socketapi.h
+++ b/src/gui/socketapi/socketapi.h
@@ -26,7 +26,8 @@
#include "socketapisocket_mac.h"
#else
#include <QLocalServer>
-typedef QLocalServer SocketApiServer;
+using SocketApiServer = QLocalServer;
+using SocketApiSocket = QLocalSocket;
#endif
class QUrl;
@@ -66,8 +67,6 @@ signals:
private slots:
void slotNewConnection();
- void onLostConnection();
- void slotSocketDestroyed(QObject *obj);
void slotReadSocket();
static void copyUrlToClipboard(const QString &link);
@@ -164,7 +163,7 @@ private:
QString buildRegisterPathMessage(const QString &path);
QSet<QString> _registeredAliases;
- QMap<QIODevice *, QSharedPointer<SocketListener>> _listeners;
+ QMap<SocketApiSocket *, QSharedPointer<SocketListener>> _listeners;
SocketApiServer _localServer;
};
}