about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-20 21:27:47 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-20 21:27:47 +0100
commitc8e6d65b7979dc22dee3c51effd321f92ab17cd1 (patch)
tree00602b322081c8bd341fd552149f6c9d030f824b /src/io
parent4d82d078f95a9654d1d8f2d0c95880ed723790fb (diff)
downloadchawan-c8e6d65b7979dc22dee3c51effd321f92ab17cd1.tar.gz
buffer: also buffer reads for packets
Since we know the length of packets, we can also read them in in one
call. Though I really wish we could do this without the StringStream.
Diffstat (limited to 'src/io')
-rw-r--r--src/io/bufwriter.nim9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/io/bufwriter.nim b/src/io/bufwriter.nim
index 99c7ed94..57219100 100644
--- a/src/io/bufwriter.nim
+++ b/src/io/bufwriter.nim
@@ -48,10 +48,11 @@ proc deinit*(writer: var BufferedWriter) =
   writer.bufLen = 0
 
 template withWriter*(stream: DynStream; w, body: untyped) =
-  var w {.inject.} = stream.initWriter()
-  body
-  w.flush()
-  w.deinit()
+  block:
+    var w {.inject.} = stream.initWriter()
+    body
+    w.flush()
+    w.deinit()
 
 proc swrite*(writer: var BufferedWriter; n: SomeNumber)
 proc swrite*[T](writer: var BufferedWriter; s: set[T])