rbb         99/04/23 08:19:36

  Added:       apr/network_io/beos Makefile networkio.h select.c sendrecv.c
                        sockets.c sockopt.c
  Log:
  First pass at BeOS socket apr code.
  Submitted by:  David Reid
  
  Revision  Changes    Path
  1.1                  apache-apr/apr/network_io/beos/Makefile
  
  Index: Makefile
  ===================================================================
  ##
  ##  Apache Makefile, automatically generated by Configure script.
  ##  Hand-edited changes will be lost if the Configure script is re-run.
  ##  Sources: - ../Makefile.config (via Configuration.apaci)
  ##           - ./Makefile.tmpl
  ##
  
  ##
  ##  Inherited Makefile options from Configure script
  ##  (Begin of automatically generated section)
  ##
  SRCDIR=..
  EXTRA_CFLAGS=-g 
  EXTRA_LDFLAGS=
  EXTRA_LIBS=
  EXTRA_INCLUDES=
  EXTRA_DEPS=
  OSDIR=
  INCDIR=../../../include
  INCLUDES0=-I. -I $(INCDIR)
  SHELL=/bin/sh
  CC=gcc
  CPP=gcc -E
  TARGET=
  OPTIM=
  CFLAGS_SHLIB=-fpic -DSHARED_MODULE
  LD_SHLIB=ld
  LDFLAGS_SHLIB=-Bshareable
  LDFLAGS_SHLIB_EXPORT=-rdynamic
  CFLAGS1= -DBEOS -DUSE_HSREGEX
  INCLUDES1=
  LIBS_SHLIB=
  LDFLAGS1=
  MFLAGS_STATIC=--no-print-directory
  REGLIB=regex/libregex.a
  RANLIB=ranlib
  LIBS1= #-lm -lcrypt -lndbm -ldl
  ##
  ##  (End of automatically generated section)
  ##
  
  
  CFLAGS=$(OPTIM) $(CFLAGS1) $(EXTRA_CFLAGS)
  LIBS=$(EXTRA_LIBS) $(LIBS1)
  INCLUDES=$(INCLUDES1) $(INCLUDES0) $(EXTRA_INCLUDES)
  LDFLAGS=$(LDFLAGS1) $(EXTRA_LDFLAGS)
  
  LIB=  libnetwork.a
  
  OBJS= sockets.o sockopt.o sendrecv.o select.o\
  
  .c.o:
        $(CC) -c $(INCLUDES) $(CFLAGS) $<
  
  all: $(HEADERS) $(LIB)
  
  $(LIB): $(OBJS)
        rm -f $@
        ar cr $@ $(OBJS)
        $(RANLIB) $@
        cp $@ ../
  clean:
        rm -f *.o $(LIB)
  
  distclean: clean
        -rm -f Makefile
  
  # We really don't expect end users to use this rule.  It works only with
  # gcc, and rebuilds Makefile.tmpl.  You have to re-run Configure after
  # using it.
  depend:
        cp Makefile.tmpl Makefile.tmpl.bak \
            && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \
            && gcc -MM $(INCLUDES) $(CFLAGS) *.c >> Makefile.new \
            && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' \
                   -e '1,$$s: $(OSDIR)/: $$(OSDIR)/:g' Makefile.new \
                > Makefile.tmpl \
            && rm Makefile.new
  
  #Dependencies
  
  $(OBJS): Makefile
  
  # DO NOT REMOVE
  sockets.o: sockets.c
  select.o: select.c
  sockopt.o: sockopt.c
  sendrecv.o: sendrecv.c
  
  
  1.1                  apache-apr/apr/network_io/beos/networkio.h
  
  Index: networkio.h
  ===================================================================
  /* ====================================================================
   * 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/>.
   *
   */
  
  #ifndef NETWORK_IO_H
  #define NETWORK_IO_H
  
  #include <socket.h>
  #include <netdb.h>
  
  /* This is for various routines that need to be removed. */
  #ifndef BEOS
  #define BEOS
  #endif
  
  struct socket_t {
      int socketdes;
      char *remote_hostname;
      struct sockaddr_in * addr;
      size_t addr_len;
  };
  
  typedef fd_set sd_set_t;
  
  #endif  /* ! NETWORK_IO_H */
  
  
  
  
  1.1                  apache-apr/apr/network_io/beos/select.c
  
  Index: select.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 <errno.h>
  #include <sys/time.h>
  #include <sys/types.h>
  #include <sys/socket.h>
  #include "apr_network_io.h"
  #include "apr_general.h"
  
  void apr_sd_set(apr_socket_t *sock, apr_sd_set_t *sd_set)
  {
      FD_SET(sock->socketdes, sd_set);
  }
  
  void apr_sd_clr(apr_socket_t *sock, apr_sd_set_t *sd_set)
  {
      FD_CLR(sock->socketdes, sd_set);
  }
  
  apr_status_t apr_sd_isset(apr_socket_t *sock, apr_sd_set_t *sd_set)
  {
      if (FD_ISSET(sock->socketdes, sd_set))
          return APR_SUCCESS;
      return APR_FAILURE;
  }
  
  void apr_sd_zero(apr_sd_set_t *sd_set)
  {
      FD_ZERO(sd_set);
  }
  
  apr_int32_t apr_select(apr_int32_t nsd, apr_sd_set_t *readset, apr_sd_set_t 
*writeset, apr_sd_set_t *exceptset, struct timeval *timeout)
  {
      return select(nsd, readset, NULL, NULL, timeout);
  } 
  
  
  
  1.1                  apache-apr/apr/network_io/beos/sendrecv.c
  
  Index: sendrecv.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1996-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 and was originally based
   * on public domain software written at the National Center for
   * Supercomputing Applications, University of Illinois, Urbana-Champaign.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  
  #include <sys/time.h>
  #include <socket.h>
  #include <netdb.h>
  #include "apr_errno.h"
  #include "apr_general.h"
  #include "apr_network_io.h"
  
  apr_ssize_t apr_send(apr_socket_t *sock, const char *buf, int len, time_t sec)
  {
      apr_ssize_t rv;
  
      do {
          rv = send(sock->socketdes, buf, len,0);
      } while (rv == -1 && errno == EINTR);
  
      if (rv == -1 && errno == EAGAIN && sec > 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);
          } while (srv == -1 && errno == EINTR);
  
          if (srv < 1) {
              return (apr_ssize_t) -1;
          }
          else {
              do {
                  rv = send(sock->socketdes, buf, len,0);
              } while (rv == -1 && errno == EINTR);
          }
      }
      return (apr_ssize_t) rv;
  }
  
  apr_ssize_t apr_recv(apr_socket_t *sock, char *buf, int len, time_t sec)
  {
      apr_ssize_t rv;
      do {
          rv = recv(sock->socketdes, buf, len,0);
      } while (rv == -1 && errno == EINTR);
  
      if (rv == -1 && errno == EAGAIN && sec > 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);
          } while (srv == -1 && errno == EINTR);
  
          if (srv < 1) {
              return (apr_ssize_t) -1;
          }
          else {
              do {
                  rv = recv(sock->socketdes, buf, len,0);
              } while (rv == -1 && errno == EINTR);
          }
      }
      return (apr_ssize_t) rv;
  }
  
  
  
  
  1.1                  apache-apr/apr/network_io/beos/sockets.c
  
  Index: sockets.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 <errno.h>
  #include <string.h>
  #include <socket.h>
  #include <netdb.h>
  #include "apr_network_io.h"
  #include "apr_general.h"
  #include <stdio.h>
  
  apr_socket_t *apr_create_tcp_socket(void)
  {
      apr_socket_t *thesocket = (apr_socket_t *)malloc(sizeof(apr_socket_t));
      
      thesocket->socketdes = socket(AF_INET ,SOCK_STREAM, 0);
        thesocket->remote_hostname=NULL;
        thesocket->addr = (struct sockaddr_in *) malloc(sizeof (struct 
sockaddr_in));
        thesocket->addr->sin_family = AF_INET;
      thesocket->addr_len = sizeof(*thesocket->addr);
        memset(&thesocket->addr->sin_zero, '0', 
sizeof(thesocket->addr->sin_zero));
  
      if (thesocket->socketdes < 0) {
                free (thesocket->addr);
                free (thesocket);
          return NULL;
      }
      else {
          return thesocket;
      }
  } 
  
  apr_status_t apr_shutdown(apr_socket_t *thesocket, apr_shutdown_how_e how)
  {
      if (shutdown(thesocket->socketdes, how) == 0) {
          return APR_SUCCESS;
      }
      else {
          return APR_FAILURE;
      }
  }
  
  apr_status_t apr_close_socket(apr_socket_t *thesocket)
  {
      if (closesocket(thesocket->socketdes) == 0) {
          free(thesocket->addr);
          free(thesocket->remote_hostname);
          free(thesocket);
          return APR_SUCCESS;
      }
      else {
          return APR_FAILURE;
      }
  }
  
  apr_status_t apr_setport(apr_socket_t *sock, apr_uint32_t port) 
  { 
      sock->addr->sin_port = htons((short)port); 
      return APR_SUCCESS; 
  } 
  
  apr_status_t apr_bind(apr_socket_t *sock) 
  { 
      sock->addr->sin_addr.s_addr = INADDR_ANY;
      if (bind(sock->socketdes, (struct sockaddr *)sock->addr, sock->addr_len) 
== -1) 
          return APR_FAILURE; 
      else 
          return APR_SUCCESS; 
  } 
   
  apr_status_t apr_listen(apr_socket_t *sock, apr_int32_t backlog) 
  { 
      if (listen(sock->socketdes, backlog) == -1) 
          return APR_FAILURE; 
      else 
          return APR_SUCCESS; 
  } 
  
  apr_socket_t *apr_accept(const apr_socket_t *sock) 
  { 
      apr_socket_t *new = (apr_socket_t *)malloc(sizeof(apr_socket_t)); 
        struct hostent *hptr;
        
         
      new->socketdes = accept(sock->socketdes, (struct sockaddr *)new->addr, 
(int*)new->addr_len); 
  
        hptr = gethostbyaddr((char*)&new->addr->sin_addr, sizeof(struct 
in_addr), AF_INET);
        if (hptr != NULL){
                new->remote_hostname = strdup(hptr->h_name);
        }
        free (hptr); 
      if (new->socketdes >= 0) 
          return new; 
        free (new);
      return NULL; 
  } 
   
  apr_status_t apr_connect(apr_socket_t *sock, char *hostname, unsigned short 
port) 
  { 
      struct hostent *hp; 
  
      hp = gethostbyname(hostname); 
      if ((sock->socketdes < 0) || (!hp) || (!sock->addr)) { 
          free(sock->addr); 
          free(sock); 
          return APR_FAILURE; 
      } 
  
        memcpy((char *)&sock->addr->sin_addr, hp->h_addr , hp->h_length);
      sock->addr->sin_port = htons((short)port); 
      sock->addr->sin_family = AF_INET; 
      memset(sock->addr->sin_zero, 0, sizeof(sock->addr->sin_zero));
      sock->addr_len = sizeof(sock->addr); 
      if ((connect(sock->socketdes, sock->addr, sock->addr_len) < 0) && 
          (errno != EINPROGRESS)) {
          free(sock->addr); 
          free(sock); 
          return APR_FAILURE; 
       } 
      else {
          sock->remote_hostname = strdup(hostname); 
          return APR_SUCCESS; 
      } 
  } 
     
  
  
  
  1.1                  apache-apr/apr/network_io/beos/sockopt.c
  
  Index: sockopt.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 <errno.h>
  #include <string.h>
  #include <sys/socket.h>
  //#include <netinet/tcp.h>
  //#include <netinet/in.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include "apr_network_io.h"
  #include "apr_general.h"
  #include <stdio.h>
  
  int soblock(int sd)
  {
      int fd_flags;
  
      fd_flags = fcntl(sd, F_GETFL, 0);
  #if defined(O_NONBLOCK)
      fd_flags &= ~O_NONBLOCK;
  #elif defined(O_NDELAY)
      fd_flags &= ~O_NDELAY;
  #elif defined(FNDELAY)
      fd_flags &= ~O_FNDELAY;
  #else
      /* XXXX: this breaks things, but an alternative isn't obvious...*/
      return -1;
  #endif
      return fcntl(sd, F_SETFL, fd_flags);
  }
  
  int sononblock(int sd)
  {
      int fd_flags;
  
      fd_flags = fcntl(sd, F_GETFL, 0);
  #if defined(O_NONBLOCK)
      fd_flags |= O_NONBLOCK;
  #elif defined(O_NDELAY)
      fd_flags |= O_NDELAY;
  #eli f defined(FNDELAY)
      fd_flags |= O_FNDELAY;
  #else
      /* XXXX: this breaks things, but an alternative isn't obvious...*/
      return -1;
  #endif
      return fcntl(sd, F_SETFL, fd_flags);
  }
  
  
  apr_status_t apr_setsocketopt(apr_socket_t *sock, apr_int32_t opt, 
apr_int32_t on)
  {
      int one;
        char *set;
      if (on){
          one = 1;
          memset (set,1,sizeof(set));
      }else
          one = 0;
  
      if (opt & APR_SO_DEBUG) {
          if (setsockopt(sock->socketdes, SOL_SOCKET, SO_DEBUG, (char *) one, 
sizeof(int)) == -1) {
              return APR_FAILURE;
          }
      }
      if (opt & APR_SO_REUSEADDR) {
          if (setsockopt(sock->socketdes, SOL_SOCKET, SO_REUSEADDR, (char *) 
one, sizeof(int)) == -1) {
              return APR_FAILURE;
          }
      }
      if (opt & APR_SO_NONBLOCK) {
         if (on) { 
              if (soblock(sock->socketdes) == -1) 
                  return APR_FAILURE; 
          } 
          else { 
              if (sononblock(sock->socketdes) == -1) 
                  return APR_FAILURE; 
          } 
      } 
      return APR_SUCCESS;
  }         
  
  apr_status_t apr_gethostname(char * buf, int len)
  {
        if (gethostname(buf, len) == -1){
                return APR_FAILURE;
        } else {
                return APR_SUCCESS;
        }
  }
  
  char *apr_get_remote_hostname(apr_socket_t *sock)
  {
        return sock->remote_hostname;
  }
  
  
  

Reply via email to