mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-10 23:20:55 +00:00
updated reading to read until you see a message for your stream (#100)
* updated reading to read until you see a message for your stream * added timeout to decode uvarint * resolved comments * shortened long line
This commit is contained in:
@ -29,12 +29,11 @@ def decode_uvarint(buff, index):
|
||||
|
||||
return result, index + 1
|
||||
|
||||
|
||||
async def decode_uvarint_from_stream(reader):
|
||||
async def decode_uvarint_from_stream(reader, timeout):
|
||||
shift = 0
|
||||
result = 0
|
||||
while True:
|
||||
byte = await asyncio.wait_for(reader.read(1), timeout=5)
|
||||
byte = await asyncio.wait_for(reader.read(1), timeout=timeout)
|
||||
i = struct.unpack('>H', b'\x00' + byte)[0]
|
||||
result |= (i & 0x7f) << shift
|
||||
shift += 7
|
||||
|
||||
Reference in New Issue
Block a user