Permalink
Browse files

Make sure we only run one Bonjour registration at a time.

Seems Bonjour isn't re-entrant with some implementations. So surround it with a lock

Fixes #11446
  • Loading branch information...
jyavenard committed Jun 17, 2013
1 parent 3690ff3 commit 9b22dab41ecc1a304ebaaf6b87bea9870a199e3f
Showing with 8 additions and 0 deletions.
  1. +6 −0 mythtv/libs/libmythbase/bonjourregister.cpp
  2. +2 −0 mythtv/libs/libmythbase/bonjourregister.h
@@ -8,6 +8,8 @@
#define LOC QString("Bonjour: ")
QMutex BonjourRegister::m_lock;
BonjourRegister::BonjourRegister(QObject *parent)
: QObject(parent), m_dnssref(0), m_socket(NULL)
{
@@ -41,6 +43,8 @@ bool BonjourRegister::Register(uint16_t port, const QByteArray &type,
return true;
}
m_lock.lock();
uint16_t qport = qToBigEndian(port);
DNSServiceErrorType res =
DNSServiceRegister(&m_dnssref, 0, 0, (const char*)name.data(),
@@ -66,6 +70,7 @@ bool BonjourRegister::Register(uint16_t port, const QByteArray &type,
}
LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to register service.");
m_lock.unlock();
return false;
}
@@ -87,6 +92,7 @@ void BonjourRegister::BonjourCallback(DNSServiceRef ref, DNSServiceFlags flags,
(void)flags;
BonjourRegister *bonjour = static_cast<BonjourRegister *>(object);
bonjour->m_lock.unlock();
if (kDNSServiceErr_NoError != errorcode)
{
LOG(VB_GENERAL, LOG_ERR, LOC + QString("Callback Error: %1")
@@ -2,6 +2,7 @@
#define BONJOURREGISTER_H
#include <QObject>
#include <QMutex>
#include <dns_sd.h>
#include "mythbaseexp.h"
@@ -31,5 +32,6 @@ class MBASE_PUBLIC BonjourRegister : public QObject
const char *domain, void *object);
DNSServiceRef m_dnssref;
QSocketNotifier *m_socket;
static QMutex m_lock;
};
#endif

0 comments on commit 9b22dab

Please sign in to comment.