upd {base}.send method.

If only a single fragment expected, don't use string array
This commit is contained in:
onyx-and-iris 2023-11-30 09:42:58 +00:00
parent 61f7afb9f7
commit e446a45a6c

View File

@ -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
try {
$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
}
}
}
$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)
}