about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-22 20:14:08 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-22 20:14:19 +0100
commit78ffc938fa7e4baad0a55625026b765d215be1aa (patch)
tree857db2e963efb13933d1e7954e9d4dc657b6f11d /src/io
parentdef15ede4fbd686b0ee9b193f41b2a47190aa43a (diff)
downloadchawan-78ffc938fa7e4baad0a55625026b765d215be1aa.tar.gz
Replace Chakasu with Chagashi
The API is horrid :( but at least it copies less.

TODO: think of a better API.
Diffstat (limited to 'src/io')
-rw-r--r--src/io/posixstream.nim8
1 files changed, 7 insertions, 1 deletions
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)