static void RegisterChannel(IChannel chnl, bool ensureSecurity) { if (chnl == null) { throw new ArgumentNullException("chnl"); } #if NET_2_0 if (ensureSecurity) { ISecurableChannel securable = chnl as ISecurableChannel; if (securable == null) { throw new RemotingException(String.Format("Channel {0} is not securable while ensureSecurity is specified as true", chnl.ChannelName)); } securable.IsSecured = true; } #endif // Put the channel in the correct place according to its priority. // Since there are not many channels, a linear search is ok. lock (registeredChannels.SyncRoot) { int pos = -1; for (int n = 0; n < registeredChannels.Count; n++) { IChannel regc = (IChannel)registeredChannels[n]; if (regc.ChannelName == chnl.ChannelName && chnl.ChannelName != "") { throw new RemotingException("Channel " + regc.ChannelName + " already registered"); } if (regc.ChannelPriority < chnl.ChannelPriority && pos == -1) { pos = n; } } if (pos != -1) { registeredChannels.Insert(pos, chnl); } else { registeredChannels.Add(chnl); } IChannelReceiver receiver = chnl as IChannelReceiver; if (receiver != null && oldStartModeTypes.Contains(chnl.GetType().ToString())) { receiver.StartListening(null); } } }
/// <summary>Registers a channel with the channel services.</summary> /// <param name="chnl">The channel to register.</param> /// <param name="ensureSecurity">true ensures that security is enabled; otherwise false. Setting the value to false will not nullify the security setting done on the TCP or IPC channel. For details, see Remarks.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="chnl" /> parameter is null. </exception> /// <exception cref="T:System.Runtime.Remoting.RemotingException">The channel has already been registered. </exception> /// <exception cref="T:System.Security.SecurityException">At least one of the callers higher in the call stack does not have permission to configure remoting types and channels. </exception> /// <exception cref="T:System.NotSupportedException">Not supported in Windows 98 for <see cref="T:System.Runtime.Remoting.Channels.Tcp.TcpServerChannel" /> and on all platforms for <see cref="T:System.Runtime.Remoting.Channels.Http.HttpServerChannel" />. Host the service using Internet Information Services (IIS) if you require a secure HTTP channel.</exception> public static void RegisterChannel(IChannel chnl, bool ensureSecurity) { if (chnl == null) { throw new ArgumentNullException("chnl"); } if (ensureSecurity) { ISecurableChannel securableChannel = chnl as ISecurableChannel; if (securableChannel == null) { throw new RemotingException(string.Format("Channel {0} is not securable while ensureSecurity is specified as true", chnl.ChannelName)); } securableChannel.IsSecured = true; } object syncRoot = ChannelServices.registeredChannels.SyncRoot; lock (syncRoot) { int num = -1; for (int i = 0; i < ChannelServices.registeredChannels.Count; i++) { IChannel channel = (IChannel)ChannelServices.registeredChannels[i]; if (channel.ChannelName == chnl.ChannelName && chnl.ChannelName != string.Empty) { throw new RemotingException("Channel " + channel.ChannelName + " already registered"); } if (channel.ChannelPriority < chnl.ChannelPriority && num == -1) { num = i; } } if (num != -1) { ChannelServices.registeredChannels.Insert(num, chnl); } else { ChannelServices.registeredChannels.Add(chnl); } IChannelReceiver channelReceiver = chnl as IChannelReceiver; if (channelReceiver != null && ChannelServices.oldStartModeTypes.Contains(chnl.GetType().ToString())) { channelReceiver.StartListening(null); } } }
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); } } }
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
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); } } }
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); } } }