libusb: add configurable write and report timeouts #832
No reviewers
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi!832
Loading…
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add libusb-specific timeout setters for
hid_write(),hid_send_output_report(), andhid_send_feature_report().Each operation keeps its existing 1000 ms default. A timeout of 0 waits indefinitely, matching libusb semantics. Control-endpoint fallback writes use the configured
hid_write()timeout, while direct output-report and feature-report operations use their respective settings.Thanks for the contribution!
This kind of mirrors the
hid_winapi_set_write_timeout, excepthid_winapi_set_write_timeoutonly changes the timeout forhid_writewhilehid_libusb_set_write_timeoutchanges timtout for all ofhid_write,hid_send_feature_reportandhid_send_output_report.I get that most likely it doesn't make much sense to configure those separately (does it?), but I don't like the idea of having a similar configuration function (with similar name) but with slightly different behavior. And updating Windows implementation to update all 3 timeouts is not as trivial as one might expect.
@mbcinergy what are you thoughs on this?
I thought it made sense to use it for all writing functions, as the name suggests. The function i need it in is actually
hid_send_output_report, which for libusb backend is also used byhid_write. So they are more or less connected together functionality wise.I don't think it makes sense to use different timeouts for
hid_send_feature_reporteither. We could leave it at fixed 1000ms, but IMO that would be strange behaviour as well.With winapi backend there is another thing, because the
hid_send_output_reportfunctions usesHidD_SetOutputReportwhich has a fixed 5000ms timeout. This is already different than the default 1000ms for libusb backend. Not sure how you could change that.We could add a separate timeout parameter for the reading functions, but that might be something for another PR. I have left the reading functions with the default 1000ms for now (and we already have
hid_read_timeout).That can be changed by using DeviceIOControl directly, instead of using HidD_SetOutputReport wrapper, but that would be a separate change
I don't believe that's the case. It is for macOS backend, but for libusb backend all 3 functions have their own implementation with a separate
libusb_control_transferinvocationLets introduce 3 separate:
hid_libusb_set_write_timeouthid_libusb_set_send_output_report_timeouthid_libusb_set_send_feature_report_timeoutThis way it will be a 100% clear what is going on and what it controls.
And we can match the implementation for other backends in the future.
for libusb backend the
hid_writeuses thehid_send_output_reportfunction when there is no interrupt out endpoint.I'm fine with adding separate timeout functions, but in this case
hid_writewould actually use the output_report_timeout instead when there is no interrupt out endpoint.Ah right, that case...
Then lets extract
static int hidapi_internal_send_output_reportwhich explicitly accepts the timeout parameter. And use it from bothhid_writeandhid_send_output_reportThis looks fine. I'll run AI review before merging
Interesting fact: I presume this entire code was handwritten by a human (@mbcinergy), but I asked codex to update the PR description and make a merge-commit, so it did and added codex annotation to the commit message body.
That is technically correct, but no code was actually touched by codex in this instance.
Yes it was written by a simple mortal human being (a.k.a. me). Thanks for the quick merge!