Beispiel #1
0
        public virtual void ReleaseConnection(Connection connection)
        {
            String lHost = connection.OriginalEndpoint.ToString();

            if (!connection.Connected)
            {
                connection.Dispose();
                return;
            }

            lock (this.fCache)
            {
                ConnectionQueue lQueue;
                if (this.fCache.ContainsKey(lHost))
                {
                    lQueue = (ConnectionQueue)this.fCache[lHost];
                }
                else
                {
                    lQueue = new ConnectionQueue(this.fMaxQueuePerHost == 0 ? 8 : fMaxQueuePerHost);
                    this.fCache.Add(lHost, lQueue);
                }

                if (lQueue.Count < this.fMaxQueuePerHost || this.fMaxQueuePerHost < 1)
                {
                    connection.LastUsed = DateTime.Now;
                    lQueue.Enqueue(connection);
                }
                else
                {
                    connection.Dispose();
                }
            }
        }
Beispiel #2
0
        private void CleanupCallback(Object state)
        {
            DateTime ExpireTime = DateTime.Now.AddSeconds(-this.Timeout);

            lock (this.fCache)
            {
                foreach (DictionaryEntry entry in this.fCache)
                {
                    ConnectionQueue lQueue    = (ConnectionQueue)entry.Value;
                    Boolean         lModified = false;

                    for (Int32 i = lQueue.UnderlyingArray.Length - 1; i >= 0; i--)
                    {
                        if (lQueue.UnderlyingArray[i] == null || lQueue.UnderlyingArray[i].LastUsed >= ExpireTime)
                        {
                            continue;
                        }

                        lModified = true;
                        lQueue.UnderlyingArray[i].Dispose();
                        lQueue.UnderlyingArray[i] = null;
                    }

                    if (lModified)
                    {
                        lQueue.RemoveNulls();
                    }
                }
            }
        }
Beispiel #3
0
        public virtual Connection GetConnection(EndPoint endPoint)
        {
            String lHost = endPoint.ToString();

            lock (this.fCache)
            {
                ConnectionQueue lQueue = this.fCache.ContainsKey(lHost) ? (ConnectionQueue)this.fCache[lHost] : null;
                if (lQueue != null && lQueue.Count > 0)
                {
                    return(lQueue.Dequeue());
                }
            }

            return(this.GetNewConnection(endPoint));
        }
Beispiel #4
0
        public virtual void ReleaseConnection(Connection connection)
        {
            String lHost = connection.OriginalEndpoint.ToString();

            if (!connection.Connected)
            {
                connection.Dispose();
                return;
            }

            lock (this.fCache)
            {
                ConnectionQueue lQueue;
                if (this.fCache.ContainsKey(lHost))
                    lQueue = (ConnectionQueue)this.fCache[lHost];
                else
                {
                    lQueue = new ConnectionQueue(this.fMaxQueuePerHost == 0 ? 8 : fMaxQueuePerHost);
                    this.fCache.Add(lHost, lQueue);
                }

                if (lQueue.Count < this.fMaxQueuePerHost || this.fMaxQueuePerHost < 1)
                {
                    ((Connection)connection).LastUsed = DateTime.Now;
                    lQueue.Enqueue((Connection)connection);
                }
                else
                {
                    connection.Dispose();
                }
            }
        }