From abc5fa3c56c5f45d5ba13d6ed577ce10870d7141 Mon Sep 17 00:00:00 2001 From: David Kahles Date: Wed, 27 Apr 2016 20:38:23 +0200 Subject: [PATCH] Remove second UDP socket in LanLinkProvider We don't need two sockets for reading and writing. REVIEW: 127769 --- core/backends/lan/lanlinkprovider.cpp | 13 ++++++------- core/backends/lan/lanlinkprovider.h | 1 - 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index 128a90b4f..dcba29f9d 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -48,8 +48,7 @@ LanLinkProvider::LanLinkProvider(bool testMode) { mTcpPort = 0; - mUdpServer = new QUdpSocket(this); - connect(mUdpServer, SIGNAL(readyRead()), this, SLOT(newUdpConnection())); + connect(&mUdpSocket, SIGNAL(readyRead()), this, SLOT(newUdpConnection())); mServer = new Server(this); connect(mServer,SIGNAL(newConnection()),this, SLOT(newConnection())); @@ -75,7 +74,7 @@ void LanLinkProvider::onStart() { const QHostAddress bindAddress = mTestMode? QHostAddress::LocalHost : QHostAddress::Any; - bool success = mUdpServer->bind(bindAddress, port, QUdpSocket::ShareAddress); + bool success = mUdpSocket.bind(bindAddress, port, QUdpSocket::ShareAddress); Q_ASSERT(success); qCDebug(KDECONNECT_CORE) << "onStart"; @@ -96,7 +95,7 @@ void LanLinkProvider::onStart() void LanLinkProvider::onStop() { qCDebug(KDECONNECT_CORE) << "onStop"; - mUdpServer->close(); + mUdpSocket.close(); mServer->close(); } @@ -121,13 +120,13 @@ void LanLinkProvider::onNetworkChange() //I will create a TcpSocket and try to connect. This can result in either connected() or connectError(). void LanLinkProvider::newUdpConnection() //udpBroadcastReceived { - while (mUdpServer->hasPendingDatagrams()) { + while (mUdpSocket.hasPendingDatagrams()) { QByteArray datagram; - datagram.resize(mUdpServer->pendingDatagramSize()); + datagram.resize(mUdpSocket.pendingDatagramSize()); QHostAddress sender; - mUdpServer->readDatagram(datagram.data(), datagram.size(), &sender); + mUdpSocket.readDatagram(datagram.data(), datagram.size(), &sender); if (sender.isLoopback() && !mTestMode) continue; diff --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h index 5116f6178..858fb1a7b 100644 --- a/core/backends/lan/lanlinkprovider.h +++ b/core/backends/lan/lanlinkprovider.h @@ -72,7 +72,6 @@ private: void addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, LanDeviceLink::ConnectionStarted connectionOrigin); Server* mServer; - QUdpSocket* mUdpServer; QUdpSocket mUdpSocket; const static quint16 port = 1714; quint16 mTcpPort;