mirror of
https://github.com/koush/scrypted.git
synced 2026-09-21 03:00:40 +01:00
rpc: various python fixes
This commit is contained in:
@@ -41,12 +41,20 @@ async def readLoop(loop, peer: rpc.RpcPeer, reader: asyncio.StreamReader):
|
||||
'buffers': []
|
||||
}
|
||||
|
||||
if isinstance(reader, asyncio.StreamReader):
|
||||
async def read(n):
|
||||
return await reader.readexactly(n)
|
||||
else:
|
||||
async def read(n):
|
||||
return await reader.read(n)
|
||||
|
||||
|
||||
while True:
|
||||
lengthBytes = await reader.read(4)
|
||||
typeBytes = await reader.read(1)
|
||||
lengthBytes = await read(4)
|
||||
typeBytes = await read(1)
|
||||
type = typeBytes[0]
|
||||
length = int.from_bytes(lengthBytes, 'big')
|
||||
data = await reader.read(length - 1)
|
||||
data = await read(length - 1)
|
||||
|
||||
if type == 1:
|
||||
deserializationContext['buffers'].append(data)
|
||||
@@ -73,6 +81,7 @@ async def prepare_peer_readloop(loop: AbstractEventLoop, readFd: int = None, wri
|
||||
except Exception as e:
|
||||
if reject:
|
||||
reject(e)
|
||||
return None
|
||||
else:
|
||||
def write(buffers, reject):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user