httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/network_io/unix inet_aton.c networkio.h poll.c sendrecv.c sockets.c sockopt.c
Date Tue, 16 May 2000 20:35:51 GMT
rbb         00/05/16 13:35:49

  Modified:    src/lib/apr/network_io/unix networkio.h poll.c sendrecv.c
                        sockets.c sockopt.c
  Added:       src/lib/apr/network_io/unix inet_aton.c
  Removed:     src/lib/apr/network_io/beos Makefile.in inet_aton.c
                        networkio.h poll.c sendrecv.c sockaddr.c sockets.c
                        sockopt.c
  Log:
  Remove the beos network I/O code and merge it with the unix code.  Most
  of this was common code already.
  
  Revision  Changes    Path
  1.26      +24 -0     apache-2.0/src/lib/apr/network_io/unix/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/networkio.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- networkio.h	2000/04/26 18:25:53	1.25
  +++ networkio.h	2000/05/16 20:35:38	1.26
  @@ -104,8 +104,28 @@
   #if HAVE_SYS_SENDFILE_H
   #include <sys/sendfile.h>
   #endif
  +#if HAVE_BYTEORDER_H
  +#include <ByteOrder.h>  /* for ntohs on BeOS */
  +#endif
   /* End System Headers */
   
  +/* The definition of isascii was missed from the PowerPC ctype.h
  + *
  + * It will be included in the next release, but until then... 
  + */
  +#if (HAVE_ISASCII == 0)
  +#define isascii(c) (((c) & ~0x7f)==0)
  +#endif
  +
  +#ifndef HAVE_POLLIN
  +#define POLLIN   1
  +#define POLLPRI  2
  +#define POLLOUT  4
  +#define POLLERR  8
  +#define POLLHUP  16
  +#define POLLNVAL 32
  +#endif
  +
   struct ap_socket_t {
       ap_pool_t *cntxt;
       int socketdes;
  @@ -134,6 +154,10 @@
       ap_int16_t *revents;
   
   };
  +
  +#if BEOS
  +int inet_aton(const char *cp, struct in_addr *addr);
  +#endif
   
   #endif  /* ! NETWORK_IO_H */
   
  
  
  
  1.32      +19 -3     apache-2.0/src/lib/apr/network_io/unix/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/poll.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- poll.c	2000/05/01 00:38:23	1.31
  +++ poll.c	2000/05/16 20:35:39	1.32
  @@ -272,7 +272,11 @@
       }
   
       rv = select(aprset->highsock + 1, aprset->read, aprset->write, 
  -                    aprset->except, tvptr);
  +#ifdef BEOS
  +                NULL, tvptr);
  +#else
  +                aprset->except, tvptr);
  +#endif
       
       (*nsds) = rv;
       if ((*nsds) == 0) {
  @@ -296,7 +300,14 @@
       if (FD_ISSET(sock->socketdes, aprset->read)) {
           revents |= APR_POLLIN;
           if (sock->connected
  +#ifdef BEOS
  +            /* XXX I would really like to understand why this difference
  +             * exists.  Can we get rid of it?  rbb
  +             */
  +	    && recv(sock->socketdes, data, 0, 0) == -1) {
  +#else
   	    && recv(sock->socketdes, data, sizeof data, flags) == -1) {
  +#endif
               switch (errno) {
                   case ECONNRESET:
                   case ECONNABORTED:
  @@ -308,17 +319,22 @@
                   case ENOTSOCK:
                       revents ^= APR_POLLIN;
                       revents |= APR_POLLNVAL;
  -		    break;
  +                    break;
                   default:
                       revents ^= APR_POLLIN;
                       revents |= APR_POLLERR;
  -		    break;
  +                    break;
               }
           }
       }
  +#ifndef BEOS
  +    /* Still no support for execpt bits in BeOS R4.5 so for the time being */
  +    /* we can't check this.  Hopefully the error checking above will allow */
  +    /* sufficient errors to be recognised to cover this. */
       if (FD_ISSET(sock->socketdes, aprset->write)) {
           revents |= APR_POLLOUT;
       }
  +#endif
       /* I am assuming that the except is for out of band data, not a failed
        * connection on a non-blocking socket.  Might be a bad assumption, but
        * it works for now. rbb.
  
  
  
  1.22      +33 -21    apache-2.0/src/lib/apr/network_io/unix/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sendrecv.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- sendrecv.c	2000/04/16 16:59:38	1.21
  +++ sendrecv.c	2000/05/16 20:35:39	1.22
  @@ -54,6 +54,17 @@
   
   #include "networkio.h"
   
  +/* BeOS needs to use send/recv for socket I/O, this allows us to do that
  + * with minimal changes in the code.
  + */
  +#ifdef BEOS
  +#define WRITE(x,y,z)  send(x,y,z,0)
  +#define READ(x,y,z)   recv(x,y,z,0)
  +#else
  +#define WRITE(x,y,z)  write(x,y,z)
  +#define READ(x,y,z)   read(x,y,z)
  +#endif
  +
   #ifdef HAVE_SENDFILE
   /* This file is needed to allow us access to the ap_file_t internals. */
   #include "../../file_io/unix/fileio.h"
  @@ -74,8 +85,8 @@
       int srv;
   
       do {
  -	FD_ZERO(&fdset);
  -	FD_SET(sock->socketdes, &fdset);
  +        FD_ZERO(&fdset);
  +        FD_SET(sock->socketdes, &fdset);
           if (sock->timeout < 0) {
               tvptr = NULL;
           }
  @@ -84,19 +95,19 @@
               tv.tv_usec = sock->timeout % AP_USEC_PER_SEC;
               tvptr = &tv;
           }
  -	srv = select(sock->socketdes + 1,
  -	    for_read ? &fdset : NULL,
  -	    for_read ? NULL : &fdset,
  -	    NULL,
  -	    tvptr);
  +        srv = select(sock->socketdes + 1,
  +            for_read ? &fdset : NULL,
  +            for_read ? NULL : &fdset,
  +            NULL,
  +            tvptr);
           /* TODO - timeout should be smaller on repeats of this loop */
       } while (srv == -1 && errno == EINTR);
   
       if (srv == 0) {
  -	return APR_TIMEUP;
  +        return APR_TIMEUP;
       }
       else if (srv < 0) {
  -	return errno;
  +        return errno;
       }
       return APR_SUCCESS;
   }
  @@ -106,20 +117,19 @@
       ssize_t rv;
       
       do {
  -        rv = write(sock->socketdes, buf, (*len));
  +        rv = WRITE(sock->socketdes, buf, (*len));
       } while (rv == -1 && errno == EINTR);
   
  -    if (rv == -1 && 
  -        (errno == EAGAIN || errno == EWOULDBLOCK) && 
  -        sock->timeout != 0) {
  -	ap_status_t arv = wait_for_io_or_timeout(sock, 0);
  -	if (arv != APR_SUCCESS) {
  -	    *len = 0;
  -	    return arv;
  -	}
  +    if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) 
  +        && sock->timeout != 0) {
  +        ap_status_t arv = wait_for_io_or_timeout(sock, 0);
  +        if (arv != APR_SUCCESS) {
  +            *len = 0;
  +            return arv;
  +        }
           else {
               do {
  -                rv = write(sock->socketdes, buf, (*len));
  +                rv = WRITE(sock->socketdes, buf, (*len));
               } while (rv == -1 && errno == EINTR);
           }
       }
  @@ -136,7 +146,7 @@
       ssize_t rv;
       
       do {
  -        rv = read(sock->socketdes, buf, (*len));
  +        rv = READ(sock->socketdes, buf, (*len));
       } while (rv == -1 && errno == EINTR);
   
       if (rv == -1 && 
  @@ -149,7 +159,7 @@
   	}
           else {
               do {
  -                rv = read(sock->socketdes, buf, (*len));
  +                rv = READ(sock->socketdes, buf, (*len));
               } while (rv == -1 && errno == EINTR);
           }
       }
  @@ -161,6 +171,7 @@
       return APR_SUCCESS;
   }
   
  +#ifdef HAVE_WRITEV
   ap_status_t ap_sendv(ap_socket_t * sock, const struct iovec *vec,
                        ap_int32_t nvec, ap_int32_t *len)
   {
  @@ -191,6 +202,7 @@
       (*len) = rv;
       return APR_SUCCESS;
   }
  +#endif
   
   #if defined(HAVE_SENDFILE)
   
  
  
  
  1.43      +20 -7     apache-2.0/src/lib/apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- sockets.c	2000/05/04 03:43:49	1.42
  +++ sockets.c	2000/05/16 20:35:39	1.43
  @@ -55,10 +55,19 @@
   #include "networkio.h"
   #include "apr_portable.h"
   
  +/* BeOS uses closesocket instead of close to close their sockets and they
  + * don't provide inet_aton.  This small ifndef takes care of both problems.
  + */
  +#ifndef BEOS
  +#define closesocket  close
  +#else
  +#include "inet_aton.c"
  +#endif
  +
   static ap_status_t socket_cleanup(void *sock)
   {
       ap_socket_t *thesocket = sock;
  -    if (close(thesocket->socketdes) == 0) {
  +    if (closesocket(thesocket->socketdes) == 0) {
           thesocket->socketdes = -1;
           return APR_SUCCESS;
       }
  @@ -102,6 +111,9 @@
   
   ap_status_t ap_shutdown(ap_socket_t *thesocket, ap_shutdown_how_e how)
   {
  +#ifdef BEOS
  +    return shutdown(thesocket->socketdes, how);
  +#endif
       if (shutdown(thesocket->socketdes, how) == 0) {
           return APR_SUCCESS;
       }
  @@ -169,6 +181,9 @@
   {
       struct hostent *hp;
   
  +    if ((sock->socketdes < 0) || (!sock->remote_addr)) {
  +        return APR_ENOTSOCK;
  +    }
       if (hostname != NULL) {
   #ifndef GETHOSTBYNAME_HANDLES_NAS
           if (*hostname >= '0' && *hostname <= '9' &&
  @@ -180,14 +195,12 @@
   #endif
           hp = gethostbyname(hostname);
   
  -        if ((sock->socketdes < 0) || (!sock->remote_addr)) {
  -            return APR_ENOTSOCK;
  -        }
           if (!hp)  {
               return (h_errno + APR_OS_START_SYSERR);
           }
       
  -        memcpy((char *)&sock->remote_addr->sin_addr, hp->h_addr_list[0], hp->h_length);
  +        memcpy((char *)&sock->remote_addr->sin_addr, hp->h_addr_list[0], 
  +               hp->h_length);
   
           sock->addr_len = sizeof(*sock->remote_addr);
   #ifndef GETHOSTBYNAME_HANDLES_NAS
  @@ -195,8 +208,8 @@
   #endif
       }
   
  -    if ((connect(sock->socketdes, (const struct sockaddr *)sock->remote_addr, sock->addr_len)
< 0) &&
  -        (errno != EINPROGRESS)) {
  +    if ((connect(sock->socketdes, (const struct sockaddr *)sock->remote_addr,
  +        sock->addr_len) < 0) && (errno != EINPROGRESS)) {
           return errno;
       }
       else {
  
  
  
  1.25      +4 -0      apache-2.0/src/lib/apr/network_io/unix/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockopt.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- sockopt.c	2000/05/12 10:38:34	1.24
  +++ sockopt.c	2000/05/16 20:35:39	1.25
  @@ -123,9 +123,13 @@
           }
       }
       if (opt & APR_SO_SNDBUF) {
  +#ifdef BEOS
  +        return APR_ENOTIMPLE;
  +#else
           if (setsockopt(sock->socketdes, SOL_SOCKET, SO_SNDBUF, (void *)&on, sizeof(int))
== -1) {
               return errno;
           }
  +#endif
       }
       if (opt & APR_SO_NONBLOCK) {
   #ifndef BEOS
  
  
  
  1.1                  apache-2.0/src/lib/apr/network_io/unix/inet_aton.c
  
  Index: inet_aton.c
  ===================================================================
  /*
   * Copyright (c) 1983, 1990, 1993
   *    The Regents of the University of California.  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 acknowledgement:
   * 	This product includes software developed by the University of
   * 	California, Berkeley and its contributors.
   * 4. Neither the name of the University nor the names of its contributors
   *    may be used to endorse or promote products derived from this software
   *    without specific prior written permission.
   * 
   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   * ANY EXPRESS 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 REGENTS OR 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.
   */
  
  /*
   * Portions Copyright (c) 1993 by Digital Equipment Corporation.
   * 
   * Permission to use, copy, modify, and distribute this software for any
   * purpose with or without fee is hereby granted, provided that the above
   * copyright notice and this permission notice appear in all copies, and that
   * the name of Digital Equipment Corporation not be used in advertising or
   * publicity pertaining to distribution of the document or software without
   * specific, written prior permission.
   * 
   * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
   * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
   * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
   * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
   * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
   * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
   * SOFTWARE.
   */
  
  /*
   * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
   *
   * Permission to use, copy, modify, and distribute this software for any
   * purpose with or without fee is hereby granted, provided that the above
   * copyright notice and this permission notice appear in all copies.
   *
   * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
   * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
   * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
   * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
   * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
   * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
   * SOFTWARE.
   */
  
  #include "apr_private.h"
  #ifndef HAVE_NETINET_TCP_H
  
  #include "networkio.h"
  
  /* BeOS doesn't yet have it's own inet_aton and Bind won't be ported
   * until R5, so this is from a Bind 8 distribution.  It's currently untested.
   */
  
  int inet_aton(const char *cp, struct in_addr *addr) {
  	u_long val;
  	int base, n;
  	char c;
  	short parts[4];
  	short *pp = parts;
  	int digit;
  
  	c = *cp;
  	for (;;) {
  		/*
  		 * Collect number up to ``.''.
  		 * Values are specified as for C:
  		 * 0x=hex, 0=octal, isdigit=decimal.
  		 */
  		if (!isdigit(c))
  			return (0);
  		val = 0; base = 10; digit = 0;
  		if (c == '0') {
  			c = *++cp;
  			if (c == 'x' || c == 'X')
  				base = 16, c = *++cp;
  			else {
  				base = 8;
  				digit = 1 ;
  			}
  		}
  		for (;;) {
  			if (isascii(c) && isdigit(c)) {
  				if (base == 8 && (c == '8' || c == '9'))
  					return (0);
  				val = (val * base) + (c - '0');
  				c = *++cp;
  				digit = 1;
  			} else if (base == 16 && isascii(c) && isxdigit(c)) {
  				val = (val << 4) |
  					(c + 10 - (islower(c) ? 'a' : 'A'));
  				c = *++cp;
  				digit = 1;
  			} else
  				break;
  		}
  		if (c == '.') {
  			/*
  			 * Internet format:
  			 *	a.b.c.d
  			 *	a.b.c	(with c treated as 16 bits)
  			 *	a.b	(with b treated as 24 bits)
  			 */
  			if (pp >= parts + 3 || val > 0xff)
  				return (0);
  			*pp++ = val;
  			c = *++cp;
  		} else
  			break;
  	}
  	/*
  	 * Check for trailing characters.
  	 */
  	if (c != '\0' && (!isascii(c) || !isspace(c)))
  		return (0);
  	/*
  	 * Did we get a valid digit?
  	 */
  	if (!digit)
  		return (0);
  	/*
  	 * Concoct the address according to
  	 * the number of parts specified.
  	 */
  	n = pp - parts + 1;
  	switch (n) {
  	case 1:				/* a -- 32 bits */
  		break;
  
  	case 2:				/* a.b -- 8.24 bits */
  		if (val > 0xffffff)
  			return (0);
  		val |= parts[0] << 24;
  		break;
  
  	case 3:				/* a.b.c -- 8.8.16 bits */
  		if (val > 0xffff)
  			return (0);
  		val |= (parts[0] << 24) | (parts[1] << 16);
  		break;
  
  	case 4:				/* a.b.c.d -- 8.8.8.8 bits */
  		if (val > 0xff)
  			return (0);
  		val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
  		break;
  	}
  	if (addr != NULL)
  		addr->s_addr = htonl(val);
  	return (1);
  }
  #endif
  
  
  

Mime
View raw message