Exemple #1
0
        /// <summary>
        /// Starts a resolve process with a timeout.
        /// </summary>
        /// <param name="seconds">The maximum number of seconds to attempt a resolve.</param>
        public void ResolveWithTimeout(int seconds)
        {
            Stop();

            resolveReplyCb = new mDNSImports.DNSServiceResolveReply(ResolveReply);

            DNSServiceErrorType err;

            err = mDNSImports.DNSServiceResolve(out registeredServiceHandle, 0, 0, Name, Type, Domain, resolveReplyCb, IntPtr.Zero);

            if (err == DNSServiceErrorType.NoError)
            {
                SetupWatchSocket(registeredServiceHandle);

                resolveTimer = new System.Threading.Timer(new TimerCallback(ResolveTimerCallback), resolveReplyCb, (seconds * 1000), Timeout.Infinite);
            }
            else
            {
                Stop();
                if (DidNotResolveService != null)
                {
                    DNSServiceException exception = new DNSServiceException("DNSServiceResolve", err);
                    DidNotResolveService(this, exception);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Stops the currently running search or resolution.
        /// </summary>
        public void Stop()
        {
            if (resolveTimer != null)
            {
                resolveTimer.Dispose();
                resolveTimer = null;
            }

            TeardownWatchSocket(registeredServiceHandle);
            if (registeredServiceHandle != IntPtr.Zero)
            {
                mDNSImports.DNSServiceRefDeallocate(registeredServiceHandle);
                registeredServiceHandle = IntPtr.Zero;
            }

            resolveReplyCb  = null;
            registerReplyCb = null;

            TeardownWatchSocket(ipLookupQueryHandle);
            if (ipLookupQueryHandle != IntPtr.Zero)
            {
                mDNSImports.DNSServiceRefDeallocate(ipLookupQueryHandle);
                ipLookupQueryHandle = IntPtr.Zero;
            }

            ipLookupReplyCb = null;
        }
Exemple #3
0
        /// <summary>
        /// Called when the resolve timer fires.
        ///
        /// If this object instance is configured with an <see cref="DNSService.InvokeableObject">InvokeableObject</see>,
        /// this method is called in a thread safe manner. Typically, this means it's called on the application main loop.
        /// </summary>
        /// <param name="state">The object passed to the timer during initialization.</param>
        private void ResolveTimerReply(object state)
        {
            mDNSImports.DNSServiceResolveReply resolveReplyCbThen = (mDNSImports.DNSServiceResolveReply)state;
            if (resolveReplyCbThen == resolveReplyCb)
            {
                Stop();

                if (DidNotResolveService != null)
                {
                    DNSServiceException exception = new DNSServiceException("Timeout", DNSServiceErrorType.Timeout);
                    DidNotResolveService(this, exception);
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Stops the currently running search or resolution.
 /// </summary>
 public void Stop()
 {
     /* FIXME: do i need to stop the poll? ... */
     if (sdRef != IntPtr.Zero)
     {
         mDNSImports.DNSServiceRefDeallocate(sdRef);
         sdRef = IntPtr.Zero;
     }
     WaitStop();
     resolveReplyCb = null;
     if (gchSelf.IsAllocated)
     {
         gchSelf.Free();
     }
 }
Exemple #5
0
        /// <summary>
        /// Starts a resolve process with a timeout.
        /// </summary>
        /// <param name="seconds">The maximum number of seconds to attempt a resolve.</param>
        public void ResolveWithTimeout(int seconds)
        {
            Stop();

            resolveReplyCb = new mDNSImports.DNSServiceResolveReply(ResolveReply);
            gchSelf = GCHandle.Alloc(this);

            DNSServiceErrorType err;
            err = mDNSImports.DNSServiceResolve(out sdRef, 0, 0, Name, Type, Domain, resolveReplyCb, (IntPtr)gchSelf);

            if (err != DNSServiceErrorType.kDNSServiceErr_NoError)
            {
                throw new DNSServiceException("DNSServiceResolve", err);
            }

            SetupWatchSocket();
        }
        /// <summary>
        /// Stops the currently running search or resolution.
        /// </summary>
        public void Stop()
        {
            if (resolveTimer != null)
            {
                resolveTimer.Dispose();
                resolveTimer = null;
            }

            TeardownWatchSocket(registeredServiceHandle);
            if (registeredServiceHandle != IntPtr.Zero)
            {
                mDNSImports.DNSServiceRefDeallocate(registeredServiceHandle);
                registeredServiceHandle = IntPtr.Zero;
            }

            resolveReplyCb = null;
            registerReplyCb = null;

            TeardownWatchSocket(ipLookupQueryHandle);
            if (ipLookupQueryHandle != IntPtr.Zero)
            {
                mDNSImports.DNSServiceRefDeallocate(ipLookupQueryHandle);
                ipLookupQueryHandle = IntPtr.Zero;
            }

            ipLookupReplyCb = null;
        }
        /// <summary>
        /// Starts a resolve process with a timeout.
        /// </summary>
        /// <param name="seconds">The maximum number of seconds to attempt a resolve.</param>
        public void ResolveWithTimeout(int seconds)
        {
            Stop();

            resolveReplyCb = new mDNSImports.DNSServiceResolveReply(ResolveReply);

            DNSServiceErrorType err;
            err = mDNSImports.DNSServiceResolve(out registeredServiceHandle, 0, 0, Name, Type, Domain, resolveReplyCb, IntPtr.Zero);

            if (err == DNSServiceErrorType.NoError)
            {
                SetupWatchSocket(registeredServiceHandle);

                resolveTimer = new System.Threading.Timer(new TimerCallback(ResolveTimerCallback), resolveReplyCb, (seconds * 1000), Timeout.Infinite);
            }
            else
            {
                Stop();
                if (DidNotResolveService != null)
                {
                    DNSServiceException exception = new DNSServiceException("DNSServiceResolve", err);
                    DidNotResolveService(this, exception);
                }
            }
        }