diff options
author | James Maki <jmaki@multitech.com> | 2010-11-19 10:04:58 -0600 |
---|---|---|
committer | James Maki <jmaki@multitech.com> | 2010-11-19 10:04:58 -0600 |
commit | 8e799fec27f9c3b6a9f13c5002168025a00fbfc7 (patch) | |
tree | b02c42ebd1371d9552fbfc107bf9850ecad3dfef /src/venus_api.c | |
parent | f1b137da46178ff963506db378560023d272e97a (diff) | |
download | venus-gps-8e799fec27f9c3b6a9f13c5002168025a00fbfc7.tar.gz venus-gps-8e799fec27f9c3b6a9f13c5002168025a00fbfc7.tar.bz2 venus-gps-8e799fec27f9c3b6a9f13c5002168025a00fbfc7.zip |
allow multiple consumers with pthreads
Diffstat (limited to 'src/venus_api.c')
-rw-r--r-- | src/venus_api.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/venus_api.c b/src/venus_api.c index 04ad78d..40a52ea 100644 --- a/src/venus_api.c +++ b/src/venus_api.c @@ -267,19 +267,24 @@ int venus_write_msg_read_ack(int fd, struct venus_msg *msg) ssize_t venus_read_nmea_sentence(int fd, void *buf, size_t count) { - int err; - char c; ssize_t total = 0; char *cp = buf; - int start = 0; + char c; + int err; - while (1) { + if (!count) { + return 0; + } + count--; + + while (count > 0) { err = safe_read(fd, &c, 1); if (err <= 0) { log_error("read from gps failed: %m"); return -1; } + if (!start) { if (c != '$') { continue; @@ -287,16 +292,16 @@ ssize_t venus_read_nmea_sentence(int fd, void *buf, size_t count) start = 1; } - if (total < count) { - *cp++ = c; - total++; - } + cp[total++] = c; + count--; if (c == '\n') { break; } } + cp[total] = '\0'; + return total; } |