public void PutSocket(NcpClient socket) { lock (this.socketsQueue) { if (this.socketsQueue.Count < this.maxConnectionNumber) { if (socket != null) { if (socket.Connected) { this.socketsQueue.Enqueue(socket); } else { socket.Close(); } } } else { socket.Close(); } } }
private NcpClient CreateSocket() { if (socketNumber <= maxConnectionNumber) { System.Threading.Interlocked.Increment(ref socketNumber); var c = new NcpClient(); return c; } throw new Exception("Connection Pool reached its limit"); }