Commit 2728f8d8 authored by Abdel-Rahman Abdel-Rahman's avatar Abdel-Rahman Abdel-Rahman Committed by Albert Vaca Cintora
Browse files

Close all sockets before suspension

parent dc8a2cf5
Pipeline #18495 failed with stage
in 5 minutes and 3 seconds
......@@ -36,6 +36,7 @@ Server::Server(QObject * parent)
void Server::incomingConnection(qintptr socketDescriptor) {
QSslSocket* serverSocket = new QSslSocket(parent());
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
QObject::connect(this, &Server::closed, serverSocket, &QSslSocket::abort);
addPendingConnection(serverSocket);
} else {
qWarning() << "setSocketDescriptor failed" << serverSocket->errorString();
......@@ -51,3 +52,9 @@ void Server::errorFound(QAbstractSocket::SocketError socketError)
{
qDebug() << "error:" << socketError;
}
void Server::close()
{
QTcpServer::close();
Q_EMIT closed();
}
......@@ -37,6 +37,10 @@ public:
~Server() override = default;
QSslSocket* nextPendingConnection() override;
void close();
Q_SIGNALS:
void closed();
protected:
void incomingConnection(qintptr socketDescriptor) override;
......
......@@ -19,9 +19,31 @@
*/
#include "linkprovider.h"
#include <QDBusConnection>
#include <core_debug.h>
LinkProvider::LinkProvider()
{
//gcc complains if we don't add something to compile on a class with virtual functions
// Terminate connections when we sleep or shut down.
QDBusConnection::systemBus().connect(QStringLiteral("org.freedesktop.login1"),
QStringLiteral("/org/freedesktop/login1"),
QStringLiteral("org.freedesktop.login1.Manager"),
QStringLiteral("PrepareForSleep"),
this, SLOT(suspend(bool)));
QDBusConnection::systemBus().connect(QStringLiteral("org.freedesktop.login1"),
QStringLiteral("/org/freedesktop/login1"),
QStringLiteral("org.freedesktop.login1.Manager"),
QStringLiteral("PrepareForShutdown"),
this, SLOT(suspend(bool)));
}
void LinkProvider::suspend(bool suspend)
{
if (suspend) {
qCDebug(KDECONNECT_CORE) << "Stopping connection for suspension";
onStop();
} else {
qCDebug(KDECONNECT_CORE) << "Restarting connection after suspension";
onStart();
}
}
......@@ -50,6 +50,8 @@ public Q_SLOTS:
virtual void onStop() = 0;
virtual void onNetworkChange() = 0;
void suspend(bool suspend);
Q_SIGNALS:
//NOTE: The provider will destroy the DeviceLink when it's no longer accessible,
// and every user should listen to the destroyed signal to remove its references.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment