From 8152c0a6df79bd1576d3f381d1582b14c9fabef9 Mon Sep 17 00:00:00 2001 From: Dan Nguyen Date: Mon, 6 Sep 2021 04:28:13 +0700 Subject: [PATCH] tcp retry on connection fail --- gpsd/libgpsd_core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gpsd/libgpsd_core.c b/gpsd/libgpsd_core.c index 37fdc92..38a51b1 100644 --- a/gpsd/libgpsd_core.c +++ b/gpsd/libgpsd_core.c @@ -487,6 +487,8 @@ int parse_uri_dest(char *s, char **host, char **service, char **device) return 0; } +extern bool __attribute__ ((weak)) gpsd_add_device(const char *device_name, + bool flag_nowait); /* open a device for access to its data * * return: the opened file descriptor * PLACEHOLDING_FD - for /dev/ppsX @@ -524,6 +526,12 @@ int gpsd_open(struct gps_device_t *session) GPSD_LOG(LOG_ERROR, &session->context->errout, "TCP device open error %s.\n", netlib_errstr(dsock)); + /* this connection will be freed, to retry we need to add back a cloned device */ + if (gpsd_add_device != NULL) { + GPSD_LOG(LOG_INF, &session->context->errout, + "retry TCP feed at %s, port %s.\n", host, port); + (void) gpsd_add_device(session->gpsdata.dev.path, false); + } return -1; } else GPSD_LOG(LOG_SPIN, &session->context->errout, -- 2.7.4