diff --git a/stand/libsa/ip.c b/stand/libsa/ip.c index f2293b3cd3f9..ea8213770432 100644 --- a/stand/libsa/ip.c +++ b/stand/libsa/ip.c @@ -416,8 +416,13 @@ readip(struct iodesc *d, void **pkt, void **payload, time_t tleft, while ((getsecs() - t) < tleft) { errno = 0; ret = readipv4(d, pkt, payload, tleft, proto); + if (ret >= 0) + return (ret); + /* Bubble up the error if it wasn't successful */ if (errno != EAGAIN) - break; + return (-1); } - return (ret); + /* We've exhausted tleft; timeout */ + errno = ETIMEDOUT; + return (-1); } diff --git a/stand/libsa/net.c b/stand/libsa/net.c index ae6e74511e12..5e13c5344327 100644 --- a/stand/libsa/net.c +++ b/stand/libsa/net.c @@ -118,7 +118,7 @@ sendrecv(struct iodesc *d, /* Try to get a packet and process it. */ cc = (*rproc)(d, pkt, payload, tleft); /* Return on data, EOF or real error. */ - if (cc != -1 || errno != 0) + if (cc != -1 || (errno != 0 && errno != ETIMEDOUT)) return (cc); /* Timed out or didn't get the packet we're waiting for */ diff --git a/stand/libsa/tftp.c b/stand/libsa/tftp.c index 9bef4643d25f..da85b9842785 100644 --- a/stand/libsa/tftp.c +++ b/stand/libsa/tftp.c @@ -638,14 +638,20 @@ sendrecv_tftp(struct tftp_handle *h, if (cc == -1) { /* Error on transmit; wait before retrying */ while ((getsecs() - t1) < tleft); + t1 = getsecs(); continue; } + t = t1 = getsecs(); recvnext: + if ((getsecs() - t) > MAXTMO) { + errno = ETIMEDOUT; + return -1; + } /* Try to get a packet and process it. */ cc = (*rproc)(h, pkt, payload, tleft, rtype); /* Return on data, EOF or real error. */ - if (cc != -1 || errno != 0) + if (cc != -1 || (errno != 0 && errno != ETIMEDOUT)) return (cc); if ((getsecs() - t1) < tleft) { goto recvnext;