-/*
- * Writes out the entire iovec
- */
-static int
-net_writev(fd, iov, iovcnt)
- int fd, iovcnt;
- struct iovec *iov;
-{
- int delta, n, total;
-
- assert(iov != NULL);
-
- total = 0;
- while (iovcnt > 0) {
- /*
- * Write the iovec
- */
- total += n = writev(fd, iov, iovcnt);
- if (n < 0)
- return (-1);
- if (n == 0) {
- errno = EIO;
- return (-1);
- }
- /*
- * Iterate through each iov. Figure out what we still need
- * to write out.
- */
- for (; n > 0; iovcnt--, iov++) {
- /* 'delta' is the bytes written from this iovec */
- delta = n < iov->iov_len ? n : iov->iov_len;
- /* subtract from the total num bytes written */
- n -= delta;
- assert(n >= 0);
- /* subtract from this iovec */
- iov->iov_len -= delta;
- (char *)iov->iov_base += delta;
- /* if this iovec isn't empty, run the writev again */
- if (iov->iov_len > 0)
- break;
- }
- }
- return (total);
-}
-
-/*
- * Like read(), but waits until the entire buffer has been filled.
- */
-static ssize_t
-net_read(kc, vbuf, origsize, timeout)
- struct krb5_conn *kc;
- void *vbuf;
- size_t origsize;
- int timeout;
-{
- char *buf = vbuf, *off; /* ptr arith */
- int nread;
- size_t size = origsize;
-
- while (size > 0) {
- if (kc->readbuf.left == 0) {
- if (net_read_fillbuf(kc, timeout) < 0)
- return (-1);
- if (kc->readbuf.size == 0)
- return (0);
- }
- nread = min(kc->readbuf.left, size);
- off = kc->readbuf.buf + kc->readbuf.size - kc->readbuf.left;
- memcpy(buf, off, nread);
-
- buf += nread;
- size -= nread;
- kc->readbuf.left -= nread;
- }
- return ((ssize_t)origsize);
-}
-
-/*
- * net_read likes to do a lot of little reads. Buffer it.
- */
-static int
-net_read_fillbuf(kc, timeout)
- struct krb5_conn *kc;
- int timeout;
-{
- fd_set readfds;
- struct timeval tv;
-
- FD_ZERO(&readfds);
- FD_SET(kc->fd, &readfds);
- tv.tv_sec = timeout;
- tv.tv_usec = 0;
- switch (select(kc->fd + 1, &readfds, NULL, NULL, &tv)) {
- case 0:
- errno = ETIMEDOUT;
- /* FALLTHROUGH */
- case -1:
- return (-1);
- case 1:
- assert(FD_ISSET(kc->fd, &readfds));
- break;
- default:
- assert(0);
- break;
- }
- kc->readbuf.left = 0;
- kc->readbuf.size = read(kc->fd, kc->readbuf.buf,
- sizeof(kc->readbuf.buf));
-k5printf(("net_read_fillbuf: read %d characters w/ errno %d\n", kc->readbuf.size, errno));
- if (kc->readbuf.size < 0)
- return (-1);
- kc->readbuf.left = kc->readbuf.size;
- return (0);
-}
-