From 78ffc938fa7e4baad0a55625026b765d215be1aa Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 22 Feb 2024 20:14:08 +0100 Subject: Replace Chakasu with Chagashi The API is horrid :( but at least it copies less. TODO: think of a better API. --- src/io/posixstream.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/io/posixstream.nim') diff --git a/src/io/posixstream.nim b/src/io/posixstream.nim index 683d72b8..c9c1c234 100644 --- a/src/io/posixstream.nim +++ b/src/io/posixstream.nim @@ -74,7 +74,13 @@ proc psClose(s: Stream) = proc psReadData(s: Stream, buffer: pointer, len: int): int = let s = PosixStream(s) assert len != 0 and s.blocking - return s.recvData(buffer, len) + result = 0 + while result < len: + let p = addr cast[ptr UncheckedArray[uint8]](buffer)[result] + let n = s.recvData(p, len - result) + if n == 0: + break + result += n proc psWriteData(s: Stream, buffer: pointer, len: int) = let s = PosixStream(s) -- cgit 1.4.1-2-gfad0