Skip to content

Commit

Permalink
SocketLineReader: don't call packets bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
aleixpol committed Sep 16, 2020
1 parent ba3c515 commit d4cf489
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/backends/lan/landevicelink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions core/backends/lan/socketlinereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 1 addition & 5 deletions tests/testsocketlinereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit d4cf489

Please sign in to comment.