Ticket #11446: 0002-Make-sure-we-only-run-one-Bonjour-registration-at-a-.patch

File 0002-Make-sure-we-only-run-one-Bonjour-registration-at-a-.patch, 2.3 KB (added by JYA, 11 years ago)

only one bonjour registration at a time

  • mythtv/libs/libmythbase/bonjourregister.cpp

    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  
    88
    99#define LOC QString("Bonjour: ")
    1010
     11QMutex BonjourRegister::m_lock;
     12
    1113BonjourRegister::BonjourRegister(QObject *parent)
    1214  : QObject(parent), m_dnssref(0), m_socket(NULL)
    1315{
    bool BonjourRegister::Register(uint16_t port, const QByteArray &type, 
    4143        return true;
    4244    }
    4345
     46    m_lock.lock();
     47
    4448    uint16_t qport = qToBigEndian(port);
    4549    DNSServiceErrorType res =
    4650        DNSServiceRegister(&m_dnssref, 0, 0, (const char*)name.data(),
    bool BonjourRegister::Register(uint16_t port, const QByteArray &type, 
    6670    }
    6771
    6872    LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to register service.");
     73    m_lock.unlock();
    6974    return false;
    7075}
    7176
    void BonjourRegister::BonjourCallback(DNSServiceRef ref, DNSServiceFlags flags, 
    8792    (void)flags;
    8893
    8994    BonjourRegister *bonjour = static_cast<BonjourRegister *>(object);
     95    bonjour->m_lock.unlock();
    9096    if (kDNSServiceErr_NoError != errorcode)
    9197    {
    9298        LOG(VB_GENERAL, LOG_ERR, LOC + QString("Callback Error: %1")
  • mythtv/libs/libmythbase/bonjourregister.h

    diff --git a/mythtv/libs/libmythbase/bonjourregister.h b/mythtv/libs/libmythbase/bonjourregister.h
    index e5205d4..c1dfa2d 100644
    a b  
    22#define BONJOURREGISTER_H
    33
    44#include <QObject>
     5#include <QMutex>
    56#include <dns_sd.h>
    67#include "mythbaseexp.h"
    78
    class MBASE_PUBLIC BonjourRegister : public QObject 
    3132                                          const char *domain, void *object);
    3233    DNSServiceRef    m_dnssref;
    3334    QSocketNotifier *m_socket;
     35    static QMutex    m_lock;
    3436};
    3537#endif