protected void PruneConnections(string threadName)
{
try
{
Thread.CurrentThread.Name = threadName;
Thread.Sleep(INITIALPRUNE_CONNECTIONS_DELAY);
while (!Closed)
{
bool checkComplete = false;
while (!checkComplete)
{
try
{
SIPConnection inactiveConnection = null;
Dictionary<string, SIPConnection> connections = GetConnectionsList();
lock (connections)
{
var inactiveConnectionKey = (from connection in connections
where connection.Value.LastTransmission < DateTime.Now.AddMinutes(PRUNE_NOTRANSMISSION_MINUTES * -1)
select connection.Key).FirstOrDefault();
if (inactiveConnectionKey != null)
{
inactiveConnection = connections[inactiveConnectionKey];
connections.Remove(inactiveConnectionKey);
}
}
if (inactiveConnection != null)
{
logger.Debug("Pruning inactive connection on " + SIPChannelContactURI + " to remote end point " + inactiveConnection.RemoteEndPoint.ToString() + ".");
inactiveConnection.Close();
}
else
{
checkComplete = true;
}
}
catch (SocketException)
{
// Will be thrown if the socket is already closed.
}
catch (Exception pruneExcp)
{
logger.Error("Exception PruneConnections (pruning). " + pruneExcp.Message);
checkComplete = true;
}
}
Thread.Sleep(PRUNE_CONNECTIONS_INTERVAL);
checkComplete = false;
}
logger.Debug("SIPChannel socket on " + m_localSIPEndPoint.ToString() + " pruning connections halted.");
}
catch (Exception excp)
{
logger.Error("Exception SIPChannel PruneConnections. " + excp.Message);
}
}