Skip to content

Commit b35d813

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 7c65c9d commit b35d813

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
@@ -1176,14 +1176,23 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
11761176

11771177
int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
11781178
{
1179+
static const int MAX_RETRIES = 50;
1180+
int retry;
11791181
int res;
11801182

11811183
register_device_error(dev, NULL);
11821184

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

1192+
if (res < 0)
1193+
register_device_error_format(dev, "ioctl (SFEATURE): %s", strerror(errno));
1194+
break;
1195+
}
11871196
return res;
11881197
}
11891198

0 commit comments

Comments
 (0)