summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clockwatcher.c24
-rw-r--r--gpxlogger.c12
-rw-r--r--libgps_shm.c3
-rw-r--r--libgps_sock.c4
4 files changed, 10 insertions, 33 deletions
diff --git a/clockwatcher.c b/clockwatcher.c
index e1191972..85d890c8 100644
--- a/clockwatcher.c
+++ b/clockwatcher.c
@@ -43,9 +43,11 @@ static time_t timeout;
static int debug;
#endif /* CLIENTDEBUG_ENABLE */
-static void conditionally_log_fix(struct gps_data_t *gpsdata UNUSED)
+static int conditionally_log_fix(struct gps_data_t *gpsdata UNUSED,
+ bool fix UNUSED)
{
/* time logging goes here */
+ return 0;
}
static void quit_handler(int signum)
@@ -97,16 +99,7 @@ static int socket_mainloop(void)
if (source.device != NULL)
flags |= WATCH_DEVICE;
(void)gps_stream(&gpsdata, flags, source.device);
-
- for (;;) {
- if (!gps_waiting(&gpsdata, 5000000)) {
- (void)fprintf(stderr, "%s: error while waiting\n", progname);
- break;
- } else {
- (void)gps_read(&gpsdata);
- conditionally_log_fix(&gpsdata);
- }
- }
+ gps_sock_mainloop(&gpsdata, 5000000, conditionally_log_fix);
(void)gps_close(&gpsdata);
return 0;
}
@@ -131,14 +124,7 @@ static int shm_mainloop(void)
return 1;
}
- for (;;) {
- status = gps_read(&gpsdata);
-
- if (status == -1)
- break;
- if (status > 0)
- conditionally_log_fix(&gpsdata);
- }
+ gps_shm_mainloop(&gpsdata, 0, conditionally_log_fix);
(void)gps_close(&gpsdata);
return 0;
}
diff --git a/gpxlogger.c b/gpxlogger.c
index f9e35bb5..46a2fe93 100644
--- a/gpxlogger.c
+++ b/gpxlogger.c
@@ -230,6 +230,7 @@ static int socket_mainloop(void)
print_gpx_header();
gps_sock_mainloop(&gpsdata, 5000000, conditionally_log_fix);
print_gpx_footer();
+ (void)gps_sock_close(&gpsdata);
return 0;
}
/*@+mustfreefresh +compdestroy@*/
@@ -254,16 +255,9 @@ static int shm_mainloop(void)
}
print_gpx_header();
- for (;;) {
- status = gps_read(&gpsdata);
-
- if (status == -1)
- break;
- if (status > 0)
- conditionally_log_fix(&gpsdata, true);
- }
+ gps_shm_mainloop(&gpsdata, 0, conditionally_log_fix);
print_gpx_footer();
- (void)gps_close(&gpsdata);
+ (void)gps_shm_close(&gpsdata);
return 0;
}
diff --git a/libgps_shm.c b/libgps_shm.c
index 61690d1c..065fd6f0 100644
--- a/libgps_shm.c
+++ b/libgps_shm.c
@@ -127,8 +127,7 @@ int gps_shm_mainloop(struct gps_data_t *gpsdata, int timeout,
if ((*hook)(gpsdata, false) != 0)
break;
} else {
- (void)gps_shm_read(gpsdata);
- if ((*hook)(gpsdata, true) != 0)
+ if (gps_shm_read(gpsdata) == -1 && (*hook)(gpsdata, true) != 0)
break;
}
}
diff --git a/libgps_sock.c b/libgps_sock.c
index cc4c8234..f9551940 100644
--- a/libgps_sock.c
+++ b/libgps_sock.c
@@ -574,12 +574,10 @@ int gps_sock_mainloop(struct gps_data_t *gpsdata, int timeout,
if ((*hook)(gpsdata, false) != 0)
break;
} else {
- (void)gps_sock_read(gpsdata);
- if ((*hook)(gpsdata, true) != 0)
+ if (gps_sock_read(gpsdata) == -1 || (*hook)(gpsdata, true) != 0)
break;
}
}
- (void)gps_close(gpsdata);
return 0;
}