internal PooledStream GetConnection(object owningObject, GeneralAsyncDelegate asyncCallback, int creationTimeout)
{
int num;
PooledStream pooledStream = null;
bool continueLoop = true;
bool flag2 = asyncCallback != null;
if (this.m_State != State.Running)
{
throw new InternalException();
}
Interlocked.Increment(ref this.m_WaitCount);
WaitHandle[] waitHandles = this.m_WaitHandles;
if (!flag2)
{
while ((pooledStream == null) && continueLoop)
{
num = WaitHandle.WaitAny(waitHandles, creationTimeout, false);
pooledStream = this.Get(owningObject, num, ref continueLoop, ref waitHandles);
}
}
else
{
num = WaitHandle.WaitAny(waitHandles, 0, false);
if (num != 0x102)
{
pooledStream = this.Get(owningObject, num, ref continueLoop, ref waitHandles);
}
if (pooledStream == null)
{
AsyncConnectionPoolRequest asyncRequest = new AsyncConnectionPoolRequest(this, owningObject, asyncCallback, creationTimeout);
this.QueueRequest(asyncRequest);
}
}
if (pooledStream != null)
{
if (!pooledStream.IsInitalizing)
{
asyncCallback = null;
}
try
{
if (!pooledStream.Activate(owningObject, asyncCallback))
{
pooledStream = null;
}
return(pooledStream);
}
catch
{
this.PutConnection(pooledStream, owningObject, creationTimeout, false);
throw;
}
}
if (!flag2)
{
throw new InternalException();
}
return(pooledStream);
}