From da9700c71d59d389cb557878656ff4339a017390 Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Mon, 2 Mar 2020 09:30:27 +0100 Subject: [PATCH] Use shorter TFTP timeout in blind mode --- main.c | 2 +- nmrpd.h | 2 -- tftp.c | 5 +++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 242e7be..58afc56 100644 --- a/main.c +++ b/main.c @@ -133,7 +133,7 @@ int main(int argc, char **argv) int c, val, max; bool list = false, have_dest_mac = false; struct nmrpd_args args = { - .rx_timeout = NMRPFLASH_DEF_RX_TIMEOUT * 1000, + .rx_timeout = 200 * 1000, .ul_timeout = 5 * 60 * 1000, .tftpcmd = NULL, .file_local = NULL, diff --git a/nmrpd.h b/nmrpd.h index c1dc77e..d65c811 100644 --- a/nmrpd.h +++ b/nmrpd.h @@ -72,8 +72,6 @@ #define NMRPFLASH_SET_REGION -#define NMRPFLASH_DEF_RX_TIMEOUT 200 - struct eth_hdr { uint8_t ether_dhost[6]; uint8_t ether_shost[6]; diff --git a/tftp.c b/tftp.c index 5c37693..eb2c314 100644 --- a/tftp.c +++ b/tftp.c @@ -315,7 +315,8 @@ int tftp_put(struct nmrpd_args *args) const char *file_remote = args->file_remote; char *val, *end; bool rollover; - unsigned rx_timeout = MAX(args->rx_timeout / NMRPFLASH_DEF_RX_TIMEOUT, 1000); + const unsigned rx_timeout = MAX(args->rx_timeout / (args->blind ? 50 : 5), 2000); + const unsigned max_timeouts = args->blind ? 3 : 5; sock = -1; ret = -1; @@ -453,7 +454,7 @@ int tftp_put(struct nmrpd_args *args) if (ret < 0) { goto cleanup; } else if (!ret) { - if (++timeouts < 5 || (!block && timeouts < 10)) { + if (++timeouts < max_timeouts || (!block && timeouts < (max_timeouts * 4))) { continue; } else if (args->blind) { timeouts = 0; -- 2.25.1