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_timeout (int s, char *buf, int len, int timeout) { int cc; int nReady; int length = len; struct timeval timeval; timeval.tv_sec = timeout; timeval.tv_usec = 0; for (;;) { nReady = rd_select_ (s, &timeval); if (nReady < 0) { lserrno = LSE_SELECT_SYS; return (-1); } else if (nReady == 0) { lserrno = LSE_TIME_OUT; return (-1); } else { if ((cc = recv (s, buf, len, 0)) > 0) { len -= cc; buf += cc; } else if (cc == 0 || BAD_IO_ERR (errno)) { if (cc == 0) errno = ECONNRESET; return (-1); } if (len == 0) break; } } 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); }