Treat empty hidraw read as device removal (EOF)

When select() reports a hidraw fd as readable but os.read() returns
empty bytes, that's EOF per POSIX — the device has been removed.
Previously this was silently treated as no data, causing the listener
to loop indefinitely on a gone device instead of cleaning up.
This commit is contained in:
Ken Sanislo 2026-03-10 21:23:33 -07:00
parent 5478224cfa
commit bed4a34d18
1 changed files with 2 additions and 0 deletions

View File

@ -403,6 +403,8 @@ def read(device_handle, bytes_count, timeout_ms=-1):
data = os.read(device_handle, bytes_count)
assert data is not None
assert isinstance(data, bytes), (repr(data), type(data))
if not data: # empty read when select() said readable means EOF (device removed)
raise OSError(errno.EIO, f"device disconnected on file descriptor {int(device_handle)}")
return data
else:
return b""