Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hidapi/linux: retry hid_send_feature_report() if the ioctl() fails with EPIPE (e.g. the device stalled) #579

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions linux/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,14 +1172,23 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)

int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
{
static const int MAX_RETRIES = 50;
int retry;
int res;

register_device_error(dev, NULL);

res = ioctl(dev->device_handle, HIDIOCSFEATURE(length), data);
if (res < 0)
register_device_error_format(dev, "ioctl (SFEATURE): %s", strerror(errno));
for (retry = 0; retry < MAX_RETRIES; ++retry) {
res = ioctl(dev->device_handle, HIDIOCSFEATURE(length), data);
if (res < 0 && errno == EPIPE) {
/* Try again... */
continue;
}

if (res < 0)
register_device_error_format(dev, "ioctl (SFEATURE): %s", strerror(errno));
break;
}
return res;
}

Expand Down
Loading