Commit d4cf4890 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

SocketLineReader: don't call packets bytes

parent ba3c5151
Pipeline #34432 failed with stage
in 31 minutes and 56 seconds
......@@ -100,7 +100,7 @@ bool LanDeviceLink::sendPacket(NetworkPacket& np)
void LanDeviceLink::dataReceived()
{
if (m_socketLineReader->bytesAvailable() == 0) return;
if (!m_socketLineReader->hasPacketsAvailable()) return;
const QByteArray serializedPacket = m_socketLineReader->readLine();
NetworkPacket packet((QString()));
......@@ -134,7 +134,7 @@ void LanDeviceLink::dataReceived()
Q_EMIT receivedPacket(packet);
if (m_socketLineReader->bytesAvailable() > 0) {
if (m_socketLineReader->hasPacketsAvailable()) {
QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection);
}
......
......@@ -26,14 +26,14 @@ class KDECONNECTCORE_EXPORT SocketLineReader
public:
explicit SocketLineReader(QSslSocket* socket, QObject* parent = nullptr);
bool hasPacketsAvailable() const { return !m_packets.isEmpty(); }
QByteArray readLine() { return m_packets.dequeue(); }
qint64 write(const QByteArray& data) { return m_socket->write(data); }
QHostAddress peerAddress() const { return m_socket->peerAddress(); }
QSslCertificate peerCertificate() const { return m_socket->peerCertificate(); }
qint64 bytesAvailable() const { return m_packets.size(); }
QSslSocket* m_socket;
Q_SIGNALS:
void readyRead();
......
......@@ -87,12 +87,8 @@ void TestSocketLineReader::socketLineReader()
void TestSocketLineReader::newPacket()
{
if (!m_reader->bytesAvailable()) {
return;
}
int maxLoops = 5;
while(m_reader->bytesAvailable() > 0 && maxLoops > 0) {
while(m_reader->hasPacketsAvailable() && maxLoops > 0) {
--maxLoops;
const QByteArray packet = m_reader->readLine();
if (!packet.isEmpty()) {
......
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