[rhythmbox] mtp: if we can't open the device immediately, try again a few times



commit 52b51228da57bb70a5ca2029c87e4feda3e2a2df
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sat Mar 27 20:32:22 2010 +1000

    mtp: if we can't open the device immediately, try again a few times

 plugins/mtpdevice/rb-mtp-thread.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/plugins/mtpdevice/rb-mtp-thread.c b/plugins/mtpdevice/rb-mtp-thread.c
index 76bb07e..a2310b6 100644
--- a/plugins/mtpdevice/rb-mtp-thread.c
+++ b/plugins/mtpdevice/rb-mtp-thread.c
@@ -141,14 +141,22 @@ static void
 open_device (RBMtpThread *thread, RBMtpThreadTask *task)
 {
 	RBMtpOpenCallback cb = task->callback;
+	int retry;
 
 	/* open the device */
-	thread->device = LIBMTP_Open_Raw_Device (task->raw_device);
-	if (thread->device == NULL) {
-		/* hm. any error information we can give here? */
-		/* maybe retry a few times since apparently that can help? */
-		cb (NULL, task->user_data);
-		return;
+	rb_debug ("attempting to open retry device");
+	for (retry = 0; retry < 5; retry++) {
+		if (retry > 0) {
+			/* sleep a while before trying again */
+			g_usleep (G_USEC_PER_SEC);
+		}
+
+		thread->device = LIBMTP_Open_Raw_Device (task->raw_device);
+		if (thread->device != NULL) {
+			break;
+		}
+
+		rb_debug ("attempt %d failed..", retry+1);
 	}
 
 	cb (thread->device, task->user_data);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]