address review comments

This commit is contained in:
Tanguy 2022-06-20 15:44:02 +02:00
parent 9b7e1c6515
commit 40ab9ff6d1
No known key found for this signature in database
GPG Key ID: 7DD8EC6B6CE6C45E
1 changed files with 3 additions and 8 deletions

View File

@ -44,14 +44,9 @@ method readOnce*(stream: QuicStream,
nbytes: int): Future[int] {.async.} =
if stream.cached.len == 0:
stream.cached = await mapExceptions(stream.stream.read())
if stream.cached.len <= nbytes:
copyMem(pbytes, addr stream.cached[0], stream.cached.len)
result = stream.cached.len
stream.cached = @[]
else:
copyMem(pbytes, addr stream.cached[0], nbytes)
result = nbytes
stream.cached = stream.cached[nbytes..^1]
result = min(nbytes, stream.cached.len)
copyMem(pbytes, addr stream.cached[0], result)
stream.cached = stream.cached[result..^1]
{.push warning[LockLevel]: off.}
method write*(stream: QuicStream, bytes: seq[byte]) {.async.} =