Exemple #1
0
        public static bool UnsafeNotifyStableUnicastIpAddressTable(Action <object> callback, object state)
        {
            TeredoHelper     item  = new TeredoHelper(callback, state);
            uint             num   = 0;
            SafeFreeMibTable table = null;

            lock (pendingNotifications)
            {
                if (impendingAppDomainUnload)
                {
                    return(false);
                }
                num = UnsafeNetInfoNativeMethods.NotifyStableUnicastIpAddressTable(AddressFamily.Unspecified, out table, item.onStabilizedDelegate, IntPtr.Zero, out item.cancelHandle);
                if (table != null)
                {
                    table.Dispose();
                }
                if (num == 0x3e5)
                {
                    pendingNotifications.Add(item);
                    return(false);
                }
            }
            if (num != 0)
            {
                throw new Win32Exception((int)num);
            }
            return(true);
        }
Exemple #2
0
        // Returns true if the address table is already stable.  Otherwise, calls callback when it becomes stable.
        // 'Unsafe' because it does not flow ExecutionContext to the callback.
        public static bool UnsafeNotifyStableUnicastIpAddressTable(Action <object> callback, object state)
        {
            if (callback == null)
            {
                if (GlobalLog.IsEnabled)
                {
                    GlobalLog.Assert("UnsafeNotifyStableUnicastIpAddressTable called without specifying callback!");
                }
                Debug.Fail("UnsafeNotifyStableUnicastIpAddressTable called without specifying callback!");
            }

            TeredoHelper helper = new TeredoHelper(callback, state);

            uint             err   = Interop.IpHlpApi.ERROR_SUCCESS;
            SafeFreeMibTable table = null;

            lock (s_pendingNotifications)
            {
                // If OnAppDomainUnload gets the lock first, tell our caller that we'll finish async.  Their AppDomain
                // is about to go down anyways.  If we do, hold the lock until we've added helper to the
                // s_pendingNotifications list (if we're going to complete asynchronously).
                if (Environment.HasShutdownStarted)
                {
                    return(false);
                }

                err = Interop.IpHlpApi.NotifyStableUnicastIpAddressTable(AddressFamily.Unspecified,
                                                                         out table, helper._onStabilizedDelegate, IntPtr.Zero, out helper._cancelHandle);

                if (table != null)
                {
                    table.Dispose();
                }

                if (err == Interop.IpHlpApi.ERROR_IO_PENDING)
                {
                    if (helper._cancelHandle.IsInvalid)
                    {
                        if (GlobalLog.IsEnabled)
                        {
                            GlobalLog.Assert("CancelHandle invalid despite returning ERROR_IO_PENDING");
                        }
                        Debug.Fail("CancelHandle invalid despite returning ERROR_IO_PENDING");
                    }

                    // Async completion: add us to the s_pendingNotifications list so we'll be canceled in the
                    // event of an AppDomain unload.
                    s_pendingNotifications.Add(helper);
                    return(false);
                }
            }

            if (err != Interop.IpHlpApi.ERROR_SUCCESS)
            {
                throw new Win32Exception((int)err);
            }

            return(true);
        }
        // Returns true if the address table is already stable.  Otherwise, calls callback when it becomes stable.
        // 'Unsafe' because it does not flow ExecutionContext to the callback.
        public static bool UnsafeNotifyStableUnicastIpAddressTable(Action <object> callback, object state)
        {
            GlobalLog.Assert(callback != null,
                             "UnsafeNotifyStableUnicastIpAddressTable called without specifying callback!");

            TeredoHelper helper = new TeredoHelper(callback, state);

            uint             err   = UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS;
            SafeFreeMibTable table = null;

            lock (pendingNotifications)
            {
                // If OnAppDomainUnload gets the lock first, tell our caller that we'll finish async.  Their AppDomain
                // is about to go down anyways.  If we do, hold the lock until we've added helper to the
                // pendingNotifications list (if we're going to complete asynchronously).
                if (impendingAppDomainUnload)
                {
                    return(false);
                }

                err = UnsafeNetInfoNativeMethods.NotifyStableUnicastIpAddressTable(AddressFamily.Unspecified,
                                                                                   out table, helper.onStabilizedDelegate, IntPtr.Zero, out helper.cancelHandle);

                if (table != null)
                {
                    table.Dispose();
                }

                if (err == UnsafeNclNativeMethods.ErrorCodes.ERROR_IO_PENDING)
                {
                    GlobalLog.Assert(!helper.cancelHandle.IsInvalid,
                                     "CancelHandle invalid despite returning ERROR_IO_PENDING");

                    // Async completion: add us to the pendingNotifications list so we'll be canceled in the
                    // event of an AppDomain unload.
                    pendingNotifications.Add(helper);
                    return(false);
                }
            }

            if (err != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
            {
                throw new Win32Exception((int)err);
            }

            return(true);
        }
 internal static extern uint NotifyStableUnicastIpAddressTable([In] AddressFamily addressFamily, out SafeFreeMibTable table, [In, MarshalAs(UnmanagedType.FunctionPtr)] StableUnicastIpAddressTableDelegate callback, [In] IntPtr context, out SafeCancelMibChangeNotify notificationHandle);
 internal static extern uint NotifyStableUnicastIpAddressTable([In] AddressFamily addressFamily, out SafeFreeMibTable table, [In, MarshalAs(UnmanagedType.FunctionPtr)] StableUnicastIpAddressTableDelegate callback, [In] IntPtr context, out SafeCancelMibChangeNotify notificationHandle);