X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=avahi-sharp%2FServiceTypeBrowser.cs;h=ab6a8668183d852a84ab0aa7997c084d09f350b5;hb=dab307a583fcacdb0703e451f4f854f540fc8ec1;hp=c3b8159dcfd5b930092f57385b6418db38e8dea2;hpb=a26804ae8742b59b220b5a0776f42de3da026d6a;p=catta diff --git a/avahi-sharp/ServiceTypeBrowser.cs b/avahi-sharp/ServiceTypeBrowser.cs index c3b8159..ab6a866 100644 --- a/avahi-sharp/ServiceTypeBrowser.cs +++ b/avahi-sharp/ServiceTypeBrowser.cs @@ -46,6 +46,7 @@ namespace Avahi private int iface; private Protocol proto; private string domain; + private ServiceTypeBrowserCallback cb; private ArrayList addListeners = new ArrayList (); private ArrayList removeListeners = new ArrayList (); @@ -101,6 +102,7 @@ namespace Avahi this.iface = iface; this.proto = proto; this.domain = domain; + cb = OnServiceTypeBrowserCallback; } ~ServiceTypeBrowser () @@ -115,20 +117,27 @@ namespace Avahi private void Start () { - if (handle != IntPtr.Zero || (addListeners.Count == 0 && removeListeners.Count == 0)) + if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero || + (addListeners.Count == 0 && removeListeners.Count == 0)) return; - IntPtr domainPtr = Utility.StringToPtr (domain); - handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, domainPtr, - OnServiceTypeBrowserCallback, IntPtr.Zero); - Utility.Free (domainPtr); + lock (client) { + IntPtr domainPtr = Utility.StringToPtr (domain); + handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, domainPtr, + cb, IntPtr.Zero); + Utility.Free (domainPtr); + } } private void Stop (bool force) { - if (handle != IntPtr.Zero && (force || (addListeners.Count == 0 && removeListeners.Count == 0))) { - avahi_service_type_browser_free (handle); - handle = IntPtr.Zero; + if (client.Handle != IntPtr.Zero && handle != IntPtr.Zero && + (force || (addListeners.Count == 0 && removeListeners.Count == 0))) { + + lock (client) { + avahi_service_type_browser_free (handle); + handle = IntPtr.Zero; + } } }