Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ] core: retry connect_dbus() several times
@ 2014-02-28  7:09 Adam Lee
  2014-02-28  7:15 ` Marcel Holtmann
  0 siblings, 1 reply; 7+ messages in thread
From: Adam Lee @ 2014-02-28  7:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Marcel Holtmann

Sometimes the hardware, especially which needs firmware patching, is not
yet ready when connect_dbus().

Signed-off-by: Adam Lee <adam8157@gmail.com>
---
 src/main.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/main.c b/src/main.c
index b3136fc..cf1f8fa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -491,6 +491,7 @@ int main(int argc, char *argv[])
 	GKeyFile *config;
 	guint signal, watchdog;
 	const char *watchdog_usec;
+	uint8_t reconnect_times = 3;
 
 	init_defaults();
 
@@ -527,9 +528,17 @@ int main(int argc, char *argv[])
 
 	parse_config(config);
 
-	if (connect_dbus() < 0) {
-		error("Unable to get on D-Bus");
-		exit(1);
+	/* Reconnect several times in case the hardware is not ready */
+	while (reconnect_times--) {
+		if (connect_dbus() == 0)
+			break;
+
+		if (reconnect_times != 1) {
+			usleep(500 * 1000);
+		} else {
+			error("Unable to get on D-Bus");
+			exit(1);
+		}
 	}
 
 	if (option_experimental)
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-03-03  7:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-28  7:09 [PATCH BlueZ] core: retry connect_dbus() several times Adam Lee
2014-02-28  7:15 ` Marcel Holtmann
2014-02-28  7:31   ` Adam Lee
2014-02-28  7:40     ` Marcel Holtmann
2014-02-28 12:22     ` Anderson Lizardo
2014-02-28 14:10       ` Luiz Augusto von Dentz
2014-03-03  7:15         ` Adam Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox