summaryrefslogtreecommitdiffstats
path: root/src/libirecovery.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2024-09-25 01:30:35 +0200
committerGravatar Nikias Bassen2024-09-25 01:30:35 +0200
commit3eb4fbb0691df6ef76b4b04b9dccb9b6cf0d079d (patch)
tree554216855167653a4182d787ed06d71e22a5f353 /src/libirecovery.c
parent3039480107e77c08206fb42e202ec3d1ec3609c1 (diff)
downloadlibirecovery-3eb4fbb0691df6ef76b4b04b9dccb9b6cf0d079d.tar.gz
libirecovery-3eb4fbb0691df6ef76b4b04b9dccb9b6cf0d079d.tar.bz2
KIS: Add some retry loops around open/set config/set interface operations
Diffstat (limited to 'src/libirecovery.c')
-rw-r--r--src/libirecovery.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c
index efcb7b4..e25eb7d 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -2370,13 +2370,19 @@ static void* _irecv_handle_device_add(void *userdata)
if (product_id == KIS_PRODUCT_ID) {
IOObjectRetain(device);
-
- error = iokit_usb_open_service(&client, device);
+ int i = 0;
+ for (i = 0; i < 10; i++) {
+ error = iokit_usb_open_service(&client, device);
+ if (error == IRECV_E_SUCCESS) {
+ break;
+ }
+ debug("%s: Could not open KIS device, retrying...\n", __func__);
+ usleep(500000);
+ }
if (error != IRECV_E_SUCCESS) {
debug("%s: ERROR: could not open KIS device!\n", __func__);
return NULL;
}
-
product_id = client->mode;
} else {
CFStringRef serialString = (CFStringRef)IORegistryEntryCreateCFProperty(device, CFSTR(kUSBSerialNumberString), kCFAllocatorDefault, 0);
@@ -2429,14 +2435,29 @@ static void* _irecv_handle_device_add(void *userdata)
#endif /* !WIN32 */
memset(&client_loc, '\0', sizeof(client_loc));
if (product_id == KIS_PRODUCT_ID) {
- error = irecv_usb_set_configuration(client, 1);
+ int i = 0;
+ for (i = 0; i < 10; i++) {
+ error = irecv_usb_set_configuration(client, 1);
+ if (error == IRECV_E_SUCCESS) {
+ break;
+ }
+ debug("Failed to set configuration, error %d, retrying...\n", error);
+ usleep(500000);
+ }
if (error != IRECV_E_SUCCESS) {
debug("Failed to set configuration, error %d\n", error);
irecv_close(client);
return NULL;
}
- error = irecv_usb_set_interface(client, 0, 0);
+ for (i = 0; i < 10; i++) {
+ error = irecv_usb_set_interface(client, 0, 0);
+ if (error == IRECV_E_SUCCESS) {
+ break;
+ }
+ debug("Failed to set interface, error %d, retrying...\n", error);
+ usleep(500000);
+ }
if (error != IRECV_E_SUCCESS) {
debug("Failed to set interface, error %d\n", error);
irecv_close(client);