diff options
author | Daniel Willmann <dwillmann@sysmocom.de> | 2014-08-27 14:48:46 +0200 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2014-08-28 06:36:57 -0400 |
commit | 7097345d93a7b1c2ecd5ffd481a45fa171706f73 (patch) | |
tree | 5031db6c253c7be91a9d4fae9e31bacf7a141bea /libgps_sock.c | |
parent | 46ae5aae19e3bef51e8c560eb454d49ec952bad5 (diff) | |
download | gpsd-7097345d93a7b1c2ecd5ffd481a45fa171706f73.tar.gz |
Exit from gps_sock_mainloop() if connection to gpsd is lost
The current mainloop function does not evaluate the return value of
gps_read(). If the socket is closed (because gpsd is stopped) the
mainloop will consume 99% CPU constantly doing a recv() from the socket
which returns zero. gps_read already returns -1 if this condition is
encountered.
This patch checks the return value of gps_read() and if it is -1 the
mainloop is exited. This is also what happens in gps_shm_mainloop().
Diffstat (limited to 'libgps_sock.c')
-rw-r--r-- | libgps_sock.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libgps_sock.c b/libgps_sock.c index 2a846a13..e84a1eb2 100644 --- a/libgps_sock.c +++ b/libgps_sock.c @@ -572,8 +572,12 @@ int gps_sock_mainloop(struct gps_data_t *gpsdata, int timeout, if (!gps_waiting(gpsdata, timeout)) { return -1; } else { - (void)gps_read(gpsdata); - (*hook)(gpsdata); + int status = gps_read(gpsdata); + + if (status == -1) + return -1; + if (status > 0) + (*hook)(gpsdata); } } //return 0; |