private void Reclaim(ISocket socket) {
if(_disposed) {
socket.Dispose();
return;
}
lock(_syncroot) {
if(!_busySockets.Remove(socket)) {
return;
}
if(socket.IsDisposed) {
// drop disposed sockets
socket.Dispose();
return;
}
// Try to hand the socket to the next client waiting in line
if(_waitingQueue.ProvideSocket(socket)) {
return;
}
if(_availableSockets.Count + _busySockets.Count >= MaxConnections) {
// drop socket if we've already hit the max
socket.Dispose();
return;
}
// Add reclaimed socket to end of available list
_availableSockets.Add(new Available(socket));
}
}