summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-03-27 02:26:22 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-03-27 02:26:22 +0000
commit7bdc8eacf14ff0bca9f99ae14302fd94aa7c4ce1 (patch)
treef4f285c0b1b3f0e52d5f576c3c8512b633596df3 /packet.c
parentd56c57d9a35f178e4121a45ddfaf16cd162671ab (diff)
downloadgpsd-7bdc8eacf14ff0bca9f99ae14302fd94aa7c4ce1.tar.gz
Significant simplification of the packet-getter interface.
packet_get() now always returns nonzero when it could either read fresh data or assemble a packet from data already read and buffered -- no more returning 0 when it has assembled a packet from buffered data but can't read any new data. I suspect this may have been causing subtle bugs.
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/packet.c b/packet.c
index 3714fc0e..8a94d57c 100644
--- a/packet.c
+++ b/packet.c
@@ -1425,11 +1425,16 @@ ssize_t packet_get(int fd, struct gps_packet_t *lexer)
/* Otherwise, consume from the packet input buffer */
packet_parse(lexer);
- /*
- * recvd can still be 0 or -1 at this point even if buffer data
- * was consumed. It could be -1 on a transient read error.
- */
- return recvd;
+ /* If we gathered a packet, return its length */
+ if (lexer->outbuflen > 0)
+ return lexer->outbuflen;
+ else
+ /*
+ * Otherwise recvd is the size of whatever packet fragment we got.
+ * It can still be 0 or -1 at this point even if buffer data
+ * was consumed.
+ */
+ return recvd;
}
void packet_reset(struct gps_packet_t *lexer)