Navigation Menu

Skip to content

Commit

Permalink
Make sure we only run one Bonjour registration at a time.
Browse files Browse the repository at this point in the history
Seems Bonjour isn't re-entrant with some implementations. So surround it with a lock

Fixes #11446
  • Loading branch information
jyavenard committed Jun 18, 2013
1 parent 3690ff3 commit 9b22dab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mythtv/libs/libmythbase/bonjourregister.cpp
Expand Up @@ -8,6 +8,8 @@

#define LOC QString("Bonjour: ")

QMutex BonjourRegister::m_lock;

BonjourRegister::BonjourRegister(QObject *parent)
: QObject(parent), m_dnssref(0), m_socket(NULL)
{
Expand Down Expand Up @@ -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(),
Expand All @@ -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;
}

Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythbase/bonjourregister.h
Expand Up @@ -2,6 +2,7 @@
#define BONJOURREGISTER_H

#include <QObject>
#include <QMutex>
#include <dns_sd.h>
#include "mythbaseexp.h"

Expand Down Expand Up @@ -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.