From 695f55dbdd4851a276fae291dd2db9c558a06abd Mon Sep 17 00:00:00 2001 From: Shaw Berrington Date: Sat, 22 Jun 2024 23:15:36 +0200 Subject: [PATCH] Fixed issues when the response from the pipe is larger than the buffer size (issue https://github.com/medokin/soundpad-connector/issues/13) --- .../SoundpadConnector.IntegrationTests.csproj | 3 ++- src/SoundpadConnector/Soundpad.cs | 16 +++++++++++++--- src/SoundpadConnector/SoundpadConnector.csproj | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/SoundpadConnector.IntegrationTests/SoundpadConnector.IntegrationTests.csproj b/src/SoundpadConnector.IntegrationTests/SoundpadConnector.IntegrationTests.csproj index 29695bf..eef190a 100644 --- a/src/SoundpadConnector.IntegrationTests/SoundpadConnector.IntegrationTests.csproj +++ b/src/SoundpadConnector.IntegrationTests/SoundpadConnector.IntegrationTests.csproj @@ -1,7 +1,8 @@  - netcoreapp2.0 + netstandard2.0 + false diff --git a/src/SoundpadConnector/Soundpad.cs b/src/SoundpadConnector/Soundpad.cs index 3a462fd..d4bdfce 100644 --- a/src/SoundpadConnector/Soundpad.cs +++ b/src/SoundpadConnector/Soundpad.cs @@ -116,9 +116,19 @@ public void Disconnect() { await _pipe.WriteAsync(buffer, 0, buffer.Length); var responseBuffer = new byte[_pipe.OutBufferSize]; - await _pipe.ReadAsync(responseBuffer, 0, responseBuffer.Length); - - var responseText = Encoding.UTF8.GetString(responseBuffer).TrimEnd('\0'); + var fullResponse = new byte[0]; + var readBytes = 0; + do + { + readBytes = await _pipe.ReadAsync(responseBuffer, 0, responseBuffer.Length); + if (readBytes > 0) + { + Array.Resize(ref fullResponse, fullResponse.Length + readBytes); + Array.Copy(responseBuffer, 0, fullResponse, fullResponse.Length - readBytes, readBytes); + } + } while (readBytes > 0); + + var responseText = Encoding.UTF8.GetString(fullResponse).TrimEnd('\0'); var response = new TResponse(); response.Parse(responseText); diff --git a/src/SoundpadConnector/SoundpadConnector.csproj b/src/SoundpadConnector/SoundpadConnector.csproj index f17e276..41d86b8 100644 --- a/src/SoundpadConnector/SoundpadConnector.csproj +++ b/src/SoundpadConnector/SoundpadConnector.csproj @@ -9,6 +9,8 @@ https://github.com/medokin/soundpad-connector Nikodem Jaworski sdk,soundpad,pipe,ipc + 1.4.1 + 1.4.1