From 82b86490301f6d69edbdffb7e80bb292ee400c2b Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Wed, 10 Dec 2014 01:25:33 +0000 Subject: [PATCH] Revert read_string() to partial results are a success status The read_string() function was changed to return a -RIG_ETIMEOUT error when timing out after having read some characters. This caused a back end to fail because it was using a read_string() with an invalid stop character and relying on the timed out read_string() to fetch the data. This patch reverts to the prior behavior of returning a null terminated buffer and read bytes count if at least one byte has been read. --- src/iofunc.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/iofunc.c b/src/iofunc.c index 492a1baa9..5494182f3 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -505,16 +505,19 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const retval = port_select(p, p->fd+1, &rfds, NULL, &efds, &tv); if (retval == 0) { - /* Record timeout time and caculate elapsed time */ - gettimeofday(&end_time, NULL); - timersub(&end_time, &start_time, &elapsed_time); + if (0 == total_count) { + /* Record timeout time and caculate elapsed time */ + gettimeofday(&end_time, NULL); + timersub(&end_time, &start_time, &elapsed_time); - dump_hex((unsigned char *) rxbuffer, total_count); - rig_debug(RIG_DEBUG_WARN, "%s(): Timed out %d.%d seconds after %d chars\n", - __func__, elapsed_time.tv_sec, elapsed_time.tv_usec, total_count); + dump_hex((unsigned char *) rxbuffer, total_count); + rig_debug(RIG_DEBUG_WARN, "%s(): Timed out %d.%d seconds after %d chars\n", + __func__, elapsed_time.tv_sec, elapsed_time.tv_usec, total_count); - return -RIG_ETIMEOUT; - } + return -RIG_ETIMEOUT; + } + break; /* return what we have read */ + } if (retval < 0) { dump_hex((unsigned char *) rxbuffer, total_count);