Index: Makefile =================================================================== RCS file: /home/ncvs/src/lib/libfetch/Makefile,v retrieving revision 1.40 diff -u -r1.40 Makefile --- Makefile 1 May 2003 14:39:43 -0000 1.40 +++ Makefile 8 May 2003 09:44:25 -0000 @@ -18,7 +18,7 @@ CSTD?= c99 WARNS?= 2 -SHLIB_MAJOR= 3 +SHLIB_MAJOR= 4 ftperr.h: ftp.errors @echo "static struct fetcherr _ftp_errlist[] = {" > ${.TARGET} Index: common.c =================================================================== RCS file: /home/ncvs/src/lib/libfetch/common.c,v retrieving revision 1.47 diff -u -r1.47 common.c --- common.c 3 Mar 2003 12:35:03 -0000 1.47 +++ common.c 8 May 2003 17:03:19 -0000 @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD: src/lib/libfetch/common.c,v 1.47 2003/03/03 12:35:03 des Exp $"); #include +#include #include #include #include @@ -373,26 +374,28 @@ ssize_t _fetch_read(conn_t *conn, char *buf, size_t len) { - struct timeval now, timeout, wait; - fd_set readfds; + struct timespec timeout, now, wait; + struct timeval timo, n; + struct kevent ev; ssize_t rlen, total; int r; if (fetchTimeout) { - FD_ZERO(&readfds); - gettimeofday(&timeout, NULL); + gettimeofday(&timo, NULL); + TIMEVAL_TO_TIMESPEC(&timo, &timeout); timeout.tv_sec += fetchTimeout; } total = 0; while (len > 0) { - while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) { - FD_SET(conn->sd, &readfds); - gettimeofday(&now, NULL); + if (fetchTimeout) { + EV_SET(&ev, conn->sd, EVFILT_READ, EV_ADD, 0, 0, NULL); + gettimeofday(&n, NULL); + TIMEVAL_TO_TIMESPEC(&n, &now); wait.tv_sec = timeout.tv_sec - now.tv_sec; - wait.tv_usec = timeout.tv_usec - now.tv_usec; - if (wait.tv_usec < 0) { - wait.tv_usec += 1000000; + wait.tv_nsec = timeout.tv_nsec - now.tv_nsec; + if (wait.tv_nsec < 0) { + wait.tv_nsec += 1000; wait.tv_sec--; } if (wait.tv_sec < 0) { @@ -400,9 +403,12 @@ _fetch_syserr(); return (-1); } + errno = 0; - r = select(conn->sd + 1, &readfds, NULL, NULL, &wait); - if (r == -1) { + struct timespec timeo = {0,0}; + //r = kevent(fetchKqfd, &ev, 1, NULL, NULL, &wait); + r = kevent(fetchKqfd, &ev, 1, NULL, NULL, &timeo); + if (r < 0) { if (errno == EINTR && fetchRestartCalls) continue; _fetch_syserr(); @@ -499,35 +505,40 @@ ssize_t _fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt) { - struct timeval now, timeout, wait; - fd_set writefds; + struct timespec timeout, now, wait; + struct timeval timo, n; + struct kevent ev; ssize_t wlen, total; int r; if (fetchTimeout) { - FD_ZERO(&writefds); - gettimeofday(&timeout, NULL); + gettimeofday(&timo, NULL); + TIMEVAL_TO_TIMESPEC(&timo, &timeout); timeout.tv_sec += fetchTimeout; } total = 0; while (iovcnt > 0) { - while (fetchTimeout && !FD_ISSET(conn->sd, &writefds)) { - FD_SET(conn->sd, &writefds); - gettimeofday(&now, NULL); + if (fetchTimeout) { + EV_SET(&ev, conn->sd, EVFILT_WRITE, EV_ADD | EV_ENABLE, + 0, 0, NULL); + gettimeofday(&n, NULL); + TIMEVAL_TO_TIMESPEC(&n, &now); wait.tv_sec = timeout.tv_sec - now.tv_sec; - wait.tv_usec = timeout.tv_usec - now.tv_usec; - if (wait.tv_usec < 0) { - wait.tv_usec += 1000000; + wait.tv_nsec = timeout.tv_nsec - now.tv_nsec; +#if 0 + if (wait.tv_nsec < 0) { + wait.tv_nsec += 1000; wait.tv_sec--; } +#endif if (wait.tv_sec < 0) { errno = ETIMEDOUT; _fetch_syserr(); return (-1); } errno = 0; - r = select(conn->sd + 1, NULL, &writefds, NULL, &wait); + r = kevent(fetchKqfd, &ev, 1, NULL, NULL, &wait); if (r == -1) { if (errno == EINTR && fetchRestartCalls) continue; Index: fetch.c =================================================================== RCS file: /home/ncvs/src/lib/libfetch/fetch.c,v retrieving revision 1.37 diff -u -r1.37 fetch.c --- fetch.c 28 Jan 2003 08:04:40 -0000 1.37 +++ fetch.c 8 May 2003 15:41:16 -0000 @@ -46,6 +46,7 @@ int fetchTimeout; int fetchRestartCalls = 1; int fetchDebug; +int fetchKqfd; /*** Local data **************************************************************/ Index: fetch.h =================================================================== RCS file: /home/ncvs/src/lib/libfetch/fetch.h,v retrieving revision 1.25 diff -u -r1.25 fetch.h --- fetch.h 22 Jul 2002 16:11:39 -0000 1.25 +++ fetch.h 8 May 2003 12:15:38 -0000 @@ -147,4 +147,6 @@ /* Extra verbosity */ extern int fetchDebug; +/* Kqueue file descriptor */ +extern int fetchKqfd; #endif Index: fetch/fetch.c =================================================================== RCS file: /home/ncvs/src/usr.bin/fetch/fetch.c,v retrieving revision 1.62 diff -u -r1.62 fetch.c --- fetch/fetch.c 2003/03/11 21:33:43 1.62 +++ fetch/fetch.c 2003/05/10 06:54:19 @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -702,6 +703,9 @@ const char *p, *s; char *end, *q; int c, e, r; + + if ((fetchKqfd = kqueue()) == -1) + return -1; while ((c = getopt(argc, argv, "146AaB:bc:dFf:Hh:lMmN:nPpo:qRrS:sT:tUvw:")) != -1)