icinga-powershell-framework/lib/webserver/Close-IcingaTCPConnection.psm1

41 lines
939 B
PowerShell
Raw Normal View History

2020-03-24 07:42:14 -04:00
function Close-IcingaTCPConnection()
{
param(
[hashtable]$Connection = @{ }
2020-03-24 07:42:14 -04:00
);
if ($null -eq $Connection -Or $Connection.Count -eq 0) {
$Connection = $null;
2020-03-24 07:42:14 -04:00
return;
}
Write-IcingaDebugMessage -Message (
[string]::Format(
'Closing client connection for endpoint {0}',
(Get-IcingaTCPClientRemoteEndpoint -Client $Connection.Client)
)
);
try {
if ($null -ne $Connection.Stream) {
$Connection.Stream.Close();
$Connection.Stream.Dispose();
$Connection.Stream = $null;
}
} catch {
$Connection.Stream = $null;
}
try {
if ($null -ne $Connection.Client) {
$Connection.Client.Close();
$Connection.Client.Dispose();
$Connection.Client = $null;
}
} catch {
$Connection.Client = $null;
}
$Connection = $null;
2020-03-24 07:42:14 -04:00
}