rbb 99/04/28 09:00:10
Modified: apr/network_io/unix Makefile networkio.h apr/test client.c server.c testsock.c include apr_network_io.h docs networkio.txt Added: apr/network_io/unix poll.c Removed: apr/network_io/unix select.c Log: Changed apr_select to apr_poll. It looks more portable, and it was what we had originally designed, so I went back to it. I also updated the test suite to use apr_poll instead of apr_select. Revision Changes Path 1.5 +3 -2 apache-apr/apr/network_io/unix/Makefile Index: Makefile =================================================================== RCS file: /home/cvs/apache-apr/apr/network_io/unix/Makefile,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Makefile 1999/04/14 19:17:18 1.4 +++ Makefile 1999/04/28 16:00:05 1.5 @@ -47,7 +47,7 @@ LIB= libnetwork.a -OBJS= sockets.o sendrecv.o sockopt.o select.o +OBJS= sockets.o sendrecv.o sockopt.o poll.o .c.o: $(CC) -c $(INCLUDES) $(CFLAGS) $< @@ -85,4 +85,5 @@ sockets.o: sockets.c sendrecv.o: sendrecv.c sockopt.o: sockopt.c -select.o: select.c +poll.o: poll.c + 1.6 +16 -1 apache-apr/apr/network_io/unix/networkio.h Index: networkio.h =================================================================== RCS file: /home/cvs/apache-apr/apr/network_io/unix/networkio.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- networkio.h 1999/04/15 20:08:15 1.5 +++ networkio.h 1999/04/28 16:00:06 1.6 @@ -56,6 +56,17 @@ #ifndef NETWORK_IO_H #define NETWORK_IO_H +#include "apr_network_io.h" +#include "apr_general.h" +#include <poll.h> + +#define APOLLIN POLLIN +#define APOLLPRI POLLPRI +#define APOLLOUT POLLOUT +#define APOLLERR POLLERR +#define APOLLHUP POLLHUP +#define APOLLNVAL POLLNVAL + struct socket_t { int socketdes; char *remote_hostname; @@ -63,7 +74,11 @@ size_t addr_len; }; -typedef fd_set sd_set_t; +struct pollfd_t { + struct socket_t *sock; + apr_int16_t events; + apr_int16_t revents; +}; #endif /* ! NETWORK_IO_H */ 1.1 apache-apr/apr/network_io/unix/poll.c Index: poll.c =================================================================== /* ==================================================================== * Copyright (c) 1999 The Apache Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * 4. The names "Apache Server" and "Apache Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Group. * For more information on the Apache Group and the Apache HTTP server * project, please see <http://www.apache.org/>. * */ #include "apr_network_io.h" #include "networkio.h" #include "apr_general.h" #include <errno.h> #include <sys/poll.h> apr_int32_t apr_poll(apr_pollfd_t *aprset, apr_int32_t nsds, apr_int32_t timeout) { int i; struct pollfd *pollset; pollset = (struct pollfd *)malloc(sizeof(struct pollfd) * nsds); for (i = 0; i < nsds; i++) { pollset[i].fd = aprset[i].sock->socketdes; pollset[i].events = aprset[i].events; } poll(pollset, nsds, timeout); for (i = 0; i < nsds; i++) { pollset[i].revents = aprset[i].revents; } } 1.2 +1 -2 apache-apr/apr/test/client.c Index: client.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/client.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- client.c 1999/04/28 14:30:25 1.1 +++ client.c 1999/04/28 16:00:08 1.2 @@ -67,7 +67,6 @@ int main(int argc, char *argv[]) { apr_socket_t *sock; - apr_sd_set_t *sdset; apr_int32_t rv; struct timeval timeout; char datasend[STRLEN] = "Send data test"; @@ -97,7 +96,7 @@ fprintf(stdout, "OK\n"); fprintf(stdout, "\tClient: Connecting to socket......."); - if (apr_connect(sock, "localhost", 8021) == APR_FAILURE) { + if (apr_connect(sock, "localhost") == APR_FAILURE) { apr_close_socket(sock); fprintf(stderr, "Could not connect\n"); exit(-1); 1.2 +6 -6 apache-apr/apr/test/server.c Index: server.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/server.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- server.c 1999/04/28 14:30:25 1.1 +++ server.c 1999/04/28 16:00:08 1.2 @@ -68,8 +68,8 @@ { apr_socket_t *sock; apr_socket_t *sock2; - apr_sd_set_t sdset; apr_int32_t rv; + apr_pollfd_t sdset; char datasend[STRLEN]; char datarecv[STRLEN] = "Recv data test"; @@ -112,13 +112,13 @@ } fprintf(stdout, "OK\n"); - fprintf(stdout, "\tServer: Setting up sd sets......."); - apr_sd_zero(&sdset); - apr_sd_set(sock, &sdset); - fprintf(stdout, "Setup done\n"); + fprintf(stdout, "\tServer: Setting up socket for polling......."); + sdset.sock = sock; + sdset.events = APR_POLLIN; + fprintf(stdout, "OK\n"); fprintf(stdout, "\tServer: Beginning to select on socket......."); - rv = apr_select(sock->socketdes + 1, &sdset, &sdset, &sdset, NULL); + rv = apr_poll(&sdset, 1, 0); if (rv == -1) { apr_close_socket(sock); fprintf(stderr, "Select caused an error\n"); 1.2 +3 -3 apache-apr/apr/test/testsock.c Index: testsock.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testsock.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- testsock.c 1999/04/28 14:30:25 1.1 +++ testsock.c 1999/04/28 16:00:08 1.2 @@ -74,7 +74,7 @@ fprintf(stdout, "This test relies on the process test working. Please\n"); fprintf(stdout, "run that test first, and only run this test when it\n"); fprintf(stdout, "completes successfully. Alternitevly, you could run\n"); - fprintf(stdout, "parnetio and childnetio by yourself.\n"); + fprintf(stdout, "server and client by yourself.\n"); fprintf(stdout, "Creating children to run network tests.......\n"); attr1 = apr_createprocattr_init(); @@ -86,8 +86,8 @@ exit(-1); } - proc1 = apr_create_process("parnetio", NULL, NULL, attr1); - proc2 = apr_create_process("childnetio", NULL, NULL, attr2); + proc1 = apr_create_process("server", NULL, NULL, attr1); + proc2 = apr_create_process("client", NULL, NULL, attr2); if (proc1 == NULL || proc2 == NULL) { fprintf(stderr, "Problem spawning new process\n"); 1.14 +10 -7 apache-apr/include/apr_network_io.h Index: apr_network_io.h =================================================================== RCS file: /home/cvs/apache-apr/include/apr_network_io.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- apr_network_io.h 1999/04/26 13:07:50 1.13 +++ apr_network_io.h 1999/04/28 16:00:09 1.14 @@ -75,11 +75,18 @@ #define APR_SO_NONBLOCK 8 #define APR_SO_REUSEADDR 16 +#define APR_POLLIN APOLLIN +#define APR_POLLPRI APOLLPRI +#define APR_POLLOUT APOLLOUT +#define APR_POLLERR APOLLERR +#define APR_POLLHUP APOLLHUP +#define APR_POLLNVAL APOLLNVAL + typedef enum {APR_SHUTDOWN_READ, APR_SHUTDOWN_WRITE, APR_SHUTDOWN_READWRITE} apr_shutdown_how_e; typedef struct socket_t apr_socket_t; -typedef sd_set_t apr_sd_set_t; +typedef struct pollfd_t apr_pollfd_t; /* function definitions */ @@ -90,7 +97,7 @@ apr_status_t apr_bind(apr_socket_t *); apr_status_t apr_listen(apr_socket_t *, apr_int32_t); apr_socket_t *apr_accept(const apr_socket_t *); -apr_status_t apr_connect(apr_socket_t *, char *, unsigned short); +apr_status_t apr_connect(apr_socket_t *, char *); char *apr_get_remote_hostname(apr_socket_t *); apr_status_t apr_gethostname(char *, int); @@ -100,12 +107,8 @@ apr_status_t apr_setsocketopt(apr_socket_t *, apr_int32_t, apr_int32_t); apr_status_t apr_setport(apr_socket_t *, apr_uint32_t); - -void apr_sd_set(apr_socket_t *, apr_sd_set_t *); -void apr_sd_clr(apr_socket_t *, apr_sd_set_t *); -apr_status_t apr_sd_isset(apr_socket_t *, apr_sd_set_t *); -void apr_sd_zero(apr_sd_set_t *); +apr_int32_t apr_poll(apr_pollfd_t *, apr_int32_t, apr_int32_t); /* accessor functions */ #endif /* ! APR_FILE_IO_H */ 1.19 +20 -9 apache-apr/docs/networkio.txt Index: networkio.txt =================================================================== RCS file: /home/cvs/apache-apr/docs/networkio.txt,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- networkio.txt 1999/04/27 14:13:37 1.18 +++ networkio.txt 1999/04/28 16:00:09 1.19 @@ -86,16 +86,21 @@ Arguments: arg 1) The apr_sd_set we are clearing. - apr_int32_t apr_select(apr_int32 nsd, apr_apr_sd_set_t *readset, apr_sd_set_t *writeset, apr_sd_set_t *exceptset, struct timeval timeout) - Monitor sockets for one of three possible conditions. + apr_int32_t apr_poll(apr_pollfd_t *, apr_int32_t, apr_int32_t) + Monitor sockets for specifiedconditions. Arguments: - arg 1) The number of sockets to check. Must be at least one greater - than the size of the biggest set. - arg 2) The set of sockets to check for data to read - arg 3) The set of sockets to check if they are ready for writing. - arg 4) The set of sockets to check for exceptional conditions. - arg 5) The length of time to wait until a socket is triggered - in one of the sets. + arg 1) an array of sockets to monitor and events to wait for. + valid events are: + APR_POLLIN data to be read + APR_POLLPRI urgent data to be read + APR_POLLOUT a write will not block + Only valid in return events: + APR_ERR an error occured + APR_HUP Hung up + APR_NVAL Invalid rquest, socket not open. + arg 2) the number of sockets in the array. + arg 3) the amount of time in seconds to monitor. 0 means wait + until a socket is triggered. return) Number of file desriptors triggered. 0 means call timed out. -1 returned on failure. @@ -234,4 +239,10 @@ char *remote_hostname struct sockaddr *addr size_t addr_len +} + +struct apr_pollfd_t { + apr_socket_t *sock + apr_int16_t events + apr_int16_t revents }