diff options
Diffstat (limited to 'kvmd/clients/streamer.py')
-rw-r--r-- | kvmd/clients/streamer.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/kvmd/clients/streamer.py b/kvmd/clients/streamer.py index e5430ef7..7d572026 100644 --- a/kvmd/clients/streamer.py +++ b/kvmd/clients/streamer.py @@ -59,21 +59,6 @@ class BaseStreamerClient: yield -# ===== -def _patch_stream_reader(reader: aiohttp.StreamReader) -> None: - # https://github.com/pikvm/pikvm/issues/92 - # Infinite looping in BodyPartReader.read() because _at_eof flag. - - orig_read = reader.read - - async def read(self: aiohttp.StreamReader, n: int=-1) -> bytes: # pylint: disable=invalid-name - if self.is_eof(): - raise StreamerTempError("StreamReader.read(): Reached EOF") - return (await orig_read(n)) - - reader.read = types.MethodType(read, reader) # type: ignore - - class StreamerHttpClient(BaseStreamerClient): def __init__( self, @@ -102,7 +87,7 @@ class StreamerHttpClient(BaseStreamerClient): ) as response: htclient.raise_not_200(response) reader = aiohttp.MultipartReader.from_response(response) - _patch_stream_reader(reader.resp.content) + self.__patch_stream_reader(reader.resp.content) while True: frame = await reader.next() # pylint: disable=not-callable @@ -142,6 +127,19 @@ class StreamerHttpClient(BaseStreamerClient): assert not handle.startswith("/"), handle return f"http://{self.__host}:{self.__port}/{handle}" + def __patch_stream_reader(self, reader: aiohttp.StreamReader) -> None: + # https://github.com/pikvm/pikvm/issues/92 + # Infinite looping in BodyPartReader.read() because _at_eof flag. + + orig_read = reader.read + + async def read(self: aiohttp.StreamReader, n: int=-1) -> bytes: # pylint: disable=invalid-name + if self.is_eof(): + raise StreamerTempError("StreamReader.read(): Reached EOF") + return (await orig_read(n)) + + reader.read = types.MethodType(read, reader) # type: ignore + def __str__(self) -> str: return f"StreamerHttpClient({self.__name})" |