From 4b77fc1eb36995abb4070973a4fac53783e90f40 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Fri, 8 Oct 2021 23:58:07 -0500 Subject: [PATCH] Allow for EBUSY return during port read and retry 10x5ms for 50ms total before returning an error https://github.com/Hamlib/Hamlib/issues/818 --- src/iofunc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/iofunc.c b/src/iofunc.c index 9f2109248..9e27c4298 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -676,6 +676,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, fd_set rfds, efds; struct timeval tv, tv_timeout, start_time, end_time, elapsed_time; int total_count = 0; + int i=0; rig_debug(RIG_DEBUG_TRACE, "%s called, rxmax=%d\n", __func__, (int)rxmax); @@ -763,7 +764,16 @@ int HAMLIB_API read_string(hamlib_port_t *p, * read 1 character from the rig, (check if in stop set) * The file descriptor must have been set up non blocking. */ - rd_count = port_read(p, &rxbuffer[total_count], 1); + do + { + rd_count = port_read(p, &rxbuffer[total_count], 1); + if (errno == EBUSY) + { + hl_usleep(5*1000); + rig_debug(RIG_DEBUG_WARN, "%s: port_read is busy?\n", __func__); + } + + } while( ++i < 10 && errno == EBUSY); // 50ms should be enough /* if we get 0 bytes or an error something is wrong */ if (rd_count <= 0)