Репозиторий Sisyphus
Последнее обновление: 27 ноября 2021 | Пакетов: 17423 | Посещений: 22404674
en ru br
Репозитории ALT

Группа :: Коммуникации
Пакет: kde5-connect

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: 721ba9faafb79aac73973410ee1dd3624ded97a5.diff
Скачать


diff --git a/core/backends/lan/socketlinereader.cpp b/core/backends/lan/socketlinereader.cpp
index f67fdf3fa397e417028fc624c1ef6655cf192709..da77052ab390e988c2eb070f8fe7a25a6d077edc 100644
--- a/core/backends/lan/socketlinereader.cpp
+++ b/core/backends/lan/socketlinereader.cpp
@@ -38,14 +38,6 @@ void SocketLineReader::dataReceived()
         }
     }
 
-    //If we still have things to read from the socket, call dataReceived again
-    //We do this manually because we do not trust readyRead to be emitted again
-    //So we call this method again just in case.
-    if (m_socket->bytesAvailable() > 0) {
-        QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection);
-        return;
-    }
-
     //If we have any packets, tell it to the world.
     if (!m_packets.isEmpty()) {
         Q_EMIT readyRead();
diff --git a/tests/testsocketlinereader.cpp b/tests/testsocketlinereader.cpp
index 755845569eedfebf159894b35f22f74a5f1f235b..b6425b034ce16fb455d3c7386e3feca37a399a4f 100644
--- a/tests/testsocketlinereader.cpp
+++ b/tests/testsocketlinereader.cpp
@@ -25,16 +25,19 @@
 #include <QProcess>
 #include <QEventLoop>
 #include <QTimer>
+#include <QSignalSpy>
 
 class TestSocketLineReader : public QObject
 {
     Q_OBJECT
 public Q_SLOTS:
-    void initTestCase();
+    void init();
+    void cleanup() { delete m_server; }
     void newPacket();
 
 private Q_SLOTS:
     void socketLineReader();
+    void badData();
 
 private:
     QTimer m_timer;
@@ -45,8 +48,9 @@ private:
     SocketLineReader* m_reader;
 };
 
-void TestSocketLineReader::initTestCase()
+void TestSocketLineReader::init()
 {
+    m_packets.clear();
     m_server = new Server(this);
 
     QVERIFY2(m_server->listen(QHostAddress::LocalHost, 8694), "Failed to create local tcp server");
@@ -97,6 +101,29 @@ void TestSocketLineReader::socketLineReader()
     }
 }
 
+void TestSocketLineReader::badData()
+{
+    const QList<QByteArray> dataToSend = { "data1\n", "data" }; //does not end in a \n
+    for (const QByteArray& line : qAsConst(dataToSend)) {
+        m_conn->write(line);
+    }
+    m_conn->flush();
+
+    QSignalSpy spy(m_server, &QTcpServer::newConnection);
+    QVERIFY(m_server->hasPendingConnections() || spy.wait(1000));
+    QSslSocket* sock = m_server->nextPendingConnection();
+
+    QVERIFY2(sock != nullptr, "Could not open a connection to the client");
+
+    m_reader = new SocketLineReader(sock, this);
+    connect(m_reader, &SocketLineReader::readyRead, this, &TestSocketLineReader::newPacket);
+    m_timer.start();
+    m_loop.exec();
+
+    QCOMPARE(m_packets.count(), 1);
+    QCOMPARE(m_packets[0], dataToSend[0]);
+}
+
 void TestSocketLineReader::newPacket()
 {
     if (!m_reader->bytesAvailable()) {
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin