Repository navigation
Expand file tree
/
Copy pathUpdate-ModuleWebSocketThread.ps1
More file actions
65 lines (52 loc) · 3.06 KB
/
Copy pathUpdate-ModuleWebSocketThread.ps1
File metadata and controls
65 lines (52 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<#
.SYNOPSIS
Update the global WebSocket thread state for the current runtime.
.DESCRIPTION
`Update-ModuleWebSocketThread` stores the active WebSocket thread values
(`Name`, `ClientWebSocket`, `CancellationTokenSource`) in
`$Global:IcingaForWindows.Private.WebSocket` via `Get-GlobalRuntimeVariable` so
other WebSocket helper functions in the same worker runspace can access the
current connection reference.
.PARAMETER Name
| Name | Type | Description | Default |
|------|---------------|------------------------------------------|---------|
| Name | System.String | Logical name of the WebSocket connection | |
.PARAMETER ClientWebSocket
| Name | Type | Description | Default |
|-----------------|---------------------------------------|----------------------------------|---------|
| ClientWebSocket | System.Net.WebSockets.ClientWebSocket | Active client WebSocket instance | |
.PARAMETER CancellationTokenSource
| Name | Type | Description | Default |
|-------------------------|------------------------------------------|-------------------------------------------------------|---------|
| CancellationTokenSource | System.Threading.CancellationTokenSource | Cancellation token source used to cancel reads/writes | |
.OUTPUTS
System.Object -- Returns structured `Write-FunctionReturnValue` status codes indicating success or validation failures.
.EXAMPLE
PS> Update-ModuleWebSocketThread -Name 'MyWebSocket' -ClientWebSocket $ws -CancellationTokenSource $cts
.NOTES
Populates thread-local `Private.WebSocket` state before reader or writer loops start.
SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com>
SPDX-License-Identifier: GPL-3.0-or-later
#>
function Update-ModuleWebSocketThread()
{
param (
[string]$Name = $null,
[System.Net.WebSockets.ClientWebSocket]$ClientWebSocket = $null,
[System.Threading.CancellationTokenSource]$CancellationTokenSource = $null
);
if ([string]::IsNullOrEmpty($Name)) {
return (Write-FunctionReturnValue -ReturnValue 'UpdateWebSocketNameEmpty');
}
if ($null -eq $ClientWebSocket) {
return (Write-FunctionReturnValue -ReturnValue 'UpdateWebSocketClientEmpty' -Data @{ 'Name' = $Name; } );
}
if ($null -eq $CancellationTokenSource) {
return (Write-FunctionReturnValue -ReturnValue 'UpdateWebSocketCancellationTokenSourceEmpty' -Data @{ 'Name' = $Name; } );
}
$GlobalVariable = Get-GlobalRuntimeVariable;
$GlobalVariable.Private.WebSocket.Name = $Name;
$GlobalVariable.Private.WebSocket.ClientWebSocket = $ClientWebSocket;
$GlobalVariable.Private.WebSocket.CancellationTokenSource = $CancellationTokenSource;
return (Write-FunctionReturnValue -ReturnValue 'WebSocketUpdatedSuccessfully' -Data @{ 'Name' = $Name; } );
}