public HmuxConnection OpenAnyServer(Server xChannelFactory)
{
int serverCount = _servers.Length;
Server server = null;
HmuxConnection connection = null;
int id = 0;
lock (this) {
_roundRobinIdx = _roundRobinIdx % serverCount;
id = _roundRobinIdx;
_roundRobinIdx++;
}
server = _servers[id];
connection = server.OpenConnection();
if (connection != null)
{
return(connection);
}
lock (this) {
_roundRobinIdx = _random.Next(serverCount);
for (int i = 0; i < serverCount; i++)
{
id = (i + _roundRobinIdx) % serverCount;
server = _servers[id];
if (xChannelFactory != server || serverCount == 1)
{
connection = server.OpenConnection();
}
_roundRobinIdx = id;
if (connection != null)
{
break;
}
}
}
Trace.TraceInformation("open any server {0}", connection);
return(connection);
}