about summary refs log tree commit diff stats
path: root/src/io/bufreader.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/bufreader.nim')
-rw-r--r--src/io/bufreader.nim10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/io/bufreader.nim b/src/io/bufreader.nim
index a8d30fb0..eca6b585 100644
--- a/src/io/bufreader.nim
+++ b/src/io/bufreader.nim
@@ -27,12 +27,14 @@ proc initReader*(stream: DynStream; len: int): BufferedReader =
       break
   return reader
 
+proc initPacketReader*(stream: DynStream): BufferedReader =
+  var len: int
+  stream.recvDataLoop(addr len, sizeof(len))
+  return stream.initReader(len)
+
 template withPacketReader*(stream: DynStream; r, body: untyped) =
   block:
-    var len: int
-    # note: this must be readData
-    doAssert stream.readData(addr len, sizeof(len)) == sizeof(len)
-    var r = stream.initReader(len)
+    var r = stream.initPacketReader()
     body
 
 proc sread*(reader: var BufferedReader; n: var SomeNumber)