Beispiel #1
0
        private WebConnectionGroup GetConnectionGroup(string name)
        {
            if (name == null)
            {
                name = "";
            }

            /*
             * Optimization:
             *
             * In the vast majority of cases, we only have one single WebConnectionGroup per ServicePoint, so we
             * don't need to allocate a dictionary.
             *
             */

            WebConnectionGroup group;

            if (groups != null && groups.TryGetValue(name, out group))
            {
                return(group);
            }

            group = new WebConnectionGroup(this, name);
            group.ConnectionClosed += (s, e) => currentConnections--;

            if (groups == null)
            {
                groups = new Dictionary <string, WebConnectionGroup> ();
            }
            groups.Add(name, group);

            return(group);
        }
Beispiel #2
0
        public bool CloseConnectionGroup(string connectionGroupName)
        {
            lock (this)
            {
                WebConnectionGroup cncGroup = GetConnectionGroup(connectionGroupName);
                if (cncGroup != null)
                {
                    cncGroup.Close();
                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
        private void RemoveConnectionGroup(WebConnectionGroup group)
        {
            if (groups == null)
            {
                return;
            }

            if (groups.Count == 0)
            {
                throw new InvalidOperationException();
            }

            groups.Remove(group.Name);
        }
Beispiel #4
0
        internal EventHandler SendRequest(HttpWebRequest request, string groupName)
        {
            WebConnection cnc;

            lock (this)
            {
                bool created;
                WebConnectionGroup cncGroup = GetConnectionGroup(groupName);
                cnc = cncGroup.GetConnection(request, out created);
                if (created)
                {
                    ++currentConnections;
                    if (idleTimer == null)
                    {
                        idleTimer = new Timer(IdleTimerCallback, null, maxIdleTime, maxIdleTime);
                    }
                }
            }

            return(cnc.SendRequest(request));
        }
			public ConnectionState (WebConnectionGroup group)
			{
				Group = group;
				idleSince = DateTime.UtcNow;
				Connection = new WebConnection (this, group.sPoint);
			}
Beispiel #6
0
        void RemoveConnectionGroup(WebConnectionGroup group)
        {
            if (groups == null || groups.Count == 0)
            {
                // No more connection groups left.
                if (group != firstGroup)
                    throw new InvalidOperationException();
                firstGroup = null;
                return;
            }

            if (group == firstGroup)
            {
                // Steal one entry from the dictionary.
                var en = groups.GetEnumerator();
                en.MoveNext();
                firstGroup = en.Current.Value;
                groups.Remove(en.Current.Key);
            }
            else
                groups.Remove(group.Name);
        }
Beispiel #7
0
        WebConnectionGroup GetConnectionGroup(string name)
        {
            if (name == null)
                name = "";

            /*
             * Optimization:
             * 
             * In the vast majority of cases, we only have one single WebConnectionGroup per ServicePoint, so we
             * don't need to allocate a dictionary.
             * 
             */

            WebConnectionGroup group;
            if (firstGroup != null && name == firstGroup.Name)
                return firstGroup;
            if (groups != null && groups.TryGetValue(name, out group))
                return group;

            group = new WebConnectionGroup(this, name);
            group.ConnectionClosed += (s, e) => currentConnections--;

            if (firstGroup == null)
                firstGroup = group;
            else
            {
                if (groups == null)
                    groups = new Dictionary<string, WebConnectionGroup>();
                groups.Add(name, group);
            }

            return group;
        }
 public ConnectionState(WebConnectionGroup group)
 {
     Group      = group;
     idleSince  = DateTime.UtcNow;
     Connection = new WebConnection(this, group.sPoint);
 }