summaryrefslogtreecommitdiff
path: root/libgps.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-01-16 06:43:23 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-01-16 06:43:23 +0000
commitd3ac3875d24b4476c68e599ee4a2364f92c3a0eb (patch)
treeba7eed6fe8dfdb607855b283fe98664a7801b245 /libgps.c
parent0919c81e4dd3284b72598eda63d4f9f46d29c502 (diff)
downloadgpsd-d3ac3875d24b4476c68e599ee4a2364f92c3a0eb.tar.gz
Back out the reconnect patch.
Diffstat (limited to 'libgps.c')
-rw-r--r--libgps.c45
1 files changed, 7 insertions, 38 deletions
diff --git a/libgps.c b/libgps.c
index c38c2ff5..b62be903 100644
--- a/libgps.c
+++ b/libgps.c
@@ -4,7 +4,6 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <sys/socket.h>
#include "gpsd.h"
@@ -21,9 +20,6 @@ struct gps_data_t *gps_open(const char *host, const char *port)
if (!port)
port = DEFAULT_GPSD_PORT;
- gpsdata->host = strdup(host);
- gpsdata->port = strdup(port);
-
if ((gpsdata->gps_fd = netlib_connectsock(host, port, "tcp")) < 0) {
errno = gpsdata->gps_fd;
free(gpsdata);
@@ -196,51 +192,24 @@ static int gps_unpack(char *buf, struct gps_data_t *gpsdata)
;
}
-static int try_reconnect(struct gps_data_t *gpsdata)
-{
- int newfd;
-
- /* Try to connect, and replace filedescriptor if it succeeds */
- if ((newfd = netlib_connectsock(gpsdata->host,gpsdata->port, "tcp")) <= 0)
- return -1;
- else {
- close(gpsdata->gps_fd);
- gpsdata->gps_fd = newfd;
- return 0;
- }
-}
-
int gps_poll(struct gps_data_t *gpsdata)
/* wait for and read data being streamed from the daemon */
{
char buf[BUFSIZE];
int n;
- for (;;) {
- errno = 0;
- /* the daemon makes sure that every read is NUL-terminated */
- if ((n = read(gpsdata->gps_fd, buf, sizeof(buf)-1)) > 0) {
- buf[n] = '\0';
- return gps_unpack(buf, gpsdata);
- } else if (errno == EBADF && try_reconnect(gpsdata))
- continue;
- else
- return -1;
- }
+ /* the daemon makes sure that every read is NUL-terminated */
+ if ((n = read(gpsdata->gps_fd, buf, sizeof(buf)-1)) <= 0)
+ return -1;
+ buf[n] = '\0';
+ return gps_unpack(buf, gpsdata);
}
int gps_query(struct gps_data_t *gpsdata, const char *requests)
/* query a gpsd instance for new data */
{
- for (;;) {
- errno = 0;
- if (write(gpsdata->gps_fd, requests, sizeof(requests)) > 0) {
- break;
- } else if (errno == EBADF && try_reconnect(gpsdata))
- continue;
- else
- return -1;
- }
+ if (write(gpsdata->gps_fd, requests, strlen(requests)) <= 0)
+ return -1;
return gps_poll(gpsdata);
}