# SDL: Retry hid\_send\_feature\_report() if the ioctl() fails with EPIPE (e.g. the device stalled)

**URL:** <https://discourse.libsdl.org/t/sdl-retry-hid-send-feature-report-if-the-ioctl-fails-with-epipe-e-g-the-device-stalled/33437>\
**Category:** SDL Commits\
**Created:** [November 11, 2021, 10:38pm UTC](https://discourse.libsdl.org/t/sdl-retry-hid-send-feature-report-if-the-ioctl-fails-with-epipe-e-g-the-device-stalled/33437 "2021-11-11T22:38:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [November 11, 2021, 10:38pm UTC](https://discourse.libsdl.org/t/sdl-retry-hid-send-feature-report-if-the-ioctl-fails-with-epipe-e-g-the-device-stalled/33437/1 "2021-11-11T22:38:02Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/911d91c55c6539e32d21db64777d5e5c59b155e5>

```diff
From 911d91c55c6539e32d21db64777d5e5c59b155e5 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 11 Nov 2021 14:35:51 -0800
Subject: [PATCH] Retry hid_send_feature_report() if the ioctl() fails with
 EPIPE (e.g. the device stalled)

---
 src/hidapi/linux/hid.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/hidapi/linux/hid.c b/src/hidapi/linux/hid.c
index 2c7128f451..5fa2db4ba6 100644
--- a/src/hidapi/linux/hid.c
+++ b/src/hidapi/linux/hid.c
@@ -826,15 +826,23 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
 	return 0; /* Success */
 }
 
-
 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;
 
-	res = ioctl(dev->device_handle, HIDIOCSFEATURE(length), data);
-	if (res < 0)
- perror("ioctl (SFEATURE)");
+	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)
+ perror("ioctl (SFEATURE)");
+ break;
+	}
 	return res;
 }
 

```
