Skip to content

Commit 9796ccb

Browse files
committed
hidapi/linux: retry hid_send_feature_report() if the ioctl() fails with EPIPE (e.g. the device stalled)
Signed-off-by: Sam Lantinga <slouken@libsdl.org>
1 parent 97431dc commit 9796ccb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/hidapi/linux/hid.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,14 +1195,23 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
11951195

11961196
int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
11971197
{
1198+
static const int MAX_RETRIES = 50;
1199+
int retry;
11981200
int res;
11991201

12001202
register_device_error(dev, NULL);
12011203

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

1211+
if (res < 0)
1212+
register_device_error_format(dev, "ioctl (SFEATURE): %s", strerror(errno));
1213+
break;
1214+
}
12061215
return res;
12071216
}
12081217

0 commit comments

Comments
 (0)