Automatically close open handle when no device detected

Prior to this change, libx52_vendor_command would leave the device
handle untouched, even if the joystick was disconnected.

This change will force applications to reconnect to the joystick after
they encounter such a failure.
pull/22/head
nirenjan 2020-06-08 16:23:11 -07:00
parent cdd5e773e2
commit 0cf977b751
1 changed files with 8 additions and 0 deletions

View File

@ -89,6 +89,14 @@ int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value)
}
}
/* Handle device removal */
if (rc == LIBUSB_ERROR_NO_DEVICE) {
/* Physical device has likely been disconnected, disconnect the virtual
* handle, and report the failure.
*/
(void)libx52_disconnect(x52);
}
return _x52_translate_libusb_error(rc);
}