summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver_geostar.c14
-rw-r--r--driver_tsip.c12
-rw-r--r--gps2udp.c15
-rw-r--r--gpsd.c4
-rw-r--r--gpsd.h2
-rw-r--r--gpsmon.c3
-rw-r--r--gpspipe.c2
-rw-r--r--gpsutils.c19
-rw-r--r--libgps_sock.c13
-rw-r--r--libgpsd_core.c2
10 files changed, 34 insertions, 52 deletions
diff --git a/driver_geostar.c b/driver_geostar.c
index 5bacbfcf..25b61bde 100644
--- a/driver_geostar.c
+++ b/driver_geostar.c
@@ -11,11 +11,10 @@
*/
#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L
-/* isfinite() and pselect() needs _POSIX_C_SOURCE >= 200112L */
+/* isfinite() needs _POSIX_C_SOURCE >= 200112L */
#define _POSIX_C_SOURCE 200112L
#endif /* _POSIX_C_SOURCE */
-#include <sys/time.h> /* for pselect() */
#include <stdbool.h>
#include <stdio.h>
#include <math.h>
@@ -24,8 +23,7 @@
#include "gpsd.h"
#include "bits.h"
#include "strfuncs.h"
-
-#include <sys/select.h>
+#include "timespec.h"
#ifdef GEOSTAR_ENABLE
#define GEOSTAR_CHANNELS 24
@@ -91,8 +89,6 @@ static bool geostar_detect(struct gps_device_t *session)
unsigned char buf[1 * 4];
bool ret = false;
int myfd;
- fd_set fdset;
- struct timespec to;
myfd = session->gpsdata.gps_fd;
@@ -101,11 +97,7 @@ static bool geostar_detect(struct gps_device_t *session)
if (geostar_write(session, 0xc1, buf, 1) == 0) {
unsigned int n;
for (n = 0; n < 3; n++) {
- FD_ZERO(&fdset);
- FD_SET(myfd, &fdset);
- to.tv_sec = 1;
- to.tv_nsec = 0;
- if (pselect(myfd + 1, &fdset, NULL, NULL, &to, NULL) != 1)
+ if (!nanowait(myfd, NS_IN_SEC))
break;
if (generic_get(session) >= 0) {
if (session->lexer.type == GEOSTAR_PACKET) {
diff --git a/driver_tsip.c b/driver_tsip.c
index cb30394b..55010584 100644
--- a/driver_tsip.c
+++ b/driver_tsip.c
@@ -26,7 +26,6 @@
#endif
-#include <sys/time.h> /* for pselect() */
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
@@ -37,8 +36,7 @@
#include "gpsd.h"
#include "bits.h"
#include "strfuncs.h"
-
-#include <sys/select.h>
+#include "timespec.h"
#define USE_SUPERPACKET 1 /* use Super Packet mode? */
@@ -85,8 +83,6 @@ static bool tsip_detect(struct gps_device_t *session)
char buf[BUFSIZ];
bool ret = false;
int myfd;
- fd_set fdset;
- struct timespec to;
speed_t old_baudrate;
char old_parity;
unsigned int old_stopbits;
@@ -105,11 +101,7 @@ static bool tsip_detect(struct gps_device_t *session)
if (write(myfd, buf, 4) == 4) {
unsigned int n;
for (n = 0; n < 3; n++) {
- FD_ZERO(&fdset);
- FD_SET(myfd, &fdset);
- to.tv_sec = 1;
- to.tv_nsec = 0;
- if (pselect(myfd + 1, &fdset, NULL, NULL, &to, NULL) != 1)
+ if (!nanowait(myfd, NS_IN_SEC))
break;
if (generic_get(session) >= 0) {
if (session->lexer.type == TSIP_PACKET) {
diff --git a/gps2udp.c b/gps2udp.c
index ea894689..b8b9c61f 100644
--- a/gps2udp.c
+++ b/gps2udp.c
@@ -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)
{
diff --git a/gpsd.c b/gpsd.c
index 6d3c14de..fb148bef 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -23,8 +23,6 @@
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/time.h> /* for pselect() */
-#include <sys/select.h>
#include <stdio.h>
#include <stdint.h> /* for uint32_t, etc. */
#include <time.h>
@@ -735,7 +733,7 @@ static bool open_device( struct gps_device_t *device)
gpsd_log(&context.errout, LOG_INF,
"device %s activated\n", device->gpsdata.dev.path);
if ( PLACEHOLDING_FD == activated ) {
- /* it is a /dev/ppsX, no need to pselect() it */
+ /* it is a /dev/ppsX, no need to wait on it */
return true;
}
FD_SET(device->gpsdata.gps_fd, &all_fds);
diff --git a/gpsd.h b/gpsd.h
index c2f19b29..127989d4 100644
--- a/gpsd.h
+++ b/gpsd.h
@@ -928,6 +928,8 @@ extern void ntpshm_link_activate(struct gps_device_t *);
#endif /* NTPSHM_ENABLE */
#endif /* NTP_ENABLE */
+bool nanowait(int, int);
+
extern void errout_reset(struct gpsd_errout_t *errout);
extern void gpsd_acquire_reporting_lock(void);
diff --git a/gpsmon.c b/gpsmon.c
index ff2a54dd..eee5e4d8 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -20,7 +20,6 @@
#include <stdarg.h>
#include <time.h>
#include <math.h>
-#include <sys/time.h> /* expected to declare pselect(2) a la SuS */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
@@ -1492,7 +1491,7 @@ int main(int argc, char **argv)
explanation = NULL;
switch (bailout) {
case TERM_SELECT_FAILED:
- explanation = "pselect(2) failed\n";
+ explanation = "I/O wait on device failed\n";
break;
case TERM_DRIVER_SWITCH:
explanation = "Driver type switch failed\n";
diff --git a/gpspipe.c b/gpspipe.c
index 7cafbf72..19870c75 100644
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -29,7 +29,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__ */
diff --git a/gpsutils.c b/gpsutils.c
index 0a4d5d40..8b855855 100644
--- a/gpsutils.c
+++ b/gpsutils.c
@@ -10,6 +10,11 @@
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_01_02 */
#define _XOPEN_SOURCE 600
+#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L
+/* pselect() needs _POSIX_C_SOURCE >= 200112L */
+#define _POSIX_C_SOURCE 200112L
+#endif
+
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
@@ -18,10 +23,12 @@
#include <math.h>
#include <errno.h>
#include <ctype.h>
+#include <sys/time.h> /* expected to have a pselect(2) prototype a la SuS */
#include "gps.h"
#include "libgps.h"
#include "os_compat.h"
+#include "timespec.h"
#ifdef USE_QT
#include <QDateTime>
@@ -621,4 +628,16 @@ double earth_distance(double lat1, double lon1, double lat2, double lon2)
return earth_distance_and_bearings(lat1, lon1, lat2, lon2, NULL, NULL);
}
+bool nanowait(int fd, int nanoseconds)
+{
+ fd_set fdset;
+ struct timespec to;
+
+ FD_ZERO(&fdset);
+ FD_SET(fd, &fdset);
+ to.tv_sec = nanoseconds / NS_IN_SEC;
+ to.tv_nsec = nanoseconds % NS_IN_SEC;
+ return pselect(fd + 1, &fdset, NULL, NULL, &to, NULL) == 1;
+}
+
/* end */
diff --git a/libgps_sock.c b/libgps_sock.c
index 808d837a..7816014d 100644
--- a/libgps_sock.c
+++ b/libgps_sock.c
@@ -13,7 +13,6 @@
#include <math.h>
#include <locale.h>
#include <assert.h>
-#include <sys/time.h> /* expected to have a pselect(2) prototype a la SuS */
#include <sys/types.h>
#include <sys/stat.h>
#include "gpsd_config.h"
@@ -132,22 +131,12 @@ bool gps_sock_waiting(const struct gps_data_t *gpsdata, int timeout)
/* timeout is in uSec */
{
#ifndef USE_QT
- fd_set rfds;
- struct timespec tv;
-
libgps_debug_trace((DEBUG_CALLS, "gps_waiting(%d): %d\n", timeout, PRIVATE(gpsdata)->waitcount++));
if (PRIVATE(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 = timeout / US_IN_SEC;
- tv.tv_nsec = (timeout % US_IN_SEC) * 1000;
/* all error conditions return "not waiting" -- crude but effective */
- return (pselect(gpsdata->gps_fd + 1, &rfds, NULL, NULL, &tv, NULL) == 1);
+ return nanowait(gpsdata->gps_fd, timeout * 1000);
#else
return ((QTcpSocket *) (gpsdata->gps_fd))->waitForReadyRead(timeout / 1000);
#endif
diff --git a/libgpsd_core.c b/libgpsd_core.c
index cc7d5fbd..e46104ff 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -1060,7 +1060,7 @@ int gpsd_await_data(fd_set *rfds,
* pselect(2) has to poll here as small as possible (for
* low-clock-rate SBCs and the like).
*
- * pselect() is preferable to vanilla select, to eliminate
+ * pselect(2) is preferable to vanilla select, to eliminate
* the once-per-second wakeup when no sensors are attached.
* This cuts power consumption.
*/