add jitter tolerance to mplex

This commit is contained in:
Dmitriy Ryajov 2020-03-11 09:12:08 -06:00
parent dc97595aad
commit 406b79887d
1 changed files with 3 additions and 2 deletions

View File

@ -57,8 +57,9 @@ proc readMsg*(conn: Connection): Future[Msg] {.async, gcsafe.} =
var data: seq[byte] = newSeq[byte](dataLenVarint.int)
if dataLenVarint.int > 0:
await conn.readExactly(addr data[0], dataLenVarint.int)
trace "read data", len = data.len
while data.len < dataLenVarint.int:
data &= await conn.read(dataLenVarint.int - data.len)
trace "read data", data = data
let header = headerVarint
result = (header shr 3, MessageType(header and 0x7), data)