public ThriftConnection(IConnectionSettings2 connectionSettings)
        {
            this._connectionSettings = connectionSettings;
            this._timeout = connectionSettings.Timeout;
            this._poolSize = Math.Max(1, connectionSettings.MaximumAsyncConnections);

            this._resourceLock = new Semaphore(_poolSize, _poolSize);

            for (var i = 0; i <= connectionSettings.MaximumAsyncConnections; i++)
            {
                var tsocket = new TSocket(connectionSettings.Host, connectionSettings.Port);
                var transport = new TBufferedTransport(tsocket, 1024);
                var protocol = new TBinaryProtocol(transport);
                var client = new Rest.Client(protocol);
                _clients.Enqueue(client);
            }
        }
        public ThriftConnection(IConnectionConfigurationValues connectionSettings)
        {
            this._connectionSettings = connectionSettings;
            this._timeout = connectionSettings.Timeout;
            this._poolSize = Math.Max(1, connectionSettings.MaximumAsyncConnections);

            this._resourceLock = new Semaphore(_poolSize, _poolSize);
            int seed; bool shouldPingHint;
            for (var i = 0; i <= connectionSettings.MaximumAsyncConnections; i++)
            {
                var uri = this._connectionSettings.ConnectionPool.GetNext(null, out seed, out shouldPingHint);
                var host = uri.Host;
                var port = uri.Port;
                var tsocket = new TSocket(host, port);
                var transport = new TBufferedTransport(tsocket, 1024);
                var protocol = new TBinaryProtocol(transport);
                var client = new Rest.Client(protocol);
                _clients.Enqueue(client);
            }
        }
		public ThriftConnection(IConnectionConfigurationValues connectionSettings)
		{
			this._connectionSettings = connectionSettings;
			this._timeout = connectionSettings.Timeout;
			var connectionPool = this._connectionSettings.ConnectionPool;
			var maximumConnections = Math.Max(1, connectionSettings.MaximumAsyncConnections);
			var maximumUrls = connectionPool.MaxRetries + 1;
			this._poolSize = maximumConnections;
			this._resourceLock = new Semaphore(_poolSize, _poolSize);

			int seed; int initialSeed = 0; bool shouldPingHint;

			for (var i = 0; i < maximumUrls; i++)
			{
				var uri = connectionPool.GetNext(initialSeed, out seed, out shouldPingHint);
				var queue = new ConcurrentQueue<Rest.Client>();
				for (var c = 0; c < maximumConnections; c++)
				{
					var host = uri.Host;
					var port = uri.Port;
					var tsocket = new TSocket(host, port);
					var transport = new TBufferedTransport(tsocket, 1024);
					var protocol = new TBinaryProtocol(transport);
					var client = new Rest.Client(protocol);
					tsocket.Timeout = this._connectionSettings.Timeout;
					tsocket.TcpClient.SendTimeout = this._connectionSettings.Timeout;
					tsocket.TcpClient.ReceiveTimeout = this._connectionSettings.Timeout;
					//tsocket.TcpClient.NoDelay = true;

					queue.Enqueue(client);

					initialSeed = seed;
				}
				_clients.TryAdd(uri, queue);
			}
		}
		protected override TTransport AcceptImpl()
		{
			if (server == null)
			{
				throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
			}
			try
			{
				TcpClient result = server.AcceptTcpClient();
				var result2 = new TSocket(result);
				result2.Timeout = clientTimeout;
				if (useBufferedSockets)
				{
					var result3 = new TBufferedTransport(result2);
					return result3;
				}
				else
				{
					return result2;
				}
			}
			catch (Exception ex)
			{
				throw new TTransportException(ex.ToString());
			}
		}
		private Rest.Client CreateClient(Uri uri, ConcurrentQueue<Rest.Client> queue)
		{
			var host = uri.Host;
			var port = uri.Port;
			var tsocket = new TSocket(host, port, this._connectionSettings.Timeout);
			var transport = new TBufferedTransport(tsocket, 1024);
			var protocol = _protocolFactory == null ? new TBinaryProtocol(transport) : _protocolFactory.GetProtocol(transport);

			var client = new Rest.Client(protocol);
			tsocket.ConnectTimeout = this._connectionSettings.ConnectTimeout.GetValueOrDefault(200);
			tsocket.Timeout = this._connectionSettings.Timeout;
			tsocket.TcpClient.SendTimeout = this._connectionSettings.Timeout;
			tsocket.TcpClient.ReceiveTimeout = this._connectionSettings.Timeout;
			tsocket.TcpClient.NoDelay = true;
			queue.Enqueue(client);
			return client;
		}