From dev-return-1708-apmail-apr-dev-archive=apr.apache.org@apr.apache.org Wed Mar 21 16:43:29 2001 Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 88464 invoked by uid 500); 21 Mar 2001 16:42:27 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 88079 invoked from network); 21 Mar 2001 16:41:41 -0000 Message-ID: <004501c0b225$9f1017e0$e524180a@VAIO> From: "David Reid" To: Subject: Poll Patch Date: Wed, 21 Mar 2001 16:39:31 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0036_01C0B225.813C4A40" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_0036_01C0B225.813C4A40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Attached is a patch for the unix/beos poll implementations using select. Basically they don't work as we'd expect them to. I found the problem during a coding session last night to get the beos MPM stopping/restarting. The problem is that when we create and setup the pollset we add the fd's to the fd_set and then pass the fd_set into select, where it gets altered, and hence looses some of the information. Imagine the following fd_set has fd 0 and fd 1 select waits for data on fd 0 and fd 1 select finds data on fd 1 fd_set now has fd 1 select waits for data on fd 1 ! :( Not good. This basically means that the select based impl. doesn't have the same behaviour as the poll one and that's something we need to fix. The patch basically adds a second set of fd_set's to the pollset and when you add/remove fd's from the pollset, you affect the new fd_sets. Just before we actually go into select, we copy the new fd_set's into the fd_set we pass to select, and store the results as before. I've tested it on BeOS and if no-one objects I'll commit on Thursday afternoon (GMT). This will impose a bit of a performance penalty, and there may be a better solution, but this works and is simple enough that it illustrates the problem nicely. david ------=_NextPart_000_0036_01C0B225.813C4A40 Content-Type: application/octet-stream; name="poll_patch.dat" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="poll_patch.dat" Index: include/arch/unix/networkio.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /home/cvs/apr/include/arch/unix/networkio.h,v=0A= retrieving revision 1.38=0A= diff -u -r1.38 networkio.h=0A= --- include/arch/unix/networkio.h 2001/02/25 20:39:32 1.38=0A= +++ include/arch/unix/networkio.h 2001/03/21 16:19:54=0A= @@ -144,6 +144,9 @@=0A= fd_set *write;=0A= fd_set *except;=0A= int highsock;=0A= + fd_set *read_set;=0A= + fd_set *write_set;=0A= + fd_set *except_set;=0A= #endif=0A= apr_int16_t *events;=0A= apr_int16_t *revents;=0A= Index: network_io/unix/poll.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /home/cvs/apr/network_io/unix/poll.c,v=0A= retrieving revision 1.44=0A= diff -u -r1.44 poll.c=0A= --- network_io/unix/poll.c 2001/02/16 04:16:02 1.44=0A= +++ network_io/unix/poll.c 2001/03/21 16:20:01=0A= @@ -232,9 +232,15 @@=0A= (*new)->read =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= (*new)->write =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= (*new)->except =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= + (*new)->read_set =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= + (*new)->write_set =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= + (*new)->except_set =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= FD_ZERO((*new)->read);=0A= FD_ZERO((*new)->write);=0A= FD_ZERO((*new)->except);=0A= + FD_ZERO((*new)->read_set);=0A= + FD_ZERO((*new)->write_set);=0A= + FD_ZERO((*new)->except_set);=0A= (*new)->highsock =3D -1;=0A= return APR_SUCCESS;=0A= }=0A= @@ -243,13 +249,13 @@=0A= apr_socket_t *sock, apr_int16_t event)=0A= {=0A= if (event & APR_POLLIN) {=0A= - FD_SET(sock->socketdes, aprset->read);=0A= + FD_SET(sock->socketdes, aprset->read_set);=0A= }=0A= if (event & APR_POLLPRI) {=0A= - FD_SET(sock->socketdes, aprset->except);=0A= + FD_SET(sock->socketdes, aprset->except_set);=0A= }=0A= if (event & APR_POLLOUT) {=0A= - FD_SET(sock->socketdes, aprset->write);=0A= + FD_SET(sock->socketdes, aprset->write_set);=0A= }=0A= if (sock->socketdes > aprset->highsock) {=0A= aprset->highsock =3D sock->socketdes;=0A= @@ -262,13 +268,13 @@=0A= apr_int16_t events)=0A= {=0A= if (events & APR_POLLIN) {=0A= - FD_CLR(sock->socketdes, aprset->read);=0A= + FD_CLR(sock->socketdes, aprset->read_set);=0A= }=0A= if (events & APR_POLLPRI) {=0A= - FD_CLR(sock->socketdes, aprset->except);=0A= + FD_CLR(sock->socketdes, aprset->except_set);=0A= }=0A= if (events & APR_POLLOUT) {=0A= - FD_CLR(sock->socketdes, aprset->write);=0A= + FD_CLR(sock->socketdes, aprset->write_set);=0A= }=0A= return APR_SUCCESS;=0A= }=0A= @@ -288,6 +294,10 @@=0A= tvptr =3D &tv;=0A= }=0A= =0A= + memcpy(aprset->read, aprset->read_set, sizeof(fd_set));=0A= + memcpy(aprset->write, aprset->write_set, sizeof(fd_set));=0A= + memcpy(aprset->except, aprset->except_set, sizeof(fd_set));=0A= +=0A= rv =3D select(aprset->highsock + 1, aprset->read, aprset->write, =0A= aprset->except, tvptr);=0A= =0A= @@ -306,7 +316,7 @@=0A= apr_int16_t revents =3D 0;=0A= char data[1];=0A= int flags =3D MSG_PEEK;=0A= -=0A= + =0A= /* We just want to PEEK at the data, so I am setting up a dummy = WSABUF=0A= * variable here.=0A= */=0A= @@ -350,22 +360,22 @@=0A= =0A= apr_status_t apr_poll_socket_remove(apr_pollfd_t *aprset, apr_socket_t = *sock)=0A= {=0A= - FD_CLR(sock->socketdes, aprset->read);=0A= - FD_CLR(sock->socketdes, aprset->except);=0A= - FD_CLR(sock->socketdes, aprset->write);=0A= + FD_CLR(sock->socketdes, aprset->read_set);=0A= + FD_CLR(sock->socketdes, aprset->except_set);=0A= + FD_CLR(sock->socketdes, aprset->write_set);=0A= return APR_SUCCESS;=0A= }=0A= =0A= apr_status_t apr_poll_socket_clear(apr_pollfd_t *aprset, apr_int16_t = event)=0A= {=0A= if (event & APR_POLLIN) {=0A= - FD_ZERO(aprset->read);=0A= + FD_ZERO(aprset->read_set);=0A= }=0A= if (event & APR_POLLPRI) {=0A= - FD_ZERO(aprset->except);=0A= + FD_ZERO(aprset->except_set);=0A= }=0A= if (event & APR_POLLOUT) {=0A= - FD_ZERO(aprset->write);=0A= + FD_ZERO(aprset->write_set);=0A= }=0A= aprset->highsock =3D 0;=0A= return APR_SUCCESS;=0A= Index: network_io/beos/poll.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /home/cvs/apr/network_io/beos/poll.c,v=0A= retrieving revision 1.26=0A= diff -u -r1.26 poll.c=0A= --- network_io/beos/poll.c 2001/02/16 04:16:00 1.26=0A= +++ network_io/beos/poll.c 2001/03/21 16:20:06=0A= @@ -77,9 +77,15 @@=0A= (*new)->read =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= (*new)->write =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= (*new)->except =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= + (*new)->read_set =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= + (*new)->write_set =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= + (*new)->except_set =3D (fd_set *)apr_pcalloc(cont, sizeof(fd_set));=0A= FD_ZERO((*new)->read);=0A= FD_ZERO((*new)->write);=0A= FD_ZERO((*new)->except);=0A= + FD_ZERO((*new)->read_set);=0A= + FD_ZERO((*new)->write_set);=0A= + FD_ZERO((*new)->except_set);=0A= (*new)->highsock =3D -1;=0A= return APR_SUCCESS;=0A= }=0A= @@ -88,13 +94,13 @@=0A= apr_socket_t *sock, apr_int16_t event)=0A= {=0A= if (event & APR_POLLIN) {=0A= - FD_SET(sock->socketdes, aprset->read);=0A= + FD_SET(sock->socketdes, aprset->read_set);=0A= }=0A= if (event & APR_POLLPRI) {=0A= - FD_SET(sock->socketdes, aprset->read);=0A= + FD_SET(sock->socketdes, aprset->read_set);=0A= }=0A= if (event & APR_POLLOUT) {=0A= - FD_SET(sock->socketdes, aprset->write);=0A= + FD_SET(sock->socketdes, aprset->write_set);=0A= }=0A= if (sock->socketdes > aprset->highsock) {=0A= aprset->highsock =3D sock->socketdes;=0A= @@ -107,13 +113,13 @@=0A= apr_int16_t events)=0A= {=0A= if (events & APR_POLLIN) {=0A= - FD_CLR(sock->socketdes, aprset->read);=0A= + FD_CLR(sock->socketdes, aprset->read_set);=0A= }=0A= if (events & APR_POLLPRI) {=0A= - FD_CLR(sock->socketdes, aprset->except);=0A= + FD_CLR(sock->socketdes, aprset->except_set);=0A= }=0A= if (events & APR_POLLOUT) {=0A= - FD_CLR(sock->socketdes, aprset->write);=0A= + FD_CLR(sock->socketdes, aprset->write_set);=0A= }=0A= return APR_SUCCESS;=0A= }=0A= @@ -133,6 +139,10 @@=0A= tvptr =3D &tv;=0A= }=0A= =0A= + memcpy(aprset->read, aprset->read_set, sizeof(fd_set));=0A= + memcpy(aprset->write, aprset->write_set, sizeof(fd_set));=0A= + memcpy(aprset->except, aprset->except_set, sizeof(fd_set));=0A= +=0A= rv =3D select(aprset->highsock + 1, aprset->read, aprset->write, =0A= aprset->except, tvptr);=0A= =0A= @@ -192,22 +202,22 @@=0A= =0A= apr_status_t apr_poll_socket_remove(apr_pollfd_t *aprset, apr_socket_t = *sock)=0A= {=0A= - FD_CLR(sock->socketdes, aprset->read);=0A= - FD_CLR(sock->socketdes, aprset->read);=0A= - FD_CLR(sock->socketdes, aprset->write);=0A= + FD_CLR(sock->socketdes, aprset->read_set);=0A= + FD_CLR(sock->socketdes, aprset->except_set);=0A= + FD_CLR(sock->socketdes, aprset->write_set);=0A= return APR_SUCCESS;=0A= }=0A= =0A= apr_status_t apr_poll_socket_clear(apr_pollfd_t *aprset, apr_int16_t = event)=0A= {=0A= if (event & APR_POLLIN) {=0A= - FD_ZERO(aprset->read);=0A= + FD_ZERO(aprset->read_set);=0A= }=0A= if (event & APR_POLLPRI) {=0A= - FD_ZERO(aprset->read);=0A= + FD_ZERO(aprset->except_set);=0A= }=0A= if (event & APR_POLLOUT) {=0A= - FD_ZERO(aprset->write);=0A= + FD_ZERO(aprset->write_set);=0A= }=0A= aprset->highsock =3D 0;=0A= return APR_SUCCESS;=0A= ------=_NextPart_000_0036_01C0B225.813C4A40--