dont use result

This commit is contained in:
Dmitriy Ryajov 2020-01-29 14:59:04 -06:00
parent 171d60fb52
commit 691efaa8a1
1 changed files with 7 additions and 8 deletions

View File

@ -115,26 +115,25 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} =
size: uint size: uint
length: int length: int
res: VarintStatus res: VarintStatus
result = newSeq[byte](10) buff = newSeq[byte](10)
try: try:
for i in 0..<len(result): for i in 0..<len(buff):
await s.readExactly(addr result[i], 1) await s.readExactly(addr buff[i], 1)
res = LP.getUVarint(result.toOpenArray(0, i), length, size) res = LP.getUVarint(buff.toOpenArray(0, i), length, size)
if res == VarintStatus.Success: if res == VarintStatus.Success:
break break
if res != VarintStatus.Success or size > DefaultReadSize: if res != VarintStatus.Success or size > DefaultReadSize:
raise newInvalidVarintException() raise newInvalidVarintException()
result.setLen(size) buff.setLen(size)
if size > 0.uint: if size > 0.uint:
trace "reading exact bytes from stream", size = size 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: except LPStreamIncompleteError as exc:
trace "remote connection ended unexpectedly", exc = exc.msg trace "remote connection ended unexpectedly", exc = exc.msg
result.setLen(0)
raise exc raise exc
except LPStreamReadError as exc: except LPStreamReadError as exc:
trace "couldn't read from stream", exc = exc.msg trace "couldn't read from stream", exc = exc.msg
result.setLen(0)
raise exc raise exc
proc writeLp*(s: Connection, msg: string | seq[byte]): Future[void] {.gcsafe.} = proc writeLp*(s: Connection, msg: string | seq[byte]): Future[void] {.gcsafe.} =