From 691efaa8a12a4055719fd9fb1b91b46e1944c12a Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 29 Jan 2020 14:59:04 -0600 Subject: [PATCH] dont use result --- libp2p/connection.nim | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libp2p/connection.nim b/libp2p/connection.nim index f80631c..b8a71db 100644 --- a/libp2p/connection.nim +++ b/libp2p/connection.nim @@ -115,26 +115,25 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} = size: uint length: int res: VarintStatus - result = newSeq[byte](10) + buff = newSeq[byte](10) try: - for i in 0.. DefaultReadSize: raise newInvalidVarintException() - result.setLen(size) + buff.setLen(size) if size > 0.uint: trace "reading exact bytes from stream", size = size - await s.readExactly(addr result[0], int(size)) + await s.readExactly(addr buff[0], int(size)) + return buff except LPStreamIncompleteError as exc: trace "remote connection ended unexpectedly", exc = exc.msg - result.setLen(0) raise exc except LPStreamReadError as exc: trace "couldn't read from stream", exc = exc.msg - result.setLen(0) raise exc proc writeLp*(s: Connection, msg: string | seq[byte]): Future[void] {.gcsafe.} =