Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Boris Schaeling" To: "Corinna Vinschen" Subject: AW: poll() bugs and patch Date: Wed, 13 Mar 2002 22:20:30 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0003_01C1CADD.49048260" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <20020313181423.C29574@cygbert.vinschen.de> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 ------=_NextPart_000_0003_01C1CADD.49048260 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit > -----Ursprüngliche Nachricht----- > Von: cygwin-owner AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com]Im Auftrag > von Corinna Vinschen > Gesendet: Mittwoch, 13. März 2002 18:14 > An: cygwin AT cygwin DOT com > Betreff: Re: poll() bugs and patch > [...] > > Actually, I'm inclined to just let this one in. There isn't a lot of > > new code, it's mainly just rearranged. > > Ok with me. However, I'll not take that patch w/o a ChangeLog entry. > Please create one, Boris. Here they are: - change.log - poll.patch - newpoll.cc (new implementation) - polltest.c (testcase) HTH, Boris ------=_NextPart_000_0003_01C1CADD.49048260 Content-Type: application/octet-stream; name="change.log" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="change.log" 2002-03-13 Boris Schaeling =0A= =0A= * poll.cc: variable open_fds removed, rearranged =0A= and added code to fix settings of revents ------=_NextPart_000_0003_01C1CADD.49048260 Content-Type: application/octet-stream; name="poll.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="poll.patch" --- poll.cc Sun Mar 10 21:52:26 2002=0A= +++ newpoll.cc Tue Mar 12 00:53:20 2002=0A= @@ -26,7 +26,7 @@ int=0A= poll (struct pollfd *fds, unsigned int nfds, int timeout)=0A= {=0A= int max_fd =3D 0;=0A= - fd_set *open_fds, *read_fds, *write_fds, *except_fds;=0A= + fd_set *read_fds, *write_fds, *except_fds;=0A= struct timeval tv =3D { timeout / 1000, (timeout % 1000) * 1000 };=0A= sigframe thisframe (mainthread);=0A= =0A= @@ -36,63 +36,55 @@ poll (struct pollfd *fds, unsigned int n=0A= =0A= size_t fds_size =3D howmany(max_fd + 1, NFDBITS) * sizeof (fd_mask);=0A= =0A= - open_fds =3D (fd_set *) alloca (fds_size);=0A= read_fds =3D (fd_set *) alloca (fds_size);=0A= write_fds =3D (fd_set *) alloca (fds_size);=0A= except_fds =3D (fd_set *) alloca (fds_size);=0A= =0A= - if (!open_fds || !read_fds || !write_fds || !except_fds)=0A= + if (!read_fds || !write_fds || !except_fds)=0A= {=0A= set_errno (ENOMEM);=0A= return -1;=0A= }=0A= =0A= - memset (open_fds, 0, fds_size);=0A= memset (read_fds, 0, fds_size);=0A= memset (write_fds, 0, fds_size);=0A= memset (except_fds, 0, fds_size);=0A= =0A= - bool valid_fds =3D false;=0A= - for (unsigned int i =3D 0; i < nfds; ++i)=0A= - if (!cygheap->fdtab.not_open (fds[i].fd))=0A= - {=0A= - valid_fds =3D true;=0A= - fds[i].revents =3D 0;=0A= - FD_SET (fds[i].fd, open_fds);=0A= - if (fds[i].events & POLLIN)=0A= - FD_SET (fds[i].fd, read_fds);=0A= - if (fds[i].events & POLLOUT)=0A= - FD_SET (fds[i].fd, write_fds);=0A= - if (fds[i].events & POLLPRI)=0A= - FD_SET (fds[i].fd, except_fds);=0A= - }=0A= - else=0A= - fds[i].revents =3D POLLNVAL;=0A= -=0A= - int ret =3D 0;=0A= - if (valid_fds)=0A= - ret =3D cygwin_select (max_fd + 1, read_fds, write_fds, except_fds,=0A= - timeout < 0 ? NULL : &tv);=0A= -=0A= - for (unsigned int i =3D 0; i < nfds; ++i)=0A= - {=0A= - if (fds[i].revents =3D=3D POLLNVAL && ret >=3D 0)=0A= - ret++;=0A= - else if (cygheap->fdtab.not_open(fds[i].fd))=0A= - fds[i].revents =3D POLLHUP;=0A= - else if (ret < 0)=0A= - fds[i].revents =3D POLLERR;=0A= - else=0A= - {=0A= - fds[i].revents =3D 0;=0A= - if (FD_ISSET (fds[i].fd, read_fds))=0A= - fds[i].revents |=3D POLLIN;=0A= - if (FD_ISSET (fds[i].fd, write_fds))=0A= - fds[i].revents |=3D POLLOUT;=0A= - if (FD_ISSET (fds[i].fd, except_fds))=0A= - fds[i].revents |=3D POLLPRI;=0A= - }=0A= - }=0A= + for (unsigned int i =3D 0; i < nfds; ++i) =0A= + { =0A= + fds[i].revents =3D 0; =0A= + if (!cygheap->fdtab.not_open(fds[i].fd)) =0A= + { =0A= + if (fds[i].events & POLLIN) =0A= + FD_SET(fds[i].fd, read_fds); =0A= + if (fds[i].events & POLLOUT) =0A= + FD_SET(fds[i].fd, write_fds); =0A= + if (fds[i].events & POLLPRI) =0A= + FD_SET(fds[i].fd, except_fds); =0A= + } =0A= + } =0A= +=0A= + int ret =3D cygwin_select (max_fd + 1, read_fds, write_fds, = except_fds, timeout < 0 ? NULL : &tv);=0A= +=0A= + if (ret > 0) =0A= + for (unsigned int i =3D 0; i < nfds; ++i) =0A= + { =0A= + if (fds[i].fd < 0) =0A= + fds[i].revents =3D POLLNVAL; =0A= + else if (cygheap->fdtab.not_open(fds[i].fd)) =0A= + fds[i].revents =3D POLLHUP; =0A= + else =0A= + { =0A= + if (FD_ISSET(fds[i].fd, read_fds)) =0A= + fds[i].revents |=3D POLLIN; =0A= + if (FD_ISSET(fds[i].fd, write_fds)) =0A= + fds[i].revents |=3D POLLOUT; =0A= + if (FD_ISSET(fds[i].fd, read_fds) && FD_ISSET(fds[i].fd, write_fds)) =0A= + fds[i].revents |=3D POLLERR; =0A= + if (FD_ISSET(fds[i].fd, except_fds)) =0A= + fds[i].revents |=3D POLLPRI; =0A= + } =0A= + } =0A= =0A= - return ret;=0A= -}=0A= + return ret; =0A= +} =0A= \ No newline at end of file=0A= ------=_NextPart_000_0003_01C1CADD.49048260 Content-Type: application/octet-stream; name="polltest.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="polltest.c" /* gcc -opolltest polltest.c */=20 #include =20 #include =20 #include =20 #include =20 #include =20 void callback_alarm(int sig) { return; }=20 int main()=20 {=20 struct pollfd p[3];=20 memset(p, 0, sizeof(struct pollfd) * 3);=20 p[0].fd =3D -1;=20 p[1].fd =3D -1;=20 p[2].fd =3D -1;=20 printf("no descriptor is valid - poll() must wait for 2 seconds\n");=20 poll(p, 3, 2000);=20 printf("no descriptor is valid - revents for any descriptor must be 0: = %d, %d, %d\n", p[0].revents, p[1].revents, p[2].revents);=20 p[2].fd =3D 0;=20 printf("no descriptor is ready - poll() must return 0: %d\n", poll(p, = 3, 500));=20 printf("no descriptor is ready - revents for any descriptor must be 0: = %d, %d, %d\n", p[0].revents, p[1].revents, p[2].revents);=20 signal(SIGALRM, callback_alarm);=20 alarm(1);=20 printf("SIGALRM - poll() must return -1: %d\n", poll(p, 3, 1500));=20 printf("SIGALRM - revents for any descriptor must be 0: %d, %d, %d\n", = p[0].revents, p[1].revents, p[2].revents);=20 } ------=_NextPart_000_0003_01C1CADD.49048260 Content-Type: application/octet-stream; name="newpoll.cc" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="newpoll.cc" /* poll.cc. Implements poll(2) via usage of select(2) call.=0A= =0A= Copyright 2000, 2001 Red Hat, Inc.=0A= =0A= This file is part of Cygwin.=0A= =0A= This software is a copyrighted work licensed under the terms of the=0A= Cygwin license. Please consult the file "CYGWIN_LICENSE" for=0A= details. */=0A= =0A= #include "winsup.h"=0A= #include =0A= #include =0A= #include =0A= #include =0A= #include "security.h"=0A= #include "fhandler.h"=0A= #include "path.h"=0A= #include "dtable.h"=0A= #include "cygerrno.h"=0A= #include "cygheap.h"=0A= #include "sigproc.h"=0A= =0A= extern "C"=0A= int=0A= poll (struct pollfd *fds, unsigned int nfds, int timeout)=0A= {=0A= int max_fd =3D 0;=0A= fd_set *read_fds, *write_fds, *except_fds;=0A= struct timeval tv =3D { timeout / 1000, (timeout % 1000) * 1000 };=0A= sigframe thisframe (mainthread);=0A= =0A= for (unsigned int i =3D 0; i < nfds; ++i)=0A= if (fds[i].fd > max_fd)=0A= max_fd =3D fds[i].fd;=0A= =0A= size_t fds_size =3D howmany(max_fd + 1, NFDBITS) * sizeof (fd_mask);=0A= =0A= read_fds =3D (fd_set *) alloca (fds_size);=0A= write_fds =3D (fd_set *) alloca (fds_size);=0A= except_fds =3D (fd_set *) alloca (fds_size);=0A= =0A= if (!read_fds || !write_fds || !except_fds)=0A= {=0A= set_errno (ENOMEM);=0A= return -1;=0A= }=0A= =0A= memset (read_fds, 0, fds_size);=0A= memset (write_fds, 0, fds_size);=0A= memset (except_fds, 0, fds_size);=0A= =0A= for (unsigned int i =3D 0; i < nfds; ++i) =0A= { =0A= fds[i].revents =3D 0; =0A= if (!cygheap->fdtab.not_open(fds[i].fd)) =0A= { =0A= if (fds[i].events & POLLIN) =0A= FD_SET(fds[i].fd, read_fds); =0A= if (fds[i].events & POLLOUT) =0A= FD_SET(fds[i].fd, write_fds); =0A= if (fds[i].events & POLLPRI) =0A= FD_SET(fds[i].fd, except_fds); =0A= } =0A= } =0A= =0A= int ret =3D cygwin_select (max_fd + 1, read_fds, write_fds, = except_fds, timeout < 0 ? NULL : &tv);=0A= =0A= if (ret > 0) =0A= for (unsigned int i =3D 0; i < nfds; ++i) =0A= { =0A= if (fds[i].fd < 0) =0A= fds[i].revents =3D POLLNVAL; =0A= else if (cygheap->fdtab.not_open(fds[i].fd)) =0A= fds[i].revents =3D POLLHUP; =0A= else =0A= { =0A= if (FD_ISSET(fds[i].fd, read_fds)) =0A= fds[i].revents |=3D POLLIN; =0A= if (FD_ISSET(fds[i].fd, write_fds)) =0A= fds[i].revents |=3D POLLOUT; =0A= if (FD_ISSET(fds[i].fd, read_fds) && FD_ISSET(fds[i].fd, = write_fds)) =0A= fds[i].revents |=3D POLLERR; =0A= if (FD_ISSET(fds[i].fd, except_fds)) =0A= fds[i].revents |=3D POLLPRI; =0A= } =0A= } =0A= =0A= return ret; =0A= } ------=_NextPart_000_0003_01C1CADD.49048260 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ ------=_NextPart_000_0003_01C1CADD.49048260--