From 96feda06e11b37df4e1148de493570617af2bc2e Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Sat, 6 Jan 2024 03:47:04 +0600 Subject: [PATCH] fsp bug fix --- DTLib.Network/FSP.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/DTLib.Network/FSP.cs b/DTLib.Network/FSP.cs index f1c6f33..630da0b 100644 --- a/DTLib.Network/FSP.cs +++ b/DTLib.Network/FSP.cs @@ -37,7 +37,7 @@ public class FSP { filePath_client.ThrowIfEscapes(); using System.IO.Stream fileStream = File.OpenWrite(filePath_client); - Download_SharedCode(fileStream); + DownloadToStream(fileStream); } public byte[] DownloadFileToMemory(IOPath filePath_server) @@ -54,11 +54,11 @@ public class FSP public byte[] DownloadFileToMemory() { using var fileStream = new System.IO.MemoryStream(); - Download_SharedCode(fileStream); + DownloadToStream(fileStream); return fileStream.ToArray(); } - private void Download_SharedCode(System.IO.Stream fileStream) + public void DownloadToStream(System.IO.Stream fileStream) { lock (MainSocket) { @@ -67,13 +67,13 @@ public class FSP if (Filesize < 0) throw new Exception("FileSize < 0"); MainSocket.SendPackage("ready"); - int recievedCount; - do + + while (BytesDownloaded < Filesize) { - recievedCount = MainSocket.Receive(buffer); + int recievedCount = MainSocket.Receive(buffer); fileStream.Write(buffer, 0, recievedCount); BytesDownloaded += recievedCount; - } while (recievedCount == buffer.Length); + } if (BytesDownloaded != Filesize) throw new Exception($"expected {Filesize} bytes, but downloaded {BytesDownloaded} bytes"); @@ -91,13 +91,13 @@ public class FSP { MainSocket.SendPackage(BitConverter.GetBytes(Filesize)); MainSocket.GetAnswer("ready"); - int readCount; - do + + while (BytesUploaded < Filesize) { - readCount = fileStream.Read(buffer, 0, buffer.Length); + int readCount = fileStream.Read(buffer, 0, buffer.Length); MainSocket.Send(buffer, 0, readCount, SocketFlags.None); BytesUploaded += readCount; - } while (readCount == buffer.Length); + } if (BytesUploaded != Filesize) throw new Exception($"expected {Filesize} bytes, but uploaded {BytesDownloaded} bytes");