summaryrefslogtreecommitdiff
path: root/libgps_core.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-03-09 01:50:53 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-03-09 01:50:53 -0500
commit2663033714a98a9c9ea1165c330371b949faec0d (patch)
tree0090a6f172564371681b899f2a8663b2b78cf752 /libgps_core.c
parent9d6dc2f1f95d0179c6175955c3dae0c5299e9a78 (diff)
downloadgpsd-2663033714a98a9c9ea1165c330371b949faec0d.tar.gz
Give gps_waiting() a timeout argument. Use it systematically in test clients.
cgps and gpxlogger are live-tested and work. All regression tests pass.
Diffstat (limited to 'libgps_core.c')
-rw-r--r--libgps_core.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libgps_core.c b/libgps_core.c
index 886b7eca..533aaec3 100644
--- a/libgps_core.c
+++ b/libgps_core.c
@@ -499,21 +499,24 @@ int gps_unpack(char *buf, struct gps_data_t *gpsdata)
/*@ +compdef @*/
/*@ -branchstate +usereleased +mustfreefresh +nullstate +usedef @*/
-bool gps_waiting(struct gps_data_t * gpsdata)
+bool gps_waiting(struct gps_data_t * gpsdata, int timeout)
/* is there input waiting from the GPS? */
{
#ifndef USE_QT
fd_set rfds;
struct timeval tv;
- libgps_debug_trace((DEBUG_CALLS, "gps_waiting(): %d\n", waitcount++));
+ libgps_debug_trace((DEBUG_CALLS, "gps_waiting(%d): %d\n", timeout, waitcount++));
if (gpsdata->waiting > 0)
return true;
+ /* we might want to check for EINTR if this returns false */
+ errno = 0;
+
FD_ZERO(&rfds);
FD_SET(gpsdata->gps_fd, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 1;
+ tv.tv_sec = timeout / 1000000;
+ tv.tv_usec = timeout % 1000000;
/* all error conditions return "not waiting" -- crude but effective */
return (select(gpsdata->gps_fd + 1, &rfds, NULL, NULL, &tv) == 1);
#else