diff --git a/ethsock.c b/ethsock.c index 1468833..2f8e374 100644 --- a/ethsock.c +++ b/ethsock.c @@ -1026,6 +1026,11 @@ inline int ethsock_set_timeout(struct ethsock *sock, unsigned msec) return 0; } +unsigned ethsock_get_timeout(struct ethsock *sock) +{ + return sock->timeout; +} + static int ethsock_arp(struct ethsock *sock, uint8_t *hwaddr, uint32_t ipaddr, struct ethsock_arp_undo **undo) { #if defined(NMRPFLASH_UNIX) && !defined(NMRPFLASH_LINUX) diff --git a/nmrp.c b/nmrp.c index 003d135..9424983 100644 --- a/nmrp.c +++ b/nmrp.c @@ -357,12 +357,15 @@ static void nmrp_drain(void* arg) // we drain the NMRP receive buffer here, otherwise it might seem // as if these packets arrived *after* the TFTP upload. + struct ethsock* sock = (struct ethsock*)arg; + unsigned timeout = ethsock_get_timeout(sock); + ethsock_set_timeout(sock, 0); long long beg = millis(); struct nmrp_pkt rx; int i = 0; - while (pkt_recv((struct ethsock*)arg, &rx) == 0) { + while (pkt_recv(sock, &rx) == 0) { if (rx.msg.code != NMRP_C_CONF_REQ && rx.msg.code != NMRP_C_TFTP_UL_REQ) { if (verbosity > 1) { printf("Drained unexpected packet type %s\n", msg_code_str(rx.msg.code)); @@ -374,6 +377,8 @@ static void nmrp_drain(void* arg) if (verbosity > 1) { printf("Drained %d packet(s) from rx buffer in %lld ms\n", i, millis() - beg); } + + ethsock_set_timeout(sock, timeout); } static const char *spinner = "\\|/-"; diff --git a/nmrpd.h b/nmrpd.h index 57c8c3b..f647c09 100644 --- a/nmrpd.h +++ b/nmrpd.h @@ -146,6 +146,7 @@ int ethsock_close(struct ethsock *sock); int ethsock_send(struct ethsock *sock, void *buf, size_t len); ssize_t ethsock_recv(struct ethsock *sock, void *buf, size_t len); int ethsock_set_timeout(struct ethsock *sock, unsigned msec); +unsigned ethsock_get_timeout(struct ethsock *sock); uint8_t *ethsock_get_hwaddr(struct ethsock *sock); int ethsock_arp_add(struct ethsock *sock, uint8_t *hwaddr, uint32_t ipaddr, struct ethsock_arp_undo **undo); int ethsock_arp_del(struct ethsock *sock, struct ethsock_arp_undo **undo);