Skip to content

libusb: prevent input report loss and expose queue statistics - #837

Open
stman wants to merge 8 commits into
libusb:masterfrom
stman:fix/libusb-input-report-overflow
Open

stman wants to merge 8 commits into
libusb:masterfrom
stman:fix/libusb-input-report-overflow

Conversation

@stman

@stman stman commented Oct 21, 2026

Copy link
Copy Markdown

libusb: retain 1024 input reports and expose native queue loss counters

Bursty input can overflow the small libusb receive queue and silently discard old
reports. Port the locally validated 1024-report limit, received/dropped/peak
counters, mutex-protected hid_get_queue_stats() snapshot and close-time logging.
The existing queue and oldest-report discard policy are preserved. Peak depth is
measured before eviction and can reach 1025. Other backends return unsupported;
existing APIs retain their behavior.

The original hardware validation transferred 22658 reports with zero drops and
matching Python/C counters. New Linux checks compile both native backends and
exercise the actual callback using mocked USB operations: overflow boundary,
FIFO retention, invalid pointers and a 22658-report zero-drop synthetic run.
Address/undefined sanitizers passed with leak detection disabled due to sandbox
tracing restrictions. No hardware was accessed. Native builds used cc because
CMake/Autotools are unavailable. Other platforms need CI.

Companion Python contribution: stman/cython-hidapi branch feat/libusb-queue-stats.

Assisted-by: Codex:GPT-6

@mcuee mcuee added the enhancement New feature or request label Oct 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants