From 15bae7bec5cc077e09f861e13c307cad0a00dce5 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 25 Sep 2019 14:13:22 -0600 Subject: [PATCH] use `result` instead of buffer --- libp2p/connection.nim | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libp2p/connection.nim b/libp2p/connection.nim index cef8373..b054415 100644 --- a/libp2p/connection.nim +++ b/libp2p/connection.nim @@ -84,23 +84,20 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} = size: uint length: int res: VarintStatus - var buffer = newSeq[byte](10) + result = newSeq[byte](10) try: - for i in 0.. DefaultReadSize: - result = buffer return - buffer.setLen(size) + result.setLen(size) if size > 0.uint: - await s.readExactly(addr buffer[0], int(size)) + await s.readExactly(addr result[0], int(size)) except LPStreamIncompleteError, LPStreamReadError: error "readLp: could not read from remote", exception = getCurrentExceptionMsg() - - result = buffer proc writeLp*(s: Connection, msg: string | seq[byte]): Future[void] {.gcsafe.} = ## write lenght prefixed