/// <summary> /// Releases all resources allocated by this instance /// </summary> public void Dispose() { // this is not a graceful shutdown // if someone uses a pooled item then 99% that an exception will be thrown // somewhere. But since the dispose is mostly used when everyone else is finished // this should not kill any kittens if (!this.isDisposed) { this.isAlive = false; this.isDisposed = true; PooledSocket ps; while (this.freeItems.TryPop(out ps)) { try { ps.Destroy(); } catch { } } this.ownerNode = null; this.semaphore.Close(); this.semaphore = null; this.freeItems = null; } }
internal InternalPoolImpl(MemcachedNode ownerNode, ISocketPoolConfiguration config) { if (config.MinPoolSize < 0) { throw new InvalidOperationException("minItems must be larger >= 0", null); } if (config.MaxPoolSize < config.MinPoolSize) { throw new InvalidOperationException("maxItems must be larger than minItems", null); } if (config.QueueTimeout < TimeSpan.Zero) { throw new InvalidOperationException("queueTimeout must be >= TimeSpan.Zero", null); } this.ownerNode = ownerNode; this.isAlive = true; this.endPoint = ownerNode.EndPoint; this.queueTimeout = config.QueueTimeout; this.minItems = config.MinPoolSize; this.maxItems = config.MaxPoolSize; this.semaphore = new Semaphore(maxItems, maxItems); this.freeItems = new InterlockedStack <PooledSocket>(); }