kdeconnect-kde/core/backends/lan/socketlinereader.cpp

32 lines
862 B
C++
Raw Permalink Normal View History

/**
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
* SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "socketlinereader.h"
2015-07-05 14:23:53 +01:00
SocketLineReader::SocketLineReader(QSslSocket* socket, QObject* parent)
: QObject(parent)
, m_socket(socket)
{
connect(m_socket, &QIODevice::readyRead,
2016-11-26 14:12:38 +00:00
this, &SocketLineReader::dataReceived);
}
void SocketLineReader::dataReceived()
{
while (m_socket->canReadLine()) {
const QByteArray line = m_socket->readLine();
2015-10-19 05:49:29 +01:00
if (line.length() > 1) { //we don't want a single \n
m_packets.enqueue(line);
}
}
//If we have any packets, tell it to the world.
if (!m_packets.isEmpty()) {
Q_EMIT readyRead();
}
}