2020-03-24 07:42:14 -04:00
|
|
|
function New-IcingaTCPSocket()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[int]$Port = 0,
|
|
|
|
|
[switch]$Start = $FALSE
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($Port -eq 0) {
|
|
|
|
|
throw 'Please specify a valid port to open a TCP socket for';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$TCPSocket = [System.Net.Sockets.TcpListener]$Port;
|
|
|
|
|
|
2020-03-24 10:32:14 -04:00
|
|
|
Write-IcingaDebugMessage -Message (
|
|
|
|
|
[string]::Format(
|
|
|
|
|
'Creating new TCP socket on Port {0}. Endpoint configuration {1}',
|
|
|
|
|
$Port,
|
|
|
|
|
$TCPSocket.LocalEndpoint
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2020-03-24 07:42:14 -04:00
|
|
|
if ($Start) {
|
2020-03-24 10:32:14 -04:00
|
|
|
Write-IcingaDebugMessage -Message (
|
|
|
|
|
[string]::Format(
|
|
|
|
|
'Starting TCP socket for endpoint {0}',
|
|
|
|
|
$TCPSocket.LocalEndpoint
|
|
|
|
|
)
|
|
|
|
|
);
|
2020-03-24 07:42:14 -04:00
|
|
|
$TCPSocket.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $TCPSocket;
|
|
|
|
|
}
|