From d521bb91e82acfc81bf1aa3b9e9c3d7d90713a97 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 15 Apr 2020 12:12:40 -0600 Subject: [PATCH] use readOnce --- libp2p/streams/chronosstream.nim | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/libp2p/streams/chronosstream.nim b/libp2p/streams/chronosstream.nim index 7c1483f8a..e4da9c64b 100644 --- a/libp2p/streams/chronosstream.nim +++ b/libp2p/streams/chronosstream.nim @@ -7,19 +7,23 @@ ## This file may not be copied, modified, or distributed except according to ## those terms. +# {.push raises: [].} + import chronos, chronicles -import stream, ringbuffer +import stream logScope: topic = "ChronosStream" const DefaultChunkSize* = 1 shl 20 # 1MB +# const DefaultChunkSize* = 10 type ChronosStream* = ref object of Stream reader: AsyncStreamReader writer: AsyncStreamWriter server: StreamServer client: StreamTransport + eof: bool buffer: seq[byte] maxChunkSize: int @@ -36,14 +40,18 @@ proc init*(C: type[ChronosStream], buffer: newSeq[byte](maxChunkSize)) proc internalRead(c: ChronosStream): Future[seq[byte]] {.async.} = - var buff = newSeq[byte](1024) - var read = await c.reader.readOnce(unsafeAddr buff[0], buff.len) - result = buff[0..