From: Zoran V. <vas...@us...> - 2005-05-04 12:35:14
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11474 Modified Files: unix.c Log Message: Modified pool() compatibility wrapper to work on Darwin 10.2 and less. Also, heavily reformatted to be easily readable. Index: unix.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/unix.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** unix.c 8 Apr 2005 19:59:17 -0000 1.4 --- unix.c 4 May 2005 12:34:58 -0000 1.5 *************** *** 482,487 **** #ifndef HAVE_POLL - /* * Copyright 1994 University of Washington * --- 482,487 ---- #ifndef HAVE_POLL /* + * ----------------------------------------------------------------- * Copyright 1994 University of Washington * *************** *** 491,546 **** * that this software is suitable for any purpose and will not * be held liable for any damage it may cause. */ int ! poll(fds, nfds, timo) ! struct pollfd *fds; ! unsigned long nfds; ! int timo; { struct timeval timeout, *toptr; ! fd_set ifds, ofds, efds, *ip, *op, *ep; ! int i, rc, n; FD_ZERO(&ifds); FD_ZERO(&ofds); FD_ZERO(&efds); ! for (i = 0, n = -1, op = ip = 0; i < nfds; ++i) { ! fds[i].revents = 0; ! if (fds[i].fd < 0) continue; ! if (fds[i].fd > n) n = fds[i].fd; - if (fds[i].events & (POLLIN|POLLPRI)) { - ip = &ifds; - FD_SET(fds[i].fd, ip); } ! if (fds[i].events & POLLOUT) { ! op = &ofds; ! FD_SET(fds[i].fd, op); } - FD_SET(fds[i].fd, &efds); } ! if (timo < 0) ! toptr = 0; ! else { toptr = &timeout; timeout.tv_sec = timo / 1000; timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; } ! ! rc = select(++n, ip, op, &efds, toptr); ! if (rc <= 0) return rc; ! ! for (i = 0, n = 0; i < nfds; ++i) { ! if (fds[i].fd < 0) continue; ! if (fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(i, &ifds)) fds[i].revents |= POLLIN; ! if (fds[i].events & POLLOUT && FD_ISSET(i, &ofds)) fds[i].revents |= POLLOUT; ! if (FD_ISSET(i, &efds)) ! /* Some error was detected ... should be some way to know. */ ! fds[i].revents |= POLLHUP; } return rc; } --- 491,553 ---- * that this software is suitable for any purpose and will not * be held liable for any damage it may cause. + * ----------------------------------------------------------------- + * + * Modified to work properly on Darwin 10.2 or less. + * Also, heavily reformatted to be more readable. */ int ! poll(struct pollfd *fds, unsigned long int nfds, int timo) { struct timeval timeout, *toptr; ! fd_set ifds, ofds, efds; ! int i, rc, n = -1; FD_ZERO(&ifds); FD_ZERO(&ofds); FD_ZERO(&efds); ! for (i = 0; i < nfds; ++i) { ! if (fds[i].fd == -1) { continue; ! } ! if (fds[i].fd > n) { n = fds[i].fd; } ! if ((fds[i].events & POLLIN)) { ! FD_SET(fds[i].fd, &ifds); ! } ! if ((fds[i].events & POLLOUT)) { ! FD_SET(fds[i].fd, &ofds); ! } ! if ((fds[i].events & POLLPRI)) { ! FD_SET(fds[i].fd, &efds); } } ! if (timo < 0) { ! toptr = NULL; ! } else { toptr = &timeout; timeout.tv_sec = timo / 1000; timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; } ! rc = select(++n, &ifds, &ofds, &efds, toptr); ! if (rc <= 0) { return rc; ! } ! for (i = 0; i < nfds; ++i) { ! fds[i].revents = 0; ! if (fds[i].fd == -1) { ! continue; ! } ! if (FD_ISSET(fds[i].fd, &ifds)) { fds[i].revents |= POLLIN; ! } ! if (FD_ISSET(fds[i].fd, &ofds)) { fds[i].revents |= POLLOUT; ! } ! if (FD_ISSET(fds[i].fd, &efds)) { ! fds[i].revents |= POLLPRI; ! } } + return rc; } |