int nb_write_fix(int s, char *buf, int len) { int cc; int length; struct timeval start, now; struct timezone junk; gettimeofday(&start, &junk); for (length = len; len > 0 ; ) { if ((cc = write(s, buf, len)) > 0) { len -= cc; buf += cc; } else if (cc < 0 && BAD_IO_ERR(errno)) { if (errno == EPIPE) lserrno = LSE_LOSTCON; return (-1); } if (len > 0) { gettimeofday(&now, &junk); if (US_DIFF(now, start) > IO_TIMEOUT * 1000) { errno = ETIMEDOUT; return(-1); } millisleep_(IO_TIMEOUT / 20); } } return (length); }
int nb_read_fix (int s, char *buf, int len) { int cc; int length; struct timeval start, now; struct timezone junk; if (logclass & LC_TRACE) ls_syslog (LOG_DEBUG, "nb_read_fix: Entering this routine..."); gettimeofday (&start, &junk); for (length = len; len > 0;) { if ((cc = read (s, buf, len)) > 0) { len -= cc; buf += cc; } else if (cc == 0 || BAD_IO_ERR (errno)) { if (cc == 0) errno = ECONNRESET; return (-1); } if (len > 0) { gettimeofday (&now, &junk); if (US_DIFF (now, start) > IO_TIMEOUT * 1000) { errno = ETIMEDOUT; return (-1); } millisleep_ (IO_TIMEOUT / 20); } } return (length); }