From 50f67eb12e530520a376ef6403b1923dbafab5f7 Mon Sep 17 00:00:00 2001
From: Jean-Yves Avenard <jyavenard@mythtv.org>
Date: Mon, 17 Jun 2013 22:17:52 +1000
Subject: [PATCH 2/6] 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
---
mythtv/libs/libmythbase/bonjourregister.cpp | 6 ++++++
mythtv/libs/libmythbase/bonjourregister.h | 2 ++
2 files changed, 8 insertions(+)
diff --git a/mythtv/libs/libmythbase/bonjourregister.cpp b/mythtv/libs/libmythbase/bonjourregister.cpp
index 017ee6d..6460673 100644
a
|
b
|
|
8 | 8 | |
9 | 9 | #define LOC QString("Bonjour: ") |
10 | 10 | |
| 11 | QMutex BonjourRegister::m_lock; |
| 12 | |
11 | 13 | BonjourRegister::BonjourRegister(QObject *parent) |
12 | 14 | : QObject(parent), m_dnssref(0), m_socket(NULL) |
13 | 15 | { |
… |
… |
bool BonjourRegister::Register(uint16_t port, const QByteArray &type, |
41 | 43 | return true; |
42 | 44 | } |
43 | 45 | |
| 46 | m_lock.lock(); |
| 47 | |
44 | 48 | uint16_t qport = qToBigEndian(port); |
45 | 49 | DNSServiceErrorType res = |
46 | 50 | DNSServiceRegister(&m_dnssref, 0, 0, (const char*)name.data(), |
… |
… |
bool BonjourRegister::Register(uint16_t port, const QByteArray &type, |
66 | 70 | } |
67 | 71 | |
68 | 72 | LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to register service."); |
| 73 | m_lock.unlock(); |
69 | 74 | return false; |
70 | 75 | } |
71 | 76 | |
… |
… |
void BonjourRegister::BonjourCallback(DNSServiceRef ref, DNSServiceFlags flags, |
87 | 92 | (void)flags; |
88 | 93 | |
89 | 94 | BonjourRegister *bonjour = static_cast<BonjourRegister *>(object); |
| 95 | bonjour->m_lock.unlock(); |
90 | 96 | if (kDNSServiceErr_NoError != errorcode) |
91 | 97 | { |
92 | 98 | LOG(VB_GENERAL, LOG_ERR, LOC + QString("Callback Error: %1") |
diff --git a/mythtv/libs/libmythbase/bonjourregister.h b/mythtv/libs/libmythbase/bonjourregister.h
index e5205d4..c1dfa2d 100644
a
|
b
|
|
2 | 2 | #define BONJOURREGISTER_H |
3 | 3 | |
4 | 4 | #include <QObject> |
| 5 | #include <QMutex> |
5 | 6 | #include <dns_sd.h> |
6 | 7 | #include "mythbaseexp.h" |
7 | 8 | |
… |
… |
class MBASE_PUBLIC BonjourRegister : public QObject |
31 | 32 | const char *domain, void *object); |
32 | 33 | DNSServiceRef m_dnssref; |
33 | 34 | QSocketNotifier *m_socket; |
| 35 | static QMutex m_lock; |
34 | 36 | }; |
35 | 37 | #endif |