diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2018-12-27 05:39:42 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2018-12-27 05:39:42 -0500 |
commit | 1998c0301f6f9542bf5dd51e8d18f3d7f4e76023 (patch) | |
tree | 47b092141978039c773e4a4e9f992eab90ee340b /gps2udp.c | |
parent | e81cfb77ab1a8de2e7cac6883e632124bcbe6f35 (diff) | |
download | gpsd-1998c0301f6f9542bf5dd51e8d18f3d7f4e76023.tar.gz |
Factor most uses of pselect(2) into a new utility function named 'nanowait'.
Also, remove sime header inclusions discovered to be unnecessary during
the change.
Diffstat (limited to 'gps2udp.c')
-rw-r--r-- | gps2udp.c | 15 |
1 files changed, 3 insertions, 12 deletions
@@ -18,7 +18,7 @@ /* #if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L */ #ifdef __linux__ /* breaks osX */ -/* isfinite() and pselect() needs _POSIX_C_SOURCE >= 200112L */ +/* isfinite() needs _POSIX_C_SOURCE >= 200112L */ #define _POSIX_C_SOURCE 200112L #endif /* __linux__ */ @@ -50,6 +50,7 @@ #include "gpsdclient.h" #include "revision.h" #include "strfuncs.h" +#include "timespec.h" #define MAX_TIME_LEN 80 #define MAX_GPSD_RETRY 10 @@ -239,27 +240,17 @@ static void connect2gpsd(bool restart) static ssize_t read_gpsd(char *message, size_t len) /* get data from gpsd */ { - struct timespec tv; - fd_set fds,master; int ind; char c; int retry=0; - // prepare select structure */ - FD_ZERO(&master); - FD_SET(gpsdata.gps_fd, &master); - /* allow room for trailing NUL */ len--; /* loop until we get some data or an error */ for (ind = 0; ind < (int)len;) { - int result; /* prepare for a blocking read with a 10s timeout */ - tv.tv_sec = 10; - tv.tv_nsec = 0; - fds = master; - result = pselect(gpsdata.gps_fd+1, &fds, NULL, NULL, &tv, NULL); + int result = nanowait(gpsdata.gps_fd, 10 % NS_IN_SEC); switch (result) { |