summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-05-26 21:40:24 +0300
committerDevaev Maxim <[email protected]>2020-05-26 21:40:24 +0300
commitb1872289cb4f3574ade4716c45f9ac7e976b6cb0 (patch)
tree4104f4dc910949ce1d4475a3906cac1d7a1fb4cb
parent00bf4a2ab113bbbd061c7b3d011e040bd9297cd5 (diff)
fixed eof handling
-rw-r--r--kvmd/clients/streamer.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/kvmd/clients/streamer.py b/kvmd/clients/streamer.py
index 72e2060f..91267bef 100644
--- a/kvmd/clients/streamer.py
+++ b/kvmd/clients/streamer.py
@@ -61,20 +61,24 @@ class StreamerClient:
) as response:
aiotools.raise_not_200(response)
reader = aiohttp.MultipartReader.from_response(response)
+
while True:
frame = await reader.next() # pylint: disable=not-callable
if not isinstance(frame, aiohttp.BodyPartReader):
raise RuntimeError("Expected body part")
+
if hasattr(frame, "_content"):
- # FIXME: An ugly workaround for:
- # Multiple access to StreamReader in eof state, might be infinite loop
if frame._content.is_eof(): # pylint: disable=protected-access
break
+ data = bytes(await frame.read())
+ if not data:
+ break
+
yield (
(frame.headers["X-UStreamer-Online"] == "true"),
int(frame.headers["X-UStreamer-Width"]),
int(frame.headers["X-UStreamer-Height"]),
- bytes(await frame.read()),
+ data,
)
except Exception as err: # Тут бывают и ассерты, и KeyError, и прочая херня из-за корявых исключений в MultipartReader
raise StreamerError(f"{type(err).__name__}: {err}")