Skip to content

Commit

Permalink
Disable timeout when draining NMRP rx buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jclehner committed Oct 18, 2023
1 parent 4e84b38 commit a045438
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ethsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion nmrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 = "\\|/-";
Expand Down
1 change: 1 addition & 0 deletions nmrpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a045438

Please sign in to comment.