summaryrefslogtreecommitdiff
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
parent0919c81e4dd3284b72598eda63d4f9f46d29c502 (diff)
downloadgpsd-d3ac3875d24b4476c68e599ee4a2364f92c3a0eb.tar.gz
Back out the reconnect patch.
-rw-r--r--gps.h2
-rwxr-xr-xgps.py38
-rw-r--r--libgps.c45
-rw-r--r--libgps.xml16
4 files changed, 19 insertions, 82 deletions
diff --git a/gps.h b/gps.h
index 94b6aa6f..777b8a1f 100644
--- a/gps.h
+++ b/gps.h
@@ -96,8 +96,6 @@ struct gps_data_t {
/* these members are private */
int gps_fd; /* socket or file descriptor to GPS */
void (*raw_hook)(char *buf);/* Raw-mode hook for GPS data. */
- const char *host; /* Remember hostname and port for reconnects */
- const char *port;
};
struct gps_data_t *gps_open(const char *host, const char *port);
diff --git a/gps.py b/gps.py
index 9cc8e521..67eea3a6 100755
--- a/gps.py
+++ b/gps.py
@@ -110,7 +110,7 @@ class gpsdata:
st += "Mode: MODE_" + ("ZERO", "NO_FIX", "2D","3D")[self.mode]
st += " " + repr(self.mode_stamp) + "\n"
st += "Quality: %d p=%2.2f h=%2.2f v=%2.2f " % \
- (self.satellites_used, self.pdop, self.hdop, self.vdop)
+ self.satellites_used, self.pdop, self.hdop, self.vdop)
st += repr(self.fix_quality_stamp) + "\n"
st += "Y: %s satellites in view:\n" % len(self.satellites)
for sat in self.satellites:
@@ -124,9 +124,7 @@ class gps(gpsdata):
gpsdata.__init__(self)
self.sock = None # in case we blow up in connect
self.sockfile = None
- self.host = host
- self.port = port
- self.connect(self.host, self.port)
+ self.connect(host, port)
self.verbose = verbose
self.raw_hook = None
@@ -257,36 +255,18 @@ class gps(gpsdata):
or self.mode_stamp.changed \
or self.satellite_stamp.changed
- def __try_reconnect(self):
- try:
- self.connect(self.host, self.port)
- return 0
- except socket.error:
- return -1
-
def poll(self):
"Wait for and read data being streamed from gpsd."
- while True:
- try:
- data = self.sockfile.readline()
- if self.verbose:
- sys.stderr.write("GPS DATA %s\n" % repr(data))
- return self.__unpack(data)
- except socket.error:
- self.connect(self.host, self.port)
- continue
+ data = self.sockfile.readline()
+ if self.verbose:
+ sys.stderr.write("GPS DATA %s\n" % repr(data))
+ return self.__unpack(data)
def query(self, commands):
"Send a command, get back a response."
- while True:
- try:
- self.sockfile.write(commands)
- self.sockfile.flush()
- break
- except socket.error:
- self.connect(self.host, self.port)
- continue
- return self.poll()
+ self.sockfile.write(commands)
+ self.sockfile.flush()
+ return self.poll()
# some multipliers for interpreting GPS output
METERS_TO_FEET = 3.2808399
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);
}
diff --git a/libgps.xml b/libgps.xml
index 465b69db..d54277f9 100644
--- a/libgps.xml
+++ b/libgps.xml
@@ -76,9 +76,9 @@ interface that goes through
and is intended for concurrent use by several applications, and one
low-level interface that speaks directly with the serial or USB device
to which the GPS is attached. This page describes the high-level
-interface that is safe for multiple applications to use
-simultaneously; it is probably the one you want. The low-level
-interface is documented at
+interface is safe for multiple applications to use simultaneously; it
+is probably the one you want. The low-level interface is documented
+at
<citerefentry><refentrytitle>libgps</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
<para>Calling <function>gpsd_open()</function> initializes a GPS-data
@@ -106,11 +106,6 @@ user has issued an 'R' or 'W' command with
to the client. If the third argument is non-NULL, it is used as a
hook function to be called on each line of streamed data. </para>
-<para>The <function>gpsd_query()</function> and
-<function>gpsd_poll()</function> functions attempt to reconnect to the
-daemon if the connection to it has been lost
-(<errorname>EBADF</errorname> error).</para>
-
<para>Several member groups within the GPS-data structure have
last-modified timestamps and change-flag members associated with them;
these get updated on each query or poll as well.
@@ -132,11 +127,6 @@ released when it is garbage-collected.</para>
</para>
</refsect1>
-<refsect1 id='bugs'><title>BUGS</title>
-<para>The C reconnect support uses the <varname>errno</varname> global,
-and is therefore not thread-safe in the presence of frequent reconnects.</para>
-</refsect1>
-
<refsect1 id='author'><title>AUTHOR</title>
<para>Eric S. Raymond &lt;esr@thyrsus.com&gt;.</para>
</refsect1>