예제 #1
0
        public unsafe static void UnregisterChannel(IChannel chnl)
        {
            bool flag = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(ChannelServices.s_channelLock, ref flag);
                if (chnl != null)
                {
                    RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
                    int num = registeredChannelList.FindChannelIndex(chnl);
                    if (-1 == num)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", new object[]
                        {
                            chnl.ChannelName
                        }));
                    }
                    RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
                    RegisteredChannel[] array           = new RegisteredChannel[registeredChannels.Length - 1];
                    IChannelReceiver    channelReceiver = chnl as IChannelReceiver;
                    if (channelReceiver != null)
                    {
                        channelReceiver.StopListening(null);
                    }
                    int num2 = 0;
                    int i    = 0;
                    while (i < registeredChannels.Length)
                    {
                        if (i == num)
                        {
                            i++;
                        }
                        else
                        {
                            array[num2] = registeredChannels[i];
                            num2++;
                            i++;
                        }
                    }
                    if (ChannelServices.perf_Contexts != null)
                    {
                        ChannelServices.perf_Contexts->cChannels--;
                    }
                    ChannelServices.s_registeredChannels = new RegisteredChannelList(array);
                }
                ChannelServices.RefreshChannelData();
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(ChannelServices.s_channelLock);
                }
            }
        }
        public static unsafe void UnregisterChannel(IChannel chnl)
        {
            bool lockTaken = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(s_channelLock, ref lockTaken);
                if (chnl != null)
                {
                    RegisteredChannelList list = s_registeredChannels;
                    int num = list.FindChannelIndex(chnl);
                    if (-1 == num)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", new object[] { chnl.ChannelName }));
                    }
                    RegisteredChannel[] registeredChannels = list.RegisteredChannels;
                    RegisteredChannel[] channels           = null;
                    channels = new RegisteredChannel[registeredChannels.Length - 1];
                    IChannelReceiver receiver = chnl as IChannelReceiver;
                    if (receiver != null)
                    {
                        receiver.StopListening(null);
                    }
                    int index = 0;
                    int num3  = 0;
                    while (num3 < registeredChannels.Length)
                    {
                        if (num3 == num)
                        {
                            num3++;
                        }
                        else
                        {
                            channels[index] = registeredChannels[num3];
                            index++;
                            num3++;
                        }
                    }
                    if (perf_Contexts != null)
                    {
                        perf_Contexts.cChannels--;
                    }
                    s_registeredChannels = new RegisteredChannelList(channels);
                }
                RefreshChannelData();
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(s_channelLock);
                }
            }
        }
예제 #3
0
        public static unsafe void UnregisterChannel(IChannel chnl)
        {
            bool lockTaken = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(ChannelServices.s_channelLock, ref lockTaken);
                if (chnl != null)
                {
                    RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
                    int channelIndex = registeredChannelList.FindChannelIndex(chnl);
                    if (-1 == channelIndex)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", (object)chnl.ChannelName));
                    }
                    RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
                    RegisteredChannel[] channels           = new RegisteredChannel[registeredChannels.Length - 1];
                    IChannelReceiver    channelReceiver    = chnl as IChannelReceiver;
                    if (channelReceiver != null)
                    {
                        channelReceiver.StopListening((object)null);
                    }
                    int index1 = 0;
                    int index2 = 0;
                    while (index2 < registeredChannels.Length)
                    {
                        if (index2 == channelIndex)
                        {
                            ++index2;
                        }
                        else
                        {
                            channels[index1] = registeredChannels[index2];
                            ++index1;
                            ++index2;
                        }
                    }
                    if ((IntPtr)ChannelServices.perf_Contexts != IntPtr.Zero)
                    {
                        --ChannelServices.perf_Contexts->cChannels;
                    }
                    ChannelServices.s_registeredChannels = new RegisteredChannelList(channels);
                }
                ChannelServices.RefreshChannelData();
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(ChannelServices.s_channelLock);
                }
            }
        }
예제 #4
0
        internal static unsafe void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        {
            if (chnl == null)
            {
                throw new ArgumentNullException("chnl");
            }
            bool lockTaken = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(ChannelServices.s_channelLock, ref lockTaken);
                string channelName = chnl.ChannelName;
                RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
                if (channelName == null || channelName.Length == 0 || -1 == registeredChannelList.FindChannelIndex(chnl.ChannelName))
                {
                    if (ensureSecurity)
                    {
                        ISecurableChannel securableChannel = chnl as ISecurableChannel;
                        if (securableChannel != null)
                        {
                            securableChannel.IsSecured = ensureSecurity;
                        }
                        else
                        {
                            throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", (object)(chnl.ChannelName ?? chnl.ToString())));
                        }
                    }
                    RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
                    RegisteredChannel[] channels           = registeredChannels != null ? new RegisteredChannel[registeredChannels.Length + 1] : new RegisteredChannel[1];
                    if (!ChannelServices.unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                    {
                        AppDomain.CurrentDomain.DomainUnload   += new EventHandler(ChannelServices.UnloadHandler);
                        ChannelServices.unloadHandlerRegistered = true;
                    }
                    int channelPriority = chnl.ChannelPriority;
                    int index;
                    for (index = 0; index < registeredChannels.Length; ++index)
                    {
                        RegisteredChannel registeredChannel = registeredChannels[index];
                        if (channelPriority > registeredChannel.Channel.ChannelPriority)
                        {
                            channels[index] = new RegisteredChannel(chnl);
                            break;
                        }
                        channels[index] = registeredChannel;
                    }
                    if (index == registeredChannels.Length)
                    {
                        channels[registeredChannels.Length] = new RegisteredChannel(chnl);
                    }
                    else
                    {
                        for (; index < registeredChannels.Length; ++index)
                        {
                            channels[index + 1] = registeredChannels[index];
                        }
                    }
                    if ((IntPtr)ChannelServices.perf_Contexts != IntPtr.Zero)
                    {
                        ++ChannelServices.perf_Contexts->cChannels;
                    }
                    ChannelServices.s_registeredChannels = new RegisteredChannelList(channels);
                    ChannelServices.RefreshChannelData();
                }
                else
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", (object)chnl.ChannelName));
                }
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(ChannelServices.s_channelLock);
                }
            }
        }
예제 #5
0
        unsafe public static void UnregisterChannel(IChannel chnl)
        {
            // we allow null to be passed in, so we can use this api to trigger the
            //   refresh of the channel data

            bool fLocked = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.ReliableEnter(s_channelLock, ref fLocked);
                if (chnl != null)
                {
                    RegisteredChannelList regChnlList = s_registeredChannels;

                    // Check to make sure that the channel has been registered
                    int matchingIdx = regChnlList.FindChannelIndex(chnl);
                    if (-1 == matchingIdx)
                    {
                        throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_ChannelNotRegistered"), chnl.ChannelName));
                    }

                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    BCLDebug.Assert((oldList != null) && (oldList.Length != 0), "channel list should not be empty");

                    newList = new RegisteredChannel[oldList.Length - 1];

                    // Call stop listening on the channel if it is a receiver.
                    IChannelReceiver srvChannel = chnl as IChannelReceiver;
                    if (srvChannel != null)
                    {
                        srvChannel.StopListening(null);
                    }

                    int current = 0;
                    int oldPos  = 0;
                    while (oldPos < oldList.Length)
                    {
                        if (oldPos == matchingIdx)
                        {
                            oldPos++;
                        }
                        else
                        {
                            newList[current] = oldList[oldPos];
                            current++;
                            oldPos++;
                        }
                    }

                    if (perf_Contexts != null)
                    {
                        perf_Contexts->cChannels--;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }

                RefreshChannelData();
            } // lock (s_channelLock)
            finally
            {
                if (fLocked)
                {
                    Monitor.Exit(s_channelLock);
                }
            }
        } // UnregisterChannel
예제 #6
0
        unsafe internal static void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        {
            // Validate arguments
            if (null == chnl)
            {
                throw new ArgumentNullException("chnl");
            }

            bool fLocked = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.ReliableEnter(s_channelLock, ref fLocked);
                String chnlName = chnl.ChannelName;

                RegisteredChannelList regChnlList = s_registeredChannels;

                // Check to make sure that the channel has not been registered
                if ((chnlName == null) ||
                    (chnlName.Length == 0) ||
                    (-1 == regChnlList.FindChannelIndex(chnl.ChannelName)))
                {
                    if (ensureSecurity)
                    {
                        ISecurableChannel securableChannel = chnl as ISecurableChannel;
                        if (securableChannel != null)
                        {
                            securableChannel.IsSecured = ensureSecurity;
                        }
                        else
                        {
                            throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Channel_CannotBeSecured"), chnl.ChannelName ?? chnl.ToString()));
                        }
                    }
                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    if (oldList == null)
                    {
                        newList = new RegisteredChannel[1];
                    }
                    else
                    {
                        newList = new RegisteredChannel[oldList.Length + 1];
                    }

                    if (!unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                    {
                        // Register a unload handler only once and if the channel being registered
                        // is not the x-domain channel. x-domain channel does nothing inside its
                        // StopListening implementation
                        AppDomain.CurrentDomain.DomainUnload += new EventHandler(UnloadHandler);
                        unloadHandlerRegistered = true;
                    }

                    // Add the interface to the array in priority order
                    int priority = chnl.ChannelPriority;
                    int current  = 0;

                    // Find the place in the array to insert
                    while (current < oldList.Length)
                    {
                        RegisteredChannel oldChannel = oldList[current];
                        if (priority > oldChannel.Channel.ChannelPriority)
                        {
                            newList[current] = new RegisteredChannel(chnl);
                            break;
                        }
                        else
                        {
                            newList[current] = oldChannel;
                            current++;
                        }
                    }

                    if (current == oldList.Length)
                    {
                        // chnl has lower priority than all old channels, so we insert
                        //   it at the end of the list.
                        newList[oldList.Length] = new RegisteredChannel(chnl);
                    }
                    else
                    {
                        // finish copying rest of the old channels
                        while (current < oldList.Length)
                        {
                            newList[current + 1] = oldList[current];
                            current++;
                        }
                    }

                    if (perf_Contexts != null)
                    {
                        perf_Contexts->cChannels++;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }
                else
                {
                    throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered"), chnl.ChannelName));
                }

                RefreshChannelData();
            } // lock (s_channelLock)
            finally
            {
                if (fLocked)
                {
                    Monitor.Exit(s_channelLock);
                }
            }
        } // RegisterChannelInternal
예제 #7
0
        unsafe internal static void RegisterChannelInternal(IChannel chnl)
        {
            // Validate arguments
            if (null == chnl)
            {
                throw new ArgumentNullException("chnl");
            }

            lock (s_channelLock)
            {
                String chnlName = chnl.ChannelName;

                RegisteredChannelList regChnlList = s_registeredChannels;

                // Check to make sure that the channel has not been registered
                if ((chnlName == null) ||
                    (chnlName.Length == 0) ||
                    (-1 == regChnlList.FindChannelIndex(chnl.ChannelName)))
                {
                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    if (oldList == null)
                    {
                        newList = new RegisteredChannel[1];
                    }
                    else
                    {
                        newList = new RegisteredChannel[oldList.Length + 1];
                    }

                    if (newList.Length == 1)
                    {
                        // This is the first channel being registered.
                        //   (we know this since the x-appdmn channel can't be unregistered).
                        AppDomain.CurrentDomain.DomainUnload += new EventHandler(UnloadHandler);

                        newList[0] = new RegisteredChannel(chnl);
                    }
                    else
                    {
                        // Add the interface to the array in priority order
                        int priority = chnl.ChannelPriority;
                        int current  = 0;

                        // Find the place in the array to insert
                        while (current < oldList.Length)
                        {
                            RegisteredChannel oldChannel = oldList[current];
                            if (priority > oldChannel.Channel.ChannelPriority)
                            {
                                newList[current] = new RegisteredChannel(chnl);
                                break;
                            }
                            else
                            {
                                newList[current] = oldChannel;
                                current++;
                            }
                        }

                        if (current == oldList.Length)
                        {
                            // chnl has lower priority than all old channels, so we insert
                            //   it at the end of the list.
                            newList[oldList.Length] = new RegisteredChannel(chnl);
                        }
                        else
                        {
                            // finish copying rest of the old channels
                            while (current < oldList.Length)
                            {
                                newList[current + 1] = oldList[current];
                                current++;
                            }
                        }
                    }

                    if (perf_Contexts != null)
                    {
                        perf_Contexts->cChannels++;
                    }
                    if (perf_globalContexts != null)
                    {
                        perf_globalContexts->cChannels++;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }
                else
                {
                    throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered"), chnl.ChannelName));
                }

                RefreshChannelData();
            } // lock (s_channelLock)
        }     // RegisterChannelInternal
예제 #8
0
        unsafe public static void UnregisterChannel(IChannel chnl)
        {
            // we allow null to be passed in, so we can use this api to trigger the
            //   refresh of the channel data (in V.Next we will expose
            //   ChannelServices::RefreshChannelData as public).

            lock (s_channelLock)
            {
                if (chnl != null)
                {
                    RegisteredChannelList regChnlList = s_registeredChannels;

                    // Check to make sure that the channel has been registered
                    int matchingIdx = regChnlList.FindChannelIndex(chnl);
                    if (-1 == matchingIdx)
                    {
                        throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_ChannelNotRegistered"), chnl.ChannelName));
                    }

                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    BCLDebug.Assert((oldList != null) && (oldList.Length != 0), "channel list should not be empty");

                    newList = new RegisteredChannel[oldList.Length - 1];

                    // Call stop listening on the channel if it is a receiver.
                    IChannelReceiver srvChannel = chnl as IChannelReceiver;
                    if (srvChannel != null)
                    {
                        srvChannel.StopListening(null);
                    }

                    int current = 0;
                    int oldPos  = 0;
                    while (oldPos < oldList.Length)
                    {
                        if (oldPos == matchingIdx)
                        {
                            oldPos++;
                        }
                        else
                        {
                            newList[current] = oldList[oldPos];
                            current++;
                            oldPos++;
                        }
                    }

                    if (perf_Contexts != null)
                    {
                        perf_Contexts->cChannels--;
                    }
                    if (perf_globalContexts != null)
                    {
                        perf_globalContexts->cChannels--;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }

                RefreshChannelData();
            } // lock (s_channelLock)
        }     // UnregisterChannel
        } // RegisteredChannelList
 
        internal RegisteredChannelList(RegisteredChannel[] channels)
        { 
            _channels = channels; 
        } // RegisteredChannelList
예제 #10
0
        internal unsafe static void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        {
            if (chnl == null)
            {
                throw new ArgumentNullException("chnl");
            }
            bool flag = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(ChannelServices.s_channelLock, ref flag);
                string channelName = chnl.ChannelName;
                RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
                if (channelName != null && channelName.Length != 0 && -1 != registeredChannelList.FindChannelIndex(chnl.ChannelName))
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", new object[]
                    {
                        chnl.ChannelName
                    }));
                }
                if (ensureSecurity)
                {
                    ISecurableChannel securableChannel = chnl as ISecurableChannel;
                    if (securableChannel == null)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", new object[]
                        {
                            chnl.ChannelName ?? chnl.ToString()
                        }));
                    }
                    securableChannel.IsSecured = ensureSecurity;
                }
                RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
                RegisteredChannel[] array;
                if (registeredChannels == null)
                {
                    array = new RegisteredChannel[1];
                }
                else
                {
                    array = new RegisteredChannel[registeredChannels.Length + 1];
                }
                if (!ChannelServices.unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                {
                    AppDomain.CurrentDomain.DomainUnload   += ChannelServices.UnloadHandler;
                    ChannelServices.unloadHandlerRegistered = true;
                }
                int channelPriority = chnl.ChannelPriority;
                int i;
                for (i = 0; i < registeredChannels.Length; i++)
                {
                    RegisteredChannel registeredChannel = registeredChannels[i];
                    if (channelPriority > registeredChannel.Channel.ChannelPriority)
                    {
                        array[i] = new RegisteredChannel(chnl);
                        break;
                    }
                    array[i] = registeredChannel;
                }
                if (i == registeredChannels.Length)
                {
                    array[registeredChannels.Length] = new RegisteredChannel(chnl);
                }
                else
                {
                    while (i < registeredChannels.Length)
                    {
                        array[i + 1] = registeredChannels[i];
                        i++;
                    }
                }
                if (ChannelServices.perf_Contexts != null)
                {
                    ChannelServices.perf_Contexts->cChannels++;
                }
                ChannelServices.s_registeredChannels = new RegisteredChannelList(array);
                ChannelServices.RefreshChannelData();
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(ChannelServices.s_channelLock);
                }
            }
        }
        [System.Security.SecurityCritical]  // auto-generated 
        unsafe internal static void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        { 
            // Validate arguments 
            if(null == chnl)
            { 
                throw new ArgumentNullException("chnl");
            }
            Contract.EndContractBlock();
 
            bool fLocked = false;
            RuntimeHelpers.PrepareConstrainedRegions(); 
            try 
            {
                Monitor.Enter(s_channelLock, ref fLocked); 
                String chnlName = chnl.ChannelName;

                RegisteredChannelList regChnlList = s_registeredChannels;
 
                // Check to make sure that the channel has not been registered
                if((chnlName == null) || 
                   (chnlName.Length == 0) || 
                   (-1 == regChnlList.FindChannelIndex(chnl.ChannelName)))
                { 
                    if (ensureSecurity)
                    {
                        ISecurableChannel securableChannel = chnl as ISecurableChannel;
                        if (securableChannel != null) 
                            securableChannel.IsSecured = ensureSecurity;
                        else 
                            throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", chnl.ChannelName??chnl.ToString())); 

                    } 
                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    if (oldList == null)
                    { 
                        newList = new RegisteredChannel[1];
                    } 
                    else 
                        newList = new RegisteredChannel[oldList.Length + 1];
 
                    if (!unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                    {
                        // Register a unload handler only once and if the channel being registered
                        // is not the x-domain channel. x-domain channel does nothing inside its 
                        // StopListening implementation
                        AppDomain.CurrentDomain.DomainUnload += new EventHandler(UnloadHandler); 
                        unloadHandlerRegistered = true; 
                    }
 
                    // Add the interface to the array in priority order
                    int priority = chnl.ChannelPriority;
                    int current = 0;
 
                    // Find the place in the array to insert
                    while (current < oldList.Length) 
                    { 
                        RegisteredChannel oldChannel = oldList[current];
                        if (priority > oldChannel.Channel.ChannelPriority) 
                        {
                            newList[current] = new RegisteredChannel(chnl);
                            break;
                        } 
                        else
                        { 
                            newList[current] = oldChannel; 
                            current++;
                        } 
                    }

                    if (current == oldList.Length)
                    { 
                        // chnl has lower priority than all old channels, so we insert
                        //   it at the end of the list. 
                        newList[oldList.Length] = new RegisteredChannel(chnl); 
                    }
                    else 
                    {
                        // finish copying rest of the old channels
                        while (current < oldList.Length)
                        { 
                            newList[current + 1] = oldList[current];
                            current++; 
                        } 
                    }
 
                    if (perf_Contexts != null) {
                        perf_Contexts->cChannels++;
                    }
 
                    s_registeredChannels = new RegisteredChannelList(newList);
                } 
                else 
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", chnl.ChannelName)); 
                }

                RefreshChannelData();
            } // lock (s_channelLock) 
            finally
            { 
                if (fLocked) 
                {
                    Monitor.Exit(s_channelLock); 
                }
            }
        } // RegisterChannelInternal
        internal static unsafe void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        {
            if (chnl == null)
            {
                throw new ArgumentNullException("chnl");
            }
            bool lockTaken = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(s_channelLock, ref lockTaken);
                string channelName         = chnl.ChannelName;
                RegisteredChannelList list = s_registeredChannels;
                if (((channelName != null) && (channelName.Length != 0)) && (-1 != list.FindChannelIndex(chnl.ChannelName)))
                {
                    goto Label_0180;
                }
                if (ensureSecurity)
                {
                    ISecurableChannel channel = chnl as ISecurableChannel;
                    if (channel == null)
                    {
                        object[] values = new object[] { chnl.ChannelName ?? chnl.ToString() };
                        throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", values));
                    }
                    channel.IsSecured = ensureSecurity;
                }
                RegisteredChannel[] registeredChannels = list.RegisteredChannels;
                RegisteredChannel[] channels           = null;
                if (registeredChannels == null)
                {
                    channels = new RegisteredChannel[1];
                }
                else
                {
                    channels = new RegisteredChannel[registeredChannels.Length + 1];
                }
                if (!unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                {
                    AppDomain.CurrentDomain.DomainUnload += new EventHandler(ChannelServices.UnloadHandler);
                    unloadHandlerRegistered = true;
                }
                int channelPriority = chnl.ChannelPriority;
                int index           = 0;
                while (index < registeredChannels.Length)
                {
                    RegisteredChannel channel2 = registeredChannels[index];
                    if (channelPriority > channel2.Channel.ChannelPriority)
                    {
                        channels[index] = new RegisteredChannel(chnl);
                        break;
                    }
                    channels[index] = channel2;
                    index++;
                }
                if (index != registeredChannels.Length)
                {
                    goto Label_014F;
                }
                channels[registeredChannels.Length] = new RegisteredChannel(chnl);
                goto Label_0157;
Label_013D:
                channels[index + 1] = registeredChannels[index];
                index++;
Label_014F:
                if (index < registeredChannels.Length)
                {
                    goto Label_013D;
                }
Label_0157:
                if (perf_Contexts != null)
                {
                    perf_Contexts.cChannels++;
                }
                s_registeredChannels = new RegisteredChannelList(channels);
                goto Label_01A4;
                Label_0180 :;
                throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", new object[] { chnl.ChannelName }));
Label_01A4:
                RefreshChannelData();
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(s_channelLock);
                }
            }
        }
 public static unsafe void UnregisterChannel(IChannel chnl)
 {
     bool lockTaken = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         Monitor.Enter(s_channelLock, ref lockTaken);
         if (chnl != null)
         {
             RegisteredChannelList list = s_registeredChannels;
             int num = list.FindChannelIndex(chnl);
             if (-1 == num)
             {
                 throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", new object[] { chnl.ChannelName }));
             }
             RegisteredChannel[] registeredChannels = list.RegisteredChannels;
             RegisteredChannel[] channels = null;
             channels = new RegisteredChannel[registeredChannels.Length - 1];
             IChannelReceiver receiver = chnl as IChannelReceiver;
             if (receiver != null)
             {
                 receiver.StopListening(null);
             }
             int index = 0;
             int num3 = 0;
             while (num3 < registeredChannels.Length)
             {
                 if (num3 == num)
                 {
                     num3++;
                 }
                 else
                 {
                     channels[index] = registeredChannels[num3];
                     index++;
                     num3++;
                 }
             }
             if (perf_Contexts != null)
             {
                 perf_Contexts.cChannels--;
             }
             s_registeredChannels = new RegisteredChannelList(channels);
         }
         RefreshChannelData();
     }
     finally
     {
         if (lockTaken)
         {
             Monitor.Exit(s_channelLock);
         }
     }
 }
 internal static unsafe void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
 {
     if (chnl == null)
     {
         throw new ArgumentNullException("chnl");
     }
     bool lockTaken = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         Monitor.Enter(s_channelLock, ref lockTaken);
         string channelName = chnl.ChannelName;
         RegisteredChannelList list = s_registeredChannels;
         if (((channelName != null) && (channelName.Length != 0)) && (-1 != list.FindChannelIndex(chnl.ChannelName)))
         {
             goto Label_0180;
         }
         if (ensureSecurity)
         {
             ISecurableChannel channel = chnl as ISecurableChannel;
             if (channel == null)
             {
                 object[] values = new object[] { chnl.ChannelName ?? chnl.ToString() };
                 throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", values));
             }
             channel.IsSecured = ensureSecurity;
         }
         RegisteredChannel[] registeredChannels = list.RegisteredChannels;
         RegisteredChannel[] channels = null;
         if (registeredChannels == null)
         {
             channels = new RegisteredChannel[1];
         }
         else
         {
             channels = new RegisteredChannel[registeredChannels.Length + 1];
         }
         if (!unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
         {
             AppDomain.CurrentDomain.DomainUnload += new EventHandler(ChannelServices.UnloadHandler);
             unloadHandlerRegistered = true;
         }
         int channelPriority = chnl.ChannelPriority;
         int index = 0;
         while (index < registeredChannels.Length)
         {
             RegisteredChannel channel2 = registeredChannels[index];
             if (channelPriority > channel2.Channel.ChannelPriority)
             {
                 channels[index] = new RegisteredChannel(chnl);
                 break;
             }
             channels[index] = channel2;
             index++;
         }
         if (index != registeredChannels.Length)
         {
             goto Label_014F;
         }
         channels[registeredChannels.Length] = new RegisteredChannel(chnl);
         goto Label_0157;
     Label_013D:
         channels[index + 1] = registeredChannels[index];
         index++;
     Label_014F:
         if (index < registeredChannels.Length)
         {
             goto Label_013D;
         }
     Label_0157:
         if (perf_Contexts != null)
         {
             perf_Contexts.cChannels++;
         }
         s_registeredChannels = new RegisteredChannelList(channels);
         goto Label_01A4;
     Label_0180:;
         throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", new object[] { chnl.ChannelName }));
     Label_01A4:
         RefreshChannelData();
     }
     finally
     {
         if (lockTaken)
         {
             Monitor.Exit(s_channelLock);
         }
     }
 }
예제 #15
0
        unsafe internal static void RegisterChannelInternal(IChannel chnl)
        {
            // Validate arguments
            if(null == chnl)
            {
                throw new ArgumentNullException("chnl");
            }
        
            lock (s_channelLock)
            {
                String chnlName = chnl.ChannelName;

                RegisteredChannelList regChnlList = s_registeredChannels;
        
                // Check to make sure that the channel has not been registered
                if((chnlName == null) ||
                   (chnlName.Length == 0) ||
                   (-1 == regChnlList.FindChannelIndex(chnl.ChannelName)))
                {
                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    if (oldList == null)
                    {                                            
                        newList = new RegisteredChannel[1];
                    }
                    else
                        newList = new RegisteredChannel[oldList.Length + 1];

                    if (newList.Length == 1)
                    {
                        // This is the first channel being registered.
                        //   (we know this since the x-appdmn channel can't be unregistered).
                        AppDomain.CurrentDomain.DomainUnload += new EventHandler(UnloadHandler);
                        
                        newList[0] = new RegisteredChannel(chnl);
                    }
                    else
                    {                                                    
                        // Add the interface to the array in priority order
                        int priority = chnl.ChannelPriority;
                        int current = 0;
        
                        // Find the place in the array to insert
                        while (current < oldList.Length)
                        {
                            RegisteredChannel oldChannel = oldList[current];
                            if (priority > oldChannel.Channel.ChannelPriority)
                            {
                                newList[current] = new RegisteredChannel(chnl);
                                break;
                            }
                            else
                            {
                                newList[current] = oldChannel;
                                current++;
                            }
                        }

                        if (current == oldList.Length)
                        {
                            // chnl has lower priority than all old channels, so we insert
                            //   it at the end of the list.
                            newList[oldList.Length] = new RegisteredChannel(chnl);
                        }
                        else
                        {
                            // finish copying rest of the old channels
                            while (current < oldList.Length)
                            {
                                newList[current + 1] = oldList[current];
                                current++;
                            }
                        }
                    }

                    if (perf_Contexts != null) {
                        perf_Contexts->cChannels++;
                    }
                    if (perf_globalContexts != null) {
                        perf_globalContexts->cChannels++;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }
                else
                {
                    throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered"), chnl.ChannelName));
                }

                RefreshChannelData();
            } // lock (s_channelLock)
        } // RegisterChannelInternal
 internal RegisteredChannelList(RegisteredChannel[] channels)
 {
     this._channels = channels;
 }
        unsafe public static void UnregisterChannel(IChannel chnl)
        { 
            // we allow null to be passed in, so we can use this api to trigger the
            //   refresh of the channel data <

 
            bool fLocked = false;
            RuntimeHelpers.PrepareConstrainedRegions(); 
            try 
            {
                Monitor.Enter(s_channelLock, ref fLocked); 
                if (chnl != null)
                {
                    RegisteredChannelList regChnlList = s_registeredChannels;
 
                    // Check to make sure that the channel has been registered
                    int matchingIdx = regChnlList.FindChannelIndex(chnl); 
                    if(-1 == matchingIdx) 
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", chnl.ChannelName)); 
                    }

                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null; 
                    Contract.Assert((oldList != null) && (oldList.Length != 0), "channel list should not be empty");
 
                    newList = new RegisteredChannel[oldList.Length - 1]; 

                    // Call stop listening on the channel if it is a receiver. 
                    IChannelReceiver srvChannel = chnl as IChannelReceiver;
                    if (srvChannel != null)
                        srvChannel.StopListening(null);
 
                    int current = 0;
                    int oldPos = 0; 
                    while (oldPos < oldList.Length) 
                    {
                        if (oldPos == matchingIdx) 
                        {
                            oldPos++;
                        }
                        else 
                        {
                            newList[current] = oldList[oldPos]; 
                            current++; 
                            oldPos++;
                        } 
                    }

                    if (perf_Contexts != null) {
                        perf_Contexts->cChannels--; 
                    }
 
                    s_registeredChannels = new RegisteredChannelList(newList); 
                }
 
                RefreshChannelData();
            } // lock (s_channelLock)
            finally
            { 
                if (fLocked)
                { 
                    Monitor.Exit(s_channelLock); 
                }
            } 
        } // UnregisterChannel