From 7a7d1224cff19d5c6ebdc8e87df39234d7974a20 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Sat, 16 Sep 2017 16:39:10 -0700 Subject: binding: gps: add gpsd.socket race condition fix Try up to 5 times with a 2500 ms interval to read data after a subscription to gpsd stream. This assures an initial connection to the gpsd.socket is in a known state. Bug-AGL: SPEC-832 Change-Id: Ice74c8372e2f592a353f1bd43ddde7d447ab0c8d Signed-off-by: Matt Ranostay --- binding/afm-gps-binding.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/binding/afm-gps-binding.c b/binding/afm-gps-binding.c index ffc787b..7fbd907 100644 --- a/binding/afm-gps-binding.c +++ b/binding/afm-gps-binding.c @@ -183,7 +183,7 @@ static void *data_poll(void *ptr) static int init() { const char *host, *port; - int ret; + int ret, tries = 5; location_event = afb_daemon_make_event("location"); @@ -196,6 +196,11 @@ static int init() gps_stream(&data, WATCH_ENABLE | WATCH_JSON, NULL); + // due to the gpsd.socket race condition need to loop till initial event + do { + gps_read(&data); + } while (!gps_waiting(&data, MSECS_TO_USECS(2500)) && tries--); + return pthread_create(&thread, NULL, &data_poll, NULL); } -- cgit 1.2.3-korg