Changeset View
Changeset View
Standalone View
Standalone View
tftp.c
Show First 20 Lines • Show All 617 Lines • ▼ Show 20 Lines | sendrecv_tftp(struct tftp_handle *h, | ||||
time_t t, t1, tleft; | time_t t, t1, tleft; | ||||
#ifdef TFTP_DEBUG | #ifdef TFTP_DEBUG | ||||
if (debug) | if (debug) | ||||
printf("sendrecv: called\n"); | printf("sendrecv: called\n"); | ||||
#endif | #endif | ||||
tleft = MINTMO; | tleft = MINTMO; | ||||
t = t1 = getsecs(); | t = getsecs(); | ||||
for (;;) { | for (;;) { | ||||
if ((getsecs() - t) > MAXTMO) { | if ((getsecs() - t) > MAXTMO) { | ||||
errno = ETIMEDOUT; | errno = ETIMEDOUT; | ||||
return -1; | return -1; | ||||
} | } | ||||
cc = (*sproc)(d, sbuf, ssize); | cc = (*sproc)(d, sbuf, ssize); | ||||
if (cc != -1 && cc < ssize) | if (cc != -1 && cc < ssize) | ||||
panic("sendrecv: short write! (%zd < %zu)", | panic("sendrecv: short write! (%zd < %zu)", | ||||
cc, ssize); | cc, ssize); | ||||
if (cc == -1) { | if (cc == -1) { | ||||
/* Error on transmit; wait before retrying */ | /* Error on transmit; wait before retrying */ | ||||
while ((getsecs() - t1) < tleft); | while ((getsecs() - t1) < tleft); | ||||
t1 = getsecs(); | |||||
continue; | continue; | ||||
} | } | ||||
t = t1 = getsecs(); | |||||
recvnext: | recvnext: | ||||
if ((getsecs() - t) > MAXTMO) { | |||||
errno = ETIMEDOUT; | |||||
return -1; | |||||
} | |||||
/* Try to get a packet and process it. */ | /* Try to get a packet and process it. */ | ||||
cc = (*rproc)(h, pkt, payload, tleft, rtype); | cc = (*rproc)(h, pkt, payload, tleft, rtype); | ||||
/* Return on data, EOF or real error. */ | /* Return on data, EOF or real error. */ | ||||
if (cc != -1 || errno != 0) | if (cc != -1 || (errno != 0 && errno != ETIMEDOUT)) | ||||
return (cc); | return (cc); | ||||
if ((getsecs() - t1) < tleft) { | if ((getsecs() - t1) < tleft) { | ||||
goto recvnext; | goto recvnext; | ||||
} | } | ||||
/* Timed out or didn't get the packet we're waiting for */ | /* Timed out or didn't get the packet we're waiting for */ | ||||
tleft += MINTMO; | tleft += MINTMO; | ||||
if (tleft > (2 * MINTMO)) { | if (tleft > (2 * MINTMO)) { | ||||
▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines |