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

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