Remove second UDP socket in LanLinkProvider

We don't need two sockets for reading and writing.

REVIEW: 127769
This commit is contained in:
David Kahles 2016-04-27 20:38:23 +02:00
parent 623ca94a0c
commit abc5fa3c56
2 changed files with 6 additions and 8 deletions

View file

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

View file

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