Skip to content

Commit 0b60ff0

Browse files
committed
SSDP::PerformSearch(): reuse the QUdpSocket from SSDPReceiver
to ensure the replies are sent to the listening socket address and port.
1 parent 7a034bc commit 0b60ff0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

mythtv/libs/libmythupnp/ssdp.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ void SSDP::DisableNotifications()
151151
}
152152
}
153153

154-
/////////////////////////////////////////////////////////////////////////////
155-
//
156-
/////////////////////////////////////////////////////////////////////////////
157154
void SSDP::PerformSearch(const QString &sST, std::chrono::seconds timeout)
155+
{
156+
m_receiver.performSearch(sST, timeout);
157+
}
158+
159+
void SSDPReceiver::performSearch(const QString &sST, std::chrono::seconds timeout)
158160
{
159161
timeout = std::clamp(timeout, 1s, 5s);
160162
QString rRequest = QString("M-SEARCH * HTTP/1.1\r\n"
@@ -170,16 +172,14 @@ void SSDP::PerformSearch(const QString &sST, std::chrono::seconds timeout)
170172
QByteArray sRequest = rRequest.toUtf8();
171173
int nSize = sRequest.size();
172174

173-
QUdpSocket socket;
174-
socket.bind(QHostAddress(QHostAddress::AnyIPv4), SSDP_PORT, QUdpSocket::ShareAddress);
175-
if (socket.writeDatagram(sRequest, QHostAddress(QString(SSDP_GROUP)), SSDP_PORT) != nSize)
175+
if (m_socket.writeDatagram(sRequest, QHostAddress(QString(SSDP_GROUP)), SSDP_PORT) != nSize)
176176
{
177177
LOG(VB_GENERAL, LOG_INFO, "SSDP::PerformSearch - did not write entire buffer.");
178178
}
179179

180180
std::this_thread::sleep_for(std::chrono::milliseconds(MythRandom(0, 250)));
181181

182-
if (socket.writeDatagram(sRequest, QHostAddress(QString(SSDP_GROUP)), SSDP_PORT) != nSize)
182+
if (m_socket.writeDatagram(sRequest, QHostAddress(QString(SSDP_GROUP)), SSDP_PORT) != nSize)
183183
{
184184
LOG(VB_GENERAL, LOG_INFO, "SSDP::PerformSearch - did not write entire buffer.");
185185
}

mythtv/libs/libmythupnp/ssdp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class SSDPReceiver : public QObject
4141
public:
4242
SSDPReceiver();
4343

44+
void performSearch(const QString &sST, std::chrono::seconds timeout = 2s);
45+
4446
private slots:
4547
void processPendingDatagrams();
4648

@@ -80,9 +82,8 @@ class UPNP_PUBLIC SSDP
8082
~SSDP();
8183

8284
/** @brief Send a SSDP discover multicast datagram.
83-
@note This needs an SSDPReceiver instance to process the replies and add to the SSDPCache.
8485
*/
85-
static void PerformSearch(const QString &sST, std::chrono::seconds timeout = 2s);
86+
void PerformSearch(const QString &sST, std::chrono::seconds timeout = 2s);
8687

8788
void EnableNotifications ( int nServicePort );
8889
void DisableNotifications();

0 commit comments

Comments
 (0)