Inheritance: IClientDevice
Beispiel #1
0
        private void BrowseCallback(IntPtr h, DnsServiceFlags flags, int ifIndex, DnsServiceErrorType errorCode, string serviceName, string regType, string domain, IntPtr context)
        {
            errorCode.ThrowException("BrowseCallback");

            Dictionary <string, BonjourDevice> deviceList;

            lock (lookups)
                if (!lookups.TryGetValue(h, out deviceList))
                {
                    return;
                }

            var device = new BonjourDevice {
                DeviceId = serviceName, IsComplete = false, Error = DnsServiceErrorType.NoError
            };

            lock (deviceList)
                deviceList[serviceName] = device;

            IntPtr handle;
            var    r = Interop.DNSServiceResolve(out handle, DnsServiceFlags.Default | DnsServiceFlags.ForceMulticast, ifIndex, serviceName, regType, domain, resolveCallback, h);

            if (r != DnsServiceErrorType.NoError)
            {
                device.Error = r;
                return;
            }

            lock (deviceList)
                deviceList["0x" + handle.ToString("X")] = device;

            try
            {
                if (!Interop.DNSServiceHasData(handle, TimeSpan.FromSeconds(5)))
                {
                    return;
                }

                r = Interop.DNSServiceProcessResult(handle);

                if (r != DnsServiceErrorType.NoError)
                {
                    device.Error = r;
                    return;
                }
            }
            finally
            {
                lock (deviceList)
                    deviceList.Remove("0x" + handle.ToString("X"));
                Interop.DNSServiceRefDeallocate(handle);
            }
        }
        private void BrowseCallback(IntPtr h, DnsServiceFlags flags, int ifIndex, DnsServiceErrorType errorCode, string serviceName, string regType, string domain, IntPtr context)
        {
            errorCode.ThrowException("BrowseCallback");

            Dictionary<string, BonjourDevice> deviceList;
            lock (lookups)
                if (!lookups.TryGetValue(h, out deviceList)) return;

            var device = new BonjourDevice { DeviceId = serviceName, IsComplete = false, Error = DnsServiceErrorType.NoError };

            lock (deviceList)
                deviceList[serviceName] = device;

            IntPtr handle;
            var r = Interop.DNSServiceResolve(out handle, DnsServiceFlags.Default | DnsServiceFlags.ForceMulticast, ifIndex, serviceName, regType, domain, resolveCallback, h);

            if (r != DnsServiceErrorType.NoError)
            {
                device.Error = r;
                return;
            }

            lock (deviceList)
                deviceList["0x" + handle.ToString("X")] = device;

            try
            {
                if (!Interop.DNSServiceHasData(handle, TimeSpan.FromSeconds(5))) return;

                r = Interop.DNSServiceProcessResult(handle);

                if (r != DnsServiceErrorType.NoError)
                {
                    device.Error = r;
                    return;
                }
            }
            finally
            {
                lock (deviceList)
                    deviceList.Remove("0x" + handle.ToString("X"));
                Interop.DNSServiceRefDeallocate(handle);
            }
        }