Ejemplo n.º 1
0
        private void SetConnectionLimit(int limit, bool fromUser)
        {
            lock (this) {
                // We'll only update the limit if the user hasn't previously
                // changed it or if this change is coming from the user.

                if (!m_UserChangedLimit || fromUser)
                {
                    // Save the value, and remember if it was changed by the
                    // user.

                    m_UserChangedLimit = fromUser;
                    m_ConnectionLimit  = limit;

                    // Now walk through the connection groups on this service
                    // point, and update all of them with the new value.
                    //

                    IDictionaryEnumerator CGEnumerator;

                    CGEnumerator = m_ConnectionGroupList.GetEnumerator();

                    while (CGEnumerator.MoveNext())
                    {
                        ConnectionGroup CurrentCG =
                            (ConnectionGroup)CGEnumerator.Value;

                        //
                        // If this change came in from the user, we want to
                        // propagate it down to the underlying connection
                        // groups no matter what. If it's from some internal state
                        // change, we want to propagate it via the internal
                        // mechanism, which only sets it if it hasn't been set by
                        // the user.

                        if (fromUser)
                        {
                            CurrentCG.ConnectionLimit = limit;
                        }
                        else
                        {
                            CurrentCG.InternalConnectionLimit = limit;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /*++
         *
         *  SetAddressList - Set the list of IP addresses for this service point.
         *
         *  This is a method called when the underlying code has resolved the
         *  destination to a list of IP addressess. We actually maintain some
         *  information about the viable IP addresses for this service point,
         *  like whether or not they're loopback, etc. So we walk through the
         *  list and set up an array of structures corresponding to the IP
         *  addresses.
         *
         *  Note that it's possible to have some IP addresses be loopbacked
         *  and some not. This can happen if a server name maps to multiple
         *  physical servers and we're one of those servers.
         *
         *  Input:
         *          addressList     - Array of resolved IP addresses.
         *
         *  Returns: Nothing.
         *
         * --*/
        private IPHostEntryInfo SetAddressList(IPHostEntry ipHostEntry)
        {
            GlobalLog.Print("SetAddressList(" + ipHostEntry.HostName + ")");
            //
            // Create an array of IPAddressInfo of the appropriate size, then
            // get a list of our local addresses. Walk through the input
            // address list. Copy each address in the address list into
            // our array, and if the address is a loopback address, mark it as
            // such.
            //
            IPAddress[]     addressList = ipHostEntry.AddressList;
            IPAddressInfo[] TempInfo    = new IPAddressInfo[addressList.Length];

            //
            // Walk through each member of the input list, copying it into our temp array.
            //
            int         i, k;
            IPHostEntry ipLocalHostEntry = null;

            try {
                ipLocalHostEntry = Dns.LocalHost;
            }
            catch (Exception exception) {
                GlobalLog.Print("ServicePoint#" + ValidationHelper.HashString(this) + "::SetAddressList() Dns.LocalHost threw exception:[" + ValidationHelper.ToString(exception) + "]");
            }
            for (i = 0; i < addressList.Length; i++)
            {
                TempInfo[i] = new IPAddressInfo(addressList[i]);

                // First, check to see if the current address is a  loopback
                // address.

                if (IPAddress.IsLoopback(TempInfo[i].Address))
                {
                    TempInfo[i].IsLoopback = true;
                    continue;
                }

                // See if the current IP address is a local address, and if
                // so mark it as such.
                if (ipLocalHostEntry != null)
                {
                    for (k = 0; k < ipLocalHostEntry.AddressList.Length; k++)
                    {
                        //
                        // IPv6 Changes: Use .Equals for this check !
                        //
                        if (TempInfo[i].Address.Equals(ipLocalHostEntry.AddressList[k]))
                        {
                            TempInfo[i].IsLoopback = true;
                            break;
                        }
                    }
                }
            }

            //
            // now look for connection group objects that don't have
            // an IP address associated with them. When it finds one, it updates
            // the IP address and tries to update the connection limit.
            //
            lock (this) {
                // Walk through the connection groups on this service
                // point, and update the ones we need to with an IP
                // address.
                //

                IDictionaryEnumerator CGEnumerator;

                CGEnumerator = m_ConnectionGroupList.GetEnumerator();

                while (CGEnumerator.MoveNext())
                {
                    ConnectionGroup CurrentCG = (ConnectionGroup)CGEnumerator.Value;

                    // If this connection group doesn't have an IP address
                    // assigned to it, give it one.

                    if (CurrentCG.RemoteIPAddress == null)
                    {
                        GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses null CurrentCG.RemoteIPAddress");

                        // Update the address.

                        CurrentCG.RemoteIPAddress = TempInfo[0].Address;

                        // Now update the connection limit based on what we know.

                        CurrentCG.InternalConnectionLimit = TempInfo[0].IsLoopback ? LoopbackConnectionLimit : m_ConnectionLimit;

                        GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses CurrentCG.InternalConnectionLimit:" + CurrentCG.InternalConnectionLimit.ToString());
                    }

                    GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses CurrentCG.RemoteIPAddress:" + CurrentCG.RemoteIPAddress.ToString());
                }
            }

            IPHostEntryInfo ipAddressInfoList = new IPHostEntryInfo(TempInfo, ipHostEntry.HostName);

            return(ipAddressInfoList);
        }