Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d09f4bf
create BlockingTcpSocket
ulmus-scott Feb 26, 2025
afbbac2
remove set but unused UPnpSearchTask::m_addressList
ulmus-scott Mar 2, 2025
0ba8a26
libmythupnp/upnptasksearch.*: only include used headers
ulmus-scott Mar 2, 2025
e47077b
UPnpSearchTask::ProcessDevice(): use const UPnpDevice&
ulmus-scott Mar 2, 2025
a744f0a
UPnpSearchTask::UPnpSearchTask(): copy and std::move()
ulmus-scott Mar 2, 2025
0099085
libmythupnp/upnptasksearch.*: remove unnecessary blank lines and comm…
ulmus-scott Mar 2, 2025
5ebc261
libmythupnp/upnptasksearch.cpp: remove unused static variable
ulmus-scott Mar 2, 2025
019a0a9
UPnpSearchTask::SendMsg(): re-enable log message
ulmus-scott Mar 2, 2025
02815d5
UPnpSearchTask::SendMsg(): remove QString temporary variables
ulmus-scott Mar 2, 2025
1a10530
UPnpSearchTask: replace Qt3 MSocketDevice with QUpdSocket
ulmus-scott Mar 3, 2025
6143421
libmythupnp/upnptasksearch.*: only include used headers
ulmus-scott Mar 3, 2025
92711be
libmythupnp/ssdp.h: only include used headers
ulmus-scott Mar 3, 2025
896d668
UPnpNotifyTask::SendNotifyMsg(): remove QMutexLocker
ulmus-scott Mar 3, 2025
5df65c5
libmythupnp/upnptasknotify.*: remove unnecessary blank lines and comm…
ulmus-scott Mar 3, 2025
5d2d510
UPnpNotifyTask::ProcessDevice(): use const UPnpDevice&
ulmus-scott Mar 3, 2025
752dde1
UPnpNotifyTask::SendNotifyMsg(): remove QString temporary variables
ulmus-scott Mar 3, 2025
a65306a
UPnpNotifyTask: replace Qt3 MMulticastSocketDevice with QUpdSocket
ulmus-scott Mar 3, 2025
77ea401
UPnpNotifyTask: use member initializer list
ulmus-scott Mar 3, 2025
c5d53d5
remove MBroadcastSocketDevice
ulmus-scott Mar 3, 2025
557ed1e
make SSDP::m_sockets[SocketIdx_Search] local to SSDP::PerformSearch()
ulmus-scott Mar 3, 2025
2c50a64
SSDP::PerformSearch(): replace Qt3 MMulticastSocketDevice with QUpdSo…
ulmus-scott Mar 3, 2025
9eb3a5f
libmythupnp/ssdp.h: remove include of ssdpcache.h
ulmus-scott Mar 3, 2025
354a15d
move SSDPExtension to its own file
ulmus-scott Mar 3, 2025
d19e1ea
SSDP: replace Qt3 MMulticastSocketDevice with QUpdSocket
ulmus-scott Mar 3, 2025
980b43a
remove now unused Qt3 MSocketDevice
ulmus-scott Mar 4, 2025
dd6b94d
SSDP: remove unused m_lock and set but unused m_bAnnouncementsEnabled
ulmus-scott Mar 4, 2025
3b3a3df
fix ssdp:discover response receipt
ulmus-scott Mar 7, 2025
940da5b
PortChecker::checkPort(): reduce blocking time
ulmus-scott Mar 7, 2025
125a635
PortChecker::checkPort(): fix indent
ulmus-scott Mar 7, 2025
36c2e72
SSDP::PerformSearch(): reuse the QUdpSocket from SSDPReceiver
ulmus-scott Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions mythtv/docs/doxygen-create-developer-docs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -902,14 +902,6 @@ EXCLUDE_PATTERNS = */moc/* \
*/test/* \
*/.git

# Skip files from the Qt3Support module.
EXCLUDE_PATTERNS += mmembuf.cpp \
mmembuf.h \
msocketdevice.cpp \
msocketdevice.h \
msocketdevice_unix.cpp \
msocketdevice_win.cpp

# Example code
EXCLUDE_PATTERNS += example.cpp

Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmyth/backendselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BackendSelection::BackendSelection(

BackendSelection::~BackendSelection()
{
SSDP::RemoveListener(this);
SSDPCache::Instance()->removeListener(this);

ItemMap::iterator it;
for (it = m_devices.begin(); it != m_devices.end(); ++it)
Expand Down Expand Up @@ -253,7 +253,7 @@ void BackendSelection::Cancel(void)

void BackendSelection::Load(void)
{
SSDP::AddListener(this);
SSDPCache::Instance()->addListener(this);
SSDP::Instance()->PerformSearch(SSDP::kBackendURI);
}

Expand Down Expand Up @@ -334,7 +334,7 @@ void BackendSelection::customEvent(QEvent *event)
if (message.startsWith("SSDP_ADD") &&
URI.startsWith("urn:schemas-mythtv-org:device:MasterMediaServer:"))
{
DeviceLocation *devLoc = SSDP::Find(URI, URN);
DeviceLocation *devLoc = SSDPCache::Instance()->Find(URI, URN);
if (devLoc)
{
AddItem(devLoc);
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmyth/mythcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ int MythContext::Impl::UPnPautoconf(const std::chrono::milliseconds milliSeconds
}
}

SSDPCacheEntries *backends = SSDP::Find(SSDP::kBackendURI);
SSDPCacheEntries *backends = SSDPCache::Instance()->Find(SSDP::kBackendURI);

if (!backends)
{
Expand All @@ -1204,7 +1204,7 @@ int MythContext::Impl::UPnPautoconf(const std::chrono::milliseconds milliSeconds
else
{
LOG(VB_GENERAL, LOG_ERR,
"No UPnP backends found, but SSDP::Find() not NULL");
"No UPnP backends found, but SSDPCache::Instance()->Find() not NULL");
}

if (count != 1)
Expand Down Expand Up @@ -1274,7 +1274,7 @@ bool MythContext::Impl::DefaultUPnP(QString& Error)
searchTime.start();
while (totalTime.elapsed() < timeout_ms)
{
devicelocation = SSDP::Find(SSDP::kBackendURI, usn);
devicelocation = SSDPCache::Instance()->Find(SSDP::kBackendURI, usn);
if (devicelocation)
break;

Expand Down
148 changes: 79 additions & 69 deletions mythtv/libs/libmythbase/portchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QCoreApplication>
#include <QHostAddress>
#include <QTcpSocket>
#include <QThread>
#include <QEventLoop>
#include <QNetworkInterface>
#include <QNetworkAddressEntry>
Expand Down Expand Up @@ -110,93 +111,110 @@ bool PortChecker::checkPort(QString &host, int port, std::chrono::milliseconds t
MythTimer timer(MythTimer::kStartRunning);
QTcpSocket socket(this);
QAbstractSocket::SocketState state = QAbstractSocket::UnconnectedState;
int retryCount = 0;
QString scope;
bool testedAll = false;
while (state != QAbstractSocket::ConnectedState
&& (timer.elapsed() < timeLimit))
{
if (state == QAbstractSocket::UnconnectedState)
{
// Windows does not need the scope on the ip address so we can skip
// some processing
#ifndef _WIN32
int iCardsEnd = 0;
if (islinkLocal && !gCoreContext->GetScopeForAddress(addr))
int iCardsEnd = 0;
if (islinkLocal && !gCoreContext->GetScopeForAddress(addr))
{
addr.setScopeId(QString());
while (addr.scopeId().isEmpty() && iCardsEnd<2)
{
addr.setScopeId(QString());
while (addr.scopeId().isEmpty() && iCardsEnd<2)
// search for the next available IPV6 interface.
if (iCard.hasNext())
{
// search for the next available IPV6 interface.
if (iCard.hasNext())
QNetworkInterface card = iCard.next();
LOG(VB_GENERAL, LOG_DEBUG, QString("Trying interface %1").arg(card.name()));
unsigned int flags = card.flags();
if ((flags & QNetworkInterface::IsLoopBack)
|| !(flags & QNetworkInterface::IsRunning))
continue;
// check that IPv6 is enabled on that interface
QList<QNetworkAddressEntry> addresses = card.addressEntries();
bool foundv6 = false;
for (const auto& ae : std::as_const(addresses))
{
QNetworkInterface card = iCard.next();
LOG(VB_GENERAL, LOG_DEBUG, QString("Trying interface %1").arg(card.name()));
unsigned int flags = card.flags();
if ((flags & QNetworkInterface::IsLoopBack)
|| !(flags & QNetworkInterface::IsRunning))
continue;
// check that IPv6 is enabled on that interface
QList<QNetworkAddressEntry> addresses = card.addressEntries();
bool foundv6 = false;
for (const auto& ae : std::as_const(addresses))
{
if (ae.ip().protocol() == QAbstractSocket::IPv6Protocol)
{
foundv6 = true;
break;
}
}
if (foundv6)
if (ae.ip().protocol() == QAbstractSocket::IPv6Protocol)
{
scope = card.name();
addr.setScopeId(scope);
foundv6 = true;
break;
}
}
else
if (foundv6)
{
// Get a new list in case a new interface
// has been added.
cards = QNetworkInterface::allInterfaces();
iCard = cards;
iCard.toFront();
testedAll=true;
iCardsEnd++;
scope = card.name();
addr.setScopeId(scope);
break;
}
}
else
{
// Get a new list in case a new interface
// has been added.
cards = QNetworkInterface::allInterfaces();
iCard = cards;
iCard.toFront();
testedAll=true;
iCardsEnd++;
}
}
if (iCardsEnd > 1)
{
LOG(VB_GENERAL, LOG_ERR, LOC + QString("There is no IPV6 compatible interface for %1")
.arg(host));
break;
}
#endif
QString dest;
if (isIPAddress)
dest=addr.toString();
else
dest=host;
socket.connectToHost(dest, port);
retryCount=0;
}
if (iCardsEnd > 1)
{
LOG(VB_GENERAL, LOG_ERR, LOC + QString("There is no IPV6 compatible interface for %1")
.arg(host));
break;
}
#endif
QString dest;
if (isIPAddress)
dest=addr.toString();
else
dest=host;
socket.connectToHost(dest, port);

MythTimer attempt_time {MythTimer::kStartRunning};
static constexpr std::chrono::milliseconds k_poll_interval {1ms};
while (state != QAbstractSocket::ConnectedState
&& (timer.elapsed() < timeLimit)
&& attempt_time.elapsed() < 3s
)
{
retryCount++;
if (QCoreApplication::instance() != nullptr &&
QThread::currentThread() == QCoreApplication::instance()->thread()
)
{
QCoreApplication::processEvents(QEventLoop::AllEvents, k_poll_interval.count());
std::this_thread::sleep_for(1ns); // force thread to be de-scheduled
}
else
{
std::this_thread::sleep_for(k_poll_interval);
}
state = socket.state();
LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("host %1 port %2 socket state %3, attempt time: %4")
.arg(host, QString::number(port), QString::number(state),
QString::number(attempt_time.elapsed().count())
)
);
// Check if user got impatient and canceled
if (m_cancelCheck)
break;
if (linkLocalOnly && testedAll
&& state == QAbstractSocket::UnconnectedState
&& attempt_time.elapsed() > 500ms
)
break;
}
// This retry count of 6 means 3 seconds of waiting for
// connection before aborting and starting a new connection attempt.
if (retryCount > 6)
socket.abort();
processEvents();
socket.abort();
// Check if user got impatient and canceled
if (m_cancelCheck)
break;
std::this_thread::sleep_for(500ms);
state = socket.state();
LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("socket state %1")
.arg(state));
if (linkLocalOnly
&& state == QAbstractSocket::UnconnectedState
&& testedAll)
Expand All @@ -208,8 +226,6 @@ bool PortChecker::checkPort(QString &host, int port, std::chrono::milliseconds t
gCoreContext->SetScopeForAddress(addr);
host = addr.toString();
}
socket.abort();
processEvents();
return (state == QAbstractSocket::ConnectedState);
}

Expand All @@ -234,12 +250,6 @@ bool PortChecker::resolveLinkLocal(QString &host, int port, std::chrono::millise
return checker.checkPort(host,port,timeLimit,true);
}

void PortChecker::processEvents(void)
{
qApp->processEvents(QEventLoop::AllEvents, 250);
qApp->processEvents(QEventLoop::AllEvents, 250);
}

/**
* Cancel the checkPort operation currently in progress.
*
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythbase/portchecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class MBASE_PUBLIC PortChecker : public QObject

private:
bool m_cancelCheck {false};
static void processEvents(void);
};

#endif
Expand Down
7 changes: 4 additions & 3 deletions mythtv/libs/libmythtv/recorders/satiputils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "libmythbase/mythlogging.h"
#include "libmythbase/mythtimer.h"
#include "libmythupnp/ssdp.h"
#include "libmythupnp/ssdpcache.h"

#include "cardutil.h"
#include "satiputils.h"
Expand Down Expand Up @@ -55,7 +56,7 @@ QStringList SatIP::doUPNPsearch(bool loginfo)
{
QStringList result;

SSDPCacheEntries *satipservers = SSDP::Find(SATIP_URI);
SSDPCacheEntries *satipservers = SSDPCache::Instance()->Find(SATIP_URI);

if (!satipservers)
{
Expand All @@ -73,7 +74,7 @@ QStringList SatIP::doUPNPsearch(bool loginfo)
}
else
{
LOG(VB_GENERAL, LOG_ERR, LOC + "No UPnP Sat>IP servers found, but SSDP::Find() != NULL");
LOG(VB_GENERAL, LOG_ERR, LOC + "No UPnP Sat>IP servers found, but SSDPCache::Instance()->Find() != NULL");
}

EntryMap map;
Expand Down Expand Up @@ -139,7 +140,7 @@ QStringList SatIP::doUPNPsearch(bool loginfo)
QStringList SatIP::findServers(void)
{
QStringList devs;
SSDPCacheEntries *satipservers = SSDP::Find(SATIP_URI);
SSDPCacheEntries *satipservers = SSDPCache::Instance()->Find(SATIP_URI);
if (satipservers && satipservers->Count() > 0)
{
devs = SatIP::doUPNPsearch(false);
Expand Down
6 changes: 4 additions & 2 deletions mythtv/libs/libmythtv/recorders/vboxutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include <QString>
#include <QStringList>
#include <QDomDocument>
#include <QRegularExpression>

// MythTV headers
#include "libmythbase/mythdownloadmanager.h"
#include "libmythbase/mythlogging.h"
#include "libmythbase/mythtimer.h"
#include "libmythupnp/ssdp.h"
#include "libmythupnp/ssdpcache.h"
#include "vboxutils.h"

#define LOC QString("VBox: ")
Expand Down Expand Up @@ -67,7 +69,7 @@ QStringList VBox::doUPNPSearch(void)
{
QStringList result;

SSDPCacheEntries *vboxes = SSDP::Find(VBOX_URI);
SSDPCacheEntries *vboxes = SSDPCache::Instance()->Find(VBOX_URI);

if (!vboxes)
{
Expand All @@ -84,7 +86,7 @@ QStringList VBox::doUPNPSearch(void)
else
{
LOG(VB_GENERAL, LOG_ERR, LOC +
"No UPnP VBoxes found, but SSDP::Find() not NULL");
"No UPnP VBoxes found, but SSDPCache::Instance()->Find() not NULL");
}

EntryMap map;
Expand Down
Loading
Loading