Disable timeout when draining NMRP rx buffer
This commit is contained in:
parent
4e84b3809f
commit
a04543808c
3 changed files with 12 additions and 1 deletions
|
@ -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)
|
||||
|
|
7
nmrp.c
7
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 = "\\|/-";
|
||||
|
|
1
nmrpd.h
1
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue