rbb         99/10/02 16:11:38

  Modified:    src/lib/apr/network_io/beos Makefile.in networkio.h
                        sendrecv.c sockets.c sockopt.c
  Added:       src/lib/apr/network_io/beos inet_aton.c
  Log:
  Update BeOS network code.  This should bring it up to the same level
  as the Unix code.
  Submitted by:  David Reid
  
  Revision  Changes    Path
  1.3       +2 -1      apache-2.0/src/lib/apr/network_io/beos/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/beos/Makefile.in,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Makefile.in       1999/08/27 16:26:03     1.2
  +++ Makefile.in       1999/10/02 23:11:36     1.3
  @@ -9,7 +9,7 @@
   [EMAIL PROTECTED]@
   [EMAIL PROTECTED]@ $(LIBS)
   INCDIR=../../inc
  -INCDIR1=../../include
  +INCDIR1=../../include -I../../file_io/unix
   INCLUDES=-I$(INCDIR) -I$(INCDIR1) -I.
   
   LIB=libnetwork.a
  @@ -18,6 +18,7 @@
        sendrecv.o \
        sockets.o \
        sockopt.o \
  +         inet_aton.o
   
   .c.o:
        $(CC) $(CFLAGS) -c $(INCLUDES) $<
  
  
  
  1.2       +4 -0      apache-2.0/src/lib/apr/network_io/beos/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/beos/networkio.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- networkio.h       1999/08/17 15:59:43     1.1
  +++ networkio.h       1999/10/02 23:11:36     1.2
  @@ -59,6 +59,7 @@
   #include <socket.h>
   #include <netdb.h>
   #include "apr_general.h"
  +#include <ByteOrder.h> /* for the ntohs definition */
   
   #define POLLIN        1
   #define POLLPRI  2
  @@ -73,6 +74,7 @@
       char *remote_hostname;
       struct sockaddr_in * addr;
       int addr_len;
  +    int timeout;
   };
   
   struct pollfd_t {
  @@ -85,6 +87,8 @@
   };
   
   ap_int16_t get_event(ap_int16_t);
  +
  +int inet_aton(const char *cp, struct in_addr *addr);
   
   #endif  /* ! NETWORK_IO_H */
   
  
  
  
  1.2       +38 -21    apache-2.0/src/lib/apr/network_io/beos/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/beos/sendrecv.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sendrecv.c        1999/08/17 15:59:43     1.1
  +++ sendrecv.c        1999/10/02 23:11:36     1.2
  @@ -59,40 +59,49 @@
   #include <socket.h>
   #include <netdb.h>
   #include "networkio.h"
  +#include "fileio.h"
   #include "apr_errno.h"
   #include "apr_general.h"
   #include "apr_network_io.h"
   
  -ap_status_t ap_send(struct socket_t *sock, const char *buf, ap_ssize_t *len, 
time_t sec)
  +ap_status_t ap_send(struct socket_t *sock, const char *buf, ap_ssize_t *len)
   {
       ssize_t rv;
  -     int sendlen = *len;
        
       do {
  -        rv = send(sock->socketdes, buf, sendlen,0);
  +        rv = send(sock->socketdes, buf, (*len), 0);
       } while (rv == -1 && errno == EINTR);
   
  -    if (rv == -1 && errno == EAGAIN && sec > 0) {
  -        struct timeval tv;
  +    if (rv == -1 && errno == EAGAIN && sock->timeout > 0) {
  +        struct timeval *tv;
           fd_set fdset;
           int srv;
   
           do {
               FD_ZERO(&fdset);
               FD_SET(sock->socketdes, &fdset);
  -            tv.tv_sec  = sec;
  -            tv.tv_usec = 0;
  -
  -            srv = select(FD_SETSIZE, NULL, &fdset, NULL, &tv);
  +            if (sock->timeout == -1)
  +                tv = NULL;
  +            else {
  +                tv = (struct timeval *)ap_palloc(sock->cntxt, sizeof(struct 
timeval));
  +                tv->tv_sec  = sock->timeout;
  +                tv->tv_usec = 0;
  +            }
  +            
  +            srv = select(FD_SETSIZE, NULL, &fdset, NULL, tv);
           } while (srv == -1 && errno == EINTR);
   
  +        if (srv == 0) {
  +            (*len) = -1;
  +            return APR_TIMEUP;
  +        }
           if (srv < 1) {
               (*len) = -1;
               return errno;
           }
           else {
               do {
  -                rv = send(sock->socketdes, buf, sendlen,0);
  +                rv = send(sock->socketdes, buf, (*len),0);
               } while (rv == -1 && errno == EINTR);
           }
       }
  @@ -100,36 +109,44 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t ap_recv(struct socket_t *sock, char *buf, ap_ssize_t *len, 
time_t sec)
  +ap_status_t ap_recv(struct socket_t *sock, char *buf, ap_ssize_t *len)
   {
       ap_ssize_t rv;
  -    int recvlen = *len;
  -    
  +   
       do {
  -        rv = recv(sock->socketdes, buf, recvlen,0);
  +        rv = recv(sock->socketdes, buf, (*len), 0);
       } while (rv == -1 && errno == EINTR);
   
  -    if (rv == -1 && errno == EAGAIN && sec > 0) {
  -        struct timeval tv;
  +    if (rv == -1 && errno == EAGAIN && sock->timeout > 0) {
  +        struct timeval *tv;
           fd_set fdset;
           int srv;
   
           do {
               FD_ZERO(&fdset);
               FD_SET(sock->socketdes, &fdset);
  -            tv.tv_sec  = sec;
  -            tv.tv_usec = 0;
  -
  -            srv = select(FD_SETSIZE, &fdset, NULL, NULL, &tv);
  +            if (sock->timeout == -1)
  +                tv = NULL;
  +            else {
  +                tv = (struct timeval *)ap_palloc(sock->cntxt, sizeof(struct 
timeval));
  +                tv->tv_sec  = sock->timeout;
  +                tv->tv_usec = 0;
  +            }
  +            
  +            srv = select(FD_SETSIZE, &fdset, NULL, NULL, tv);
           } while (srv == -1 && errno == EINTR);
   
  +        if (srv == 0) {
  +            (*len) = -1;
  +            return APR_TIMEUP;
  +        }
           if (srv < 1) {
               (*len) = -1;
               return errno;
           }
           else {
               do {
  -                rv = recv(sock->socketdes, buf, recvlen,0);
  +                rv = recv(sock->socketdes, buf, (*len), 0);
               } while (rv == -1 && errno == EINTR);
           }
       }
  
  
  
  1.2       +83 -13    apache-2.0/src/lib/apr/network_io/beos/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/beos/sockets.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sockets.c 1999/08/17 15:59:43     1.1
  +++ sockets.c 1999/10/02 23:11:36     1.2
  @@ -60,6 +60,7 @@
   #include "networkio.h"
   #include "apr_network_io.h"
   #include "apr_general.h"
  +#include "apr_portable.h"
   
   ap_status_t socket_cleanup(void *sock)
   {
  @@ -90,36 +91,34 @@
       
       (*new)->socketdes = socket(AF_INET ,SOCK_STREAM, 0);
        (*new)->remote_hostname=NULL;
  -     
  -     (*new)->addr->sin_family = AF_INET;
  -    
  +     (*new)->addr->sin_family = AF_INET; 
       (*new)->addr_len = sizeof(*(*new)->addr);
        memset(&(*new)->addr->sin_zero, 0, sizeof((*new)->addr->sin_zero));
   
       if ((*new)->socketdes < 0) {
           return errno;
       }
  -    else {
  -        ap_register_cleanup((*new)->cntxt, (void *)(*new),
  +
  +    (*new)->timeout = -1;
  +    ap_register_cleanup((*new)->cntxt, (void *)(*new),
                               socket_cleanup, NULL);
  -        return APR_SUCCESS;
  -    }
  +    return APR_SUCCESS;
   } 
   
   ap_status_t ap_shutdown(struct socket_t *thesocket, ap_shutdown_how_e how)
   {
  -    /*if (shutdown(thesocket->socketdes, how) == 0) {*/
  +    if (shutdown(thesocket->socketdes, how) == 0) {
           return APR_SUCCESS;
  -    /*}
  +    }
       else {
  -        return APR_FAILURE;
  -    }*/
  +        return errno;
  +    }
   }
   
   ap_status_t ap_close_socket(struct socket_t *thesocket)
   {
  -     ap_kill_cleanup(thesocket->cntxt,thesocket,socket_cleanup);
  -     return socket_cleanup(thesocket);
  +    ap_kill_cleanup(thesocket->cntxt,thesocket,socket_cleanup);
  +    return socket_cleanup(thesocket);
   }
   
   ap_status_t ap_setport(struct socket_t *sock, ap_uint32_t port) 
  @@ -128,6 +127,31 @@
       return APR_SUCCESS; 
   } 
   
  +ap_status_t ap_getport(struct socket_t *sock, ap_uint32_t *port)
  +{
  +    *port = ntohs(sock->addr->sin_port);
  +    return APR_SUCCESS;
  +}
  +
  +ap_status_t ap_setipaddr(struct socket_t *sock, const char *addr)
  +{
  +    if (!strcmp(addr, APR_ANYADDR)) {
  +        sock->addr->sin_addr.s_addr = htonl(INADDR_ANY);
  +        return APR_SUCCESS;
  +    }
  +    if (inet_aton(addr, &sock->addr->sin_addr) == 0) {
  +        return errno;
  +    }
  +    return APR_SUCCESS;
  +}
  +
  +ap_status_t ap_getipaddr(struct socket_t *sock, char **addr)
  +{
  +    char *temp = inet_ntoa(sock->addr->sin_addr);
  +    *addr=temp;
  +    return APR_SUCCESS;
  +}
  +
   ap_status_t ap_bind(struct socket_t *sock) 
   { 
       sock->addr->sin_addr.s_addr = INADDR_ANY;
  @@ -200,3 +224,49 @@
       sock->remote_hostname = strdup(hostname);
       return APR_SUCCESS; 
   } 
  +
  +ap_status_t ap_get_socketdata(struct socket_t *socket, char *key, void *data)
  +{
  +    if (socket != NULL) {
  +        return ap_get_userdata(socket->cntxt, key, &data);
  +    }
  +    else {
  +        data = NULL;
  +        return APR_ENOSOCKET;
  +    }
  +}
  +
  +ap_status_t ap_set_socketdata(struct socket_t *socket, void *data, char *key,
  +                              ap_status_t (*cleanup) (void *))
  +{
  +    if (socket != NULL) {
  +        return ap_set_userdata(socket->cntxt, data, key, cleanup);
  +    }
  +    else {
  +        data = NULL;
  +        return APR_ENOSOCKET;
  +    }
  +}
  +
  +ap_status_t ap_get_os_sock(struct socket_t *sock, ap_os_sock_t *thesock)
  +{
  +    if (sock == NULL) {
  +        return APR_ENOSOCKET;
  +    }
  +    *thesock = sock->socketdes;
  +    return APR_SUCCESS;
  +}
  +
  +ap_status_t ap_put_os_sock(ap_context_t *cont, struct socket_t **sock,
  +                            ap_os_sock_t *thesock)
  +{
  +    if (cont == NULL) {
  +        return APR_ENOCONT;
  +    }
  +    if ((*sock) == NULL) {
  +        (*sock) = (struct socket_t *)ap_palloc(cont, sizeof(struct 
socket_t));
  +        (*sock)->cntxt = cont;
  +    }
  +    (*sock)->socketdes = *thesock;
  +    return APR_SUCCESS;
  +}
  
  
  
  1.2       +3 -0      apache-2.0/src/lib/apr/network_io/beos/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/beos/sockopt.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sockopt.c 1999/08/17 15:59:43     1.1
  +++ sockopt.c 1999/10/02 23:11:37     1.2
  @@ -70,6 +70,9 @@
       }else {
           one = 0;
        }
  +     if (opt & APR_SO_SNDBUF) 
  +         return APR_ENOTIMPL;
  +
       if (opt & APR_SO_DEBUG) {
           if (setsockopt(sock->socketdes, SOL_SOCKET, SO_DEBUG, &one, 
sizeof(one)) == -1) {
               return errno;
  
  
  
  1.1                  apache-2.0/src/lib/apr/network_io/beos/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 <socket.h>
  #include <stdlib.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);
  }
  
  
  

Reply via email to