diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/9pserve.c | 1 | ||||
-rw-r--r-- | src/lib9/mkfile | 1 | ||||
-rw-r--r-- | src/lib9/quote.c | 2 | ||||
-rw-r--r-- | src/libthread/fdwait.c | 88 |
4 files changed, 84 insertions, 8 deletions
diff --git a/src/cmd/9pserve.c b/src/cmd/9pserve.c index 4263f035..3d72437f 100644 --- a/src/cmd/9pserve.c +++ b/src/cmd/9pserve.c @@ -2,7 +2,6 @@ #include <libc.h> #include <fcall.h> #include <thread.h> -#include <poll.h> #include <errno.h> enum diff --git a/src/lib9/mkfile b/src/lib9/mkfile index 16804b33..7824ff18 100644 --- a/src/lib9/mkfile +++ b/src/lib9/mkfile @@ -10,7 +10,6 @@ NUM=\ # Could add errfmt, but we want to pick it up from lib9 instead. FMTOFILES=\ dofmt.$O\ - errfmt.$O\ fltfmt.$O\ fmt.$O\ fmtfd.$O\ diff --git a/src/lib9/quote.c b/src/lib9/quote.c index 4467377a..32f434c4 100644 --- a/src/lib9/quote.c +++ b/src/lib9/quote.c @@ -1,9 +1,9 @@ #include <u.h> #include <libc.h> -int (*doquote)(int); /* in libfmt */ +extern int (*doquote)(int); extern int __needsquotes(char*, int*); extern int __runeneedsquotes(Rune*, int*); diff --git a/src/libthread/fdwait.c b/src/libthread/fdwait.c index 2f8581f1..170305eb 100644 --- a/src/libthread/fdwait.c +++ b/src/libthread/fdwait.c @@ -4,10 +4,87 @@ #include <thread.h> #include <errno.h> -#include <poll.h> #include <unistd.h> #include <fcntl.h> +#define debugpoll 0 + +#ifdef __APPLE__ +#include <sys/time.h> +enum { POLLIN=1, POLLOUT=2, POLLERR=4 }; +struct pollfd +{ + int fd; + int events; + int revents; +}; + +int +poll(struct pollfd *p, int np, int ms) +{ + int i, maxfd, n; + struct timeval tv, *tvp; + fd_set rfd, wfd, efd; + + maxfd = -1; + FD_ZERO(&rfd); + FD_ZERO(&wfd); + FD_ZERO(&efd); + for(i=0; i<np; i++){ + p[i].revents = 0; + if(p[i].fd == -1) + continue; + if(p[i].fd > maxfd) + maxfd = p[i].fd; + if(p[i].events & POLLIN) + FD_SET(p[i].fd, &rfd); + if(p[i].events & POLLOUT) + FD_SET(p[i].fd, &wfd); + FD_SET(p[i].fd, &efd); + } + + if(ms != -1){ + tv.tv_usec = (ms%1000)*1000; + tv.tv_sec = ms/1000; + tvp = &tv; + }else + tvp = nil; + + if(debugpoll){ + fprint(2, "select %d:", maxfd+1); + for(i=0; i<=maxfd; i++){ + if(FD_ISSET(i, &rfd)) + fprint(2, " r%d", i); + if(FD_ISSET(i, &wfd)) + fprint(2, " w%d", i); + if(FD_ISSET(i, &efd)) + fprint(2, " e%d", i); + } + fprint(2, "; tp=%p, t=%d.%d\n", tvp, tv.tv_sec, tv.tv_usec); + } + + n = select(maxfd+1, &rfd, &wfd, &efd, tvp); + + if(n <= 0) + return n; + + for(i=0; i<np; i++){ + if(p[i].fd == -1) + continue; + if(FD_ISSET(p[i].fd, &rfd)) + p[i].revents |= POLLIN; + if(FD_ISSET(p[i].fd, &wfd)) + p[i].revents |= POLLOUT; + if(FD_ISSET(p[i].fd, &efd)) + p[i].revents |= POLLERR; + } + return n; +} + +#else +#include <poll.h> +#endif + /* * Poll file descriptors in an idle loop. */ @@ -34,21 +111,22 @@ pollidle(void *v) uint now; for(;; yield()){ - //fprint(2, "poll %d:", npoll); + if(debugpoll) fprint(2, "poll %d:", npoll); for(i=0; i<npoll; i++){ - //fprint(2, " %d%c", pfd[i].fd, pfd[i].events==POLLIN ? 'r' : 'w'); + if(debugpoll) fprint(2, " %d%c", pfd[i].fd, pfd[i].events==POLLIN ? 'r' : 'w'); pfd[i].revents = 0; } t = -1; + now = p9nsec()/1000000; for(i=0; i<nsleep; i++){ - now = p9nsec()/1000000; n = sleeptime[i] - now; + if(debugpoll) fprint(2, " s%d", n); if(n < 0) n = 0; if(t == -1 || n < t) t = n; } - //fprint(2, "\n"); + if(debugpoll) fprint(2, "; t=%d\n", t); n = poll(pfd, npoll, t); //fprint(2, "poll ret %d:", n); |