From 3ba5936c70f2a4d7636958f60e229cb56fdebeb1 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 27 Aug 2026 12:44:30 +0200 Subject: [PATCH] faster client polling. Should make the pm3 client more spiffy --- client/src/uart/uart_posix.c | 10 ++++++++++ include/pm3_cmd.h | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/client/src/uart/uart_posix.c b/client/src/uart/uart_posix.c index b04a4c208..3e8f63706 100644 --- a/client/src/uart/uart_posix.c +++ b/client/src/uart/uart_posix.c @@ -617,6 +617,16 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin FD_ZERO(&rfds); FD_SET(spu->fd, &rfds); tv = timeout; + if ((*pszRxLen == 0) && + (spu->udpBuffer == NULL) && + (timeout.tv_sec == 0) && + (timeout.tv_usec <= UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000)) { + // Nothing of a frame in hand yet - see the header note. Local links + // only: a network link keeps its own longer timeout, where polling + // this fast would cost more than it saves. + tv.tv_sec = 0; + tv.tv_usec = UART_USB_CLIENT_RX_IDLE_TIMEOUT_MS * 1000; + } res = select(spu->fd + 1, &rfds, NULL, NULL, &tv); // Read error diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 9dd79232c..b76c7e205 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -1150,6 +1150,13 @@ typedef struct { // uart_win32.c & uart_posix.c #define UART_FPC_CLIENT_RX_TIMEOUT_MS 200 #define UART_USB_CLIENT_RX_TIMEOUT_MS 20 +// Idle poll, used only while no part of a frame is in hand. The comm thread +// transmits a queued command only after its receive phase returns, so a long +// idle wait here delays every single command by up to one full timeout. +// Returning "no data" promptly costs nothing; once part of a frame IS in hand +// the full timeout above applies, so a frame split across USB frames is never +// truncated. +#define UART_USB_CLIENT_RX_IDLE_TIMEOUT_MS 1 #define UART_NET_CLIENT_RX_TIMEOUT_MS 500 #define UART_TCP_LOCAL_CLIENT_RX_TIMEOUT_MS 40 #define UART_UDP_LOCAL_CLIENT_RX_TIMEOUT_MS 20