From: Zoran V. <vas...@us...> - 2005-04-08 19:59:27
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27356/nsd Modified Files: nsd.h unix.c Log Message: Added non-gnu implementation of poll() for platforms not implementing it (Darwin as up to 8.0 aka Mac OS X 10.3) Index: unix.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/unix.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** unix.c 17 Mar 2005 17:49:12 -0000 1.3 --- unix.c 8 Apr 2005 19:59:17 -0000 1.4 *************** *** 483,564 **** #ifndef HAVE_POLL ! /* Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc. ! This file is part of the GNU C Library. ! ! The GNU C Library is free software; you can redistribute it and/or ! modify it under the terms of the GNU Library General Public License as ! published by the Free Software Foundation; either version 2 of the ! License, or (at your option) any later version. ! ! The GNU C Library is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! Library General Public License for more details. ! ! You should have received a copy of the GNU Library General Public ! License along with the GNU C Library; see the file COPYING.LIB. If not, ! write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ! Boston, MA 02111-1307, USA. */ ! ! /* Poll the file descriptors described by the NFDS structures starting at ! FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for ! an event to occur; if TIMEOUT is -1, block until an event occurs. ! Returns the number of file descriptors with events, zero if timed out, ! or -1 for errors. */ int ! poll (fds, nfds, timeout) ! struct pollfd *fds; ! unsigned long int nfds; ! int timeout; { ! struct timeval tv, *tvp; ! fd_set rset, wset, xset; ! struct pollfd *f; ! int ready; ! int maxfd = 0; ! ! FD_ZERO (&rset); ! FD_ZERO (&wset); ! FD_ZERO (&xset); ! ! for (f = fds; f < &fds[nfds]; ++f) ! if (f->fd != -1) ! { ! if (f->events & POLLIN) ! FD_SET (f->fd, &rset); ! if (f->events & POLLOUT) ! FD_SET (f->fd, &wset); ! if (f->events & POLLPRI) ! FD_SET (f->fd, &xset); ! if (f->fd > maxfd && (f->events & (POLLIN|POLLOUT|POLLPRI))) ! maxfd = f->fd; ! } ! ! if (timeout < 0) { ! tvp = NULL; ! } else { ! tv.tv_sec = timeout / 1000; ! tv.tv_usec = (timeout % 1000) * 1000; ! tvp = &tv; ! } ! ! ready = select (maxfd + 1, &rset, &wset, &xset, tvp); ! if (ready > 0) ! for (f = fds; f < &fds[nfds]; ++f) ! { ! f->revents = 0; ! if (f->fd >= 0) ! { ! if (FD_ISSET (f->fd, &rset)) ! f->revents |= POLLIN; ! if (FD_ISSET (f->fd, &wset)) ! f->revents |= POLLOUT; ! if (FD_ISSET (f->fd, &xset)) ! f->revents |= POLLPRI; } ! } ! ! return ready; } --- 483,547 ---- #ifndef HAVE_POLL ! /* ! * Copyright 1994 University of Washington ! * ! * Permission is hereby granted to copy this software, and to ! * use and redistribute it, except that this notice may not be ! * removed. The University of Washington does not guarantee ! * 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; } Index: nsd.h =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsd.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** nsd.h 3 Apr 2005 06:38:01 -0000 1.9 --- nsd.h 8 Apr 2005 19:59:16 -0000 1.10 *************** *** 66,72 **** #include <poll.h> #else ! #define POLLIN 1 ! #define POLLOUT 2 ! #define POLLPRI 3 struct pollfd { int fd; --- 66,76 ---- #include <poll.h> #else ! #define POLLIN 001 ! #define POLLPRI 002 ! #define POLLOUT 004 ! #define POLLNORM POLLIN ! #define POLLERR 010 ! #define POLLHUP 020 ! #define POLLNVAL 040 struct pollfd { int fd; |