From e446a45a6c98535ef47d5a1aa044c8cc5e91f29d Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 30 Nov 2023 09:42:58 +0000 Subject: [PATCH] upd {base}.send method. If only a single fragment expected, don't use string array --- lib/base.ps1 | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/base.ps1 b/lib/base.ps1 index b046850..7b065ad 100644 --- a/lib/base.ps1 +++ b/lib/base.ps1 @@ -38,22 +38,16 @@ class Base { [string] _send([string]$msg) { $this._socket.Send($this.request.Payload($msg)) - [string[]]$data = @() - $sw = [Diagnostics.Stopwatch]::StartNew() - While ($sw.ElapsedMilliseconds -lt 50) { - try { - $buf = New-Object System.Byte[] 4096 - $this._socket.Receive($buf) - $data += [System.Text.Encoding]::ASCII.GetString($($buf | Select-Object -Skip $($this.response.Header().Length - 1))) - } - catch [System.Net.Sockets.SocketException] { - if ( $_.Exception.SocketErrorCode -eq 'TimedOut' ) { - "finished waiting for fragment" | Write-Debug - } + $buf = New-Object System.Byte[] 4096 + try { + $this._socket.Receive($buf) + } + catch [System.Net.Sockets.SocketException] { + if ( $_.Exception.SocketErrorCode -eq 'TimedOut' ) { + "finished waiting for fragment" | Write-Debug } } - $sw.Stop() - return [string]::Join("", $data) + return [System.Text.Encoding]::ASCII.GetString($($buf | Select-Object -Skip $($this.response.Header().Length - 1))) } [string] _send([string]$msg, [int]$timeout) { @@ -73,6 +67,7 @@ class Base { } } } + $sw.Stop() return [string]::Join("", $data) }