SocketLineReader: don't call packets bytes

This commit is contained in:
Aleix Pol 2020-09-16 02:16:06 +02:00
parent ba3c515148
commit d4cf48901c
3 changed files with 5 additions and 9 deletions

View file

@ -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);
}

View file

@ -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();

View file

@ -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()) {