[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:29:16 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=e2f068b

The following commit has been merged in the master branch:
commit e2f068b2869b0a94be1bd87b714731e86dff90e5
Author: Albert Vaca <albertvaka at gmail.com>
Date:   Sun Oct 18 21:48:39 2015 -0700

    Fixed a memory leak making the DownloadJob destroy itself on disconnect
    
    There are still some code paths where it doesn't get destroyed though,
    like when the device gets unreachable (and the download socket doesn't
    close for some reason).
---
 core/backends/lan/downloadjob.cpp |  34 +++++++++---
 core/backends/lan/downloadjob.h   |   6 +--
 core/core_debug.h                 |   4 +-
 tests/CMakeLists.txt              |   1 +
 tests/downloadjobtest.cpp         | 107 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 141 insertions(+), 11 deletions(-)

diff --git a/core/backends/lan/downloadjob.cpp b/core/backends/lan/downloadjob.cpp
index bba2e98..abbedf1 100644
--- a/core/backends/lan/downloadjob.cpp
+++ b/core/backends/lan/downloadjob.cpp
@@ -20,30 +20,50 @@
 
 #include "downloadjob.h"
 
+#include <core/core_debug.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <netdb.h>
+
+#include "lanlinkprovider.h"
+
 DownloadJob::DownloadJob(QHostAddress address, QVariantMap transferInfo): KJob()
 {
     mAddress = address;
     mPort = transferInfo["port"].toInt();
-    mSocket = QSharedPointer<QTcpSocket>(new QTcpSocket);
+    mSocket = QSharedPointer<QTcpSocket>(new QTcpSocket());
+}
+
+DownloadJob::~DownloadJob()
+{
 }
 
 void DownloadJob::start()
 {
-    //kDebug(kdeconnect_kded()) << "DownloadJob Start";
+    //TODO: Timeout?
+    connect(mSocket.data(), &QAbstractSocket::disconnected, this, &DownloadJob::done);
+    connect(mSocket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(done()));
+    //connect(mSocket.data(), &QAbstractSocket::connected, [=](){ qDebug() << "Connected"; });
+
     mSocket->connectToHost(mAddress, mPort, QIODevice::ReadOnly);
-    connect(mSocket.data(), SIGNAL(disconnected()),
-            this, SLOT(disconnected()));
+
+    //mSocket->open(QIODevice::ReadOnly);
+
     //TODO: Implement payload encryption somehow (create an intermediate iodevice to encrypt the payload here?)
 }
 
-void DownloadJob::disconnected()
+void DownloadJob::done()
 {
-    //kDebug(kdeconnect_kded()) << "DownloadJob End";
+    if (mSocket->error()) {
+        qWarning(KDECONNECT_CORE) << mSocket->errorString();
+    }
     emitResult();
+    deleteLater();
 }
 
 QSharedPointer<QIODevice> DownloadJob::getPayload()
 {
-    //kDebug(kdeconnect_kded()) << "getPayload";
     return mSocket.staticCast<QIODevice>();
 }
diff --git a/core/backends/lan/downloadjob.h b/core/backends/lan/downloadjob.h
index 544e33c..e3d3a7d 100644
--- a/core/backends/lan/downloadjob.h
+++ b/core/backends/lan/downloadjob.h
@@ -35,7 +35,8 @@ class DownloadJob
     Q_OBJECT
 public:
     DownloadJob(QHostAddress address, QVariantMap transferInfo);
-    virtual void start() override;
+    ~DownloadJob();
+    void start() Q_DECL_OVERRIDE;
     QSharedPointer<QIODevice> getPayload();
 
 private:
@@ -43,9 +44,8 @@ private:
     qint16 mPort;
     QSharedPointer<QTcpSocket> mSocket;
 
-
 private Q_SLOTS:
-    void disconnected();
+    void done();
 
 };
 
diff --git a/core/core_debug.h b/core/core_debug.h
index 93a0f1d..d74745c 100644
--- a/core/core_debug.h
+++ b/core/core_debug.h
@@ -23,6 +23,8 @@
 
 #include <QLoggingCategory>
 
-Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_CORE)
+#include "kdeconnectcore_export.h"
+
+KDECONNECTCORE_EXPORT Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_CORE)
 
 #endif //CORE_DEBUG_H
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 727f395..4be7945 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -16,3 +16,4 @@ set(kdeconnect_libraries
 
 ecm_add_test(networkpackagetests.cpp LINK_LIBRARIES ${kdeconnect_libraries})
 ecm_add_test(testsocketlinereader.cpp ../core/backends/lan/socketlinereader.cpp TEST_NAME testsocketlinereader LINK_LIBRARIES ${kdeconnect_libraries})
+ecm_add_test(downloadjobtest.cpp ../core/backends/lan/downloadjob.cpp TEST_NAME downloadjobtest LINK_LIBRARIES ${kdeconnect_libraries})
diff --git a/tests/downloadjobtest.cpp b/tests/downloadjobtest.cpp
new file mode 100644
index 0000000..efaea3d
--- /dev/null
+++ b/tests/downloadjobtest.cpp
@@ -0,0 +1,107 @@
+/*************************************************************************************
+ *  Copyright (C) 2014 by Albert Vaca Cintora <albertvaka at gmail.com>                 *
+ *                                                                                   *
+ *  This library is free software; you can redistribute it and/or                    *
+ *  modify it under the terms of the GNU Lesser General Public                       *
+ *  License as published by the Free Software Foundation; either                     *
+ *  version 2.1 of the License, or (at your option) any later version.               *
+ *                                                                                   *
+ *  This library is distributed in the hope that it will be useful,                  *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                *
+ *  Lesser General Public License for more details.                                  *
+ *                                                                                   *
+ *  You should have received a copy of the GNU Lesser General Public                 *
+ *  License along with this library; if not, write to the Free Software              *
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA       *
+ *************************************************************************************/
+
+#include "../core/backends/lan/downloadjob.h"
+
+#include <QTest>
+#include <QTcpServer>
+#include <QTcpSocket>
+#include <QProcess>
+#include <QEventLoop>
+#include <QTimer>
+#include <QHostAddress>
+#include <KJob>
+#include <unistd.h>
+#include <iostream>
+
+class DownloadJobTest : public QObject
+{
+    Q_OBJECT
+
+private Q_SLOTS:
+    void failToConnectShouldDestroyTheJob();
+    void closingTheConnectionShouldDestroyTheJob();
+private:
+
+    void initServer();
+    void initDownloadJob();
+    void awaitToBeDestroyedOrTimeOut();
+    void stopServer();
+
+    QTimer mTimer;
+    QEventLoop mLoop;
+    DownloadJob* test;
+    QTcpServer *mServer;
+};
+
+void DownloadJobTest::initServer()
+{
+    mServer = new QTcpServer(this);
+    QVERIFY2(mServer->listen(QHostAddress::LocalHost, 8694), "Failed to create local tcp server");
+}
+
+void DownloadJobTest::stopServer()
+{
+    mServer->close();
+}
+
+void DownloadJobTest::initDownloadJob()
+{
+    QVariantMap transferInfo;
+    transferInfo["port"]= 8694;
+    test = new DownloadJob(QHostAddress::LocalHost, transferInfo);
+    test->start();
+}
+
+void DownloadJobTest::awaitToBeDestroyedOrTimeOut()
+{
+    //Either the job is destroyed
+    connect(test, &QObject::destroyed, &mLoop, &QEventLoop::quit);
+
+    //Or we time out
+    mTimer.setInterval(2000);
+    mTimer.setSingleShot(true);
+    connect(&mTimer, &QTimer::timeout, [this]() {
+        mLoop.quit();
+        QFAIL("Test timed out");
+    });
+    mTimer.start();
+
+    //We wait
+    mLoop.exec();
+
+    mTimer.stop();
+}
+
+void DownloadJobTest::failToConnectShouldDestroyTheJob()
+{
+    initDownloadJob();
+    awaitToBeDestroyedOrTimeOut();
+}
+
+void DownloadJobTest::closingTheConnectionShouldDestroyTheJob()
+{
+    initServer();
+    initDownloadJob();
+    stopServer();
+    awaitToBeDestroyedOrTimeOut();
+}
+
+QTEST_GUILESS_MAIN(DownloadJobTest)
+
+#include "downloadjobtest.moc"

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list