apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject cvs commit: apr/network_io/unix sa_common.c
Date Tue, 31 Jul 2001 02:10:11 GMT
jerenkrantz    01/07/30 19:10:11

  Modified:    .        CHANGES acconfig.h configure.in
               build    apr_network.m4
               network_io/unix sa_common.c
  Log:
  Support the AIX, glibc2, and Solaris variants of gethostby{name|addr}_r.
  Use gethostbyaddr_r function when available.
  
  The AIX gurus will have to test this to make sure I got their prototype
  right.  This compiles on Solaris.
  
  Submitted by:	Sterling Hughes <sterling@designmultimedia.com>
                  (Modified by Justin)
  Reviewed by:	Justin Erenkrantz
  
  Revision  Changes    Path
  1.130     +4 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.129
  retrieving revision 1.130
  diff -u -r1.129 -r1.130
  --- CHANGES	2001/07/30 17:56:16	1.129
  +++ CHANGES	2001/07/31 02:10:10	1.130
  @@ -1,5 +1,9 @@
   Changes with APR b1  
   
  +  *) Support the AIX, glibc2, and Solaris variants of gethostby{name|addr}_r.
  +     Use gethostbyaddr_r function when available.
  +     [Sterling Hughes <sterling@designmultimedia.com>]
  +
     *) Add new socket option, APR_INCOMPLETE_READ, that should be
        set when you expect the first non-blocking read to fail with
        EAGAIN. Setting APR_INCOMPLETE_READ prior to calling apr_read
  
  
  
  1.49      +1 -0      apr/acconfig.h
  
  Index: acconfig.h
  ===================================================================
  RCS file: /home/cvs/apr/acconfig.h,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- acconfig.h	2001/07/25 18:00:51	1.48
  +++ acconfig.h	2001/07/31 02:10:10	1.49
  @@ -24,6 +24,7 @@
   
   #undef READDIR_IS_THREAD_SAFE
   #undef GETHOSTBYNAME_IS_THREAD_SAFE
  +#undef GETHOSTBYADDR_IS_THREAD_SAFE
   
   #undef NEED_RLIM_T
   #undef USEBCOPY
  
  
  
  1.350     +8 -1      apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /home/cvs/apr/configure.in,v
  retrieving revision 1.349
  retrieving revision 1.350
  diff -u -r1.349 -r1.350
  --- configure.in	2001/07/30 18:06:26	1.349
  +++ configure.in	2001/07/31 02:10:10	1.350
  @@ -338,11 +338,13 @@
   
   ac_cv_define_READDIR_IS_THREAD_SAFE=no
   ac_cv_define_GETHOSTBYNAME_IS_THREAD_SAFE=no
  +ac_cv_define_GETHOSTBYADDR_IS_THREAD_SAFE=no
   if test "$threads" = "1"; then
       echo "APR will use threads"
       AC_CHECK_LIB(c_r, readdir, AC_DEFINE(READDIR_IS_THREAD_SAFE))
       AC_CHECK_LIB(c_r, gethostbyname, AC_DEFINE(GETHOSTBYNAME_IS_THREAD_SAFE))
  -    AC_CHECK_FUNCS(gethostbyname_r)
  +    AC_CHECK_LIB(c_r, gethostbyaddr, AC_DEFINE(GETHOSTBYADDR_IS_THREAD_SAFE))
  +    AC_CHECK_FUNCS(gethostbyname_r gethostbyaddr_r)
   else
       echo "APR will be non-threaded"
   fi
  @@ -1195,6 +1197,11 @@
   APR_CHECK_SOCKADDR_SA_LEN
   
   APR_CHECK_GETHOSTBYNAME_NAS
  +
  +dnl Check the types only if we have gethostbyname_r
  +if test "$ac_cv_func_gethostbyname_r" = "yes"; then
  +    APR_CHECK_GETHOSTBYNAME_R_STYLE
  +fi
   
   APR_CHECK_TCP_NODELAY_INHERITED
   
  
  
  
  1.7       +63 -0     apr/build/apr_network.m4
  
  Index: apr_network.m4
  ===================================================================
  RCS file: /home/cvs/apr/build/apr_network.m4,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- apr_network.m4	2001/04/27 04:06:51	1.6
  +++ apr_network.m4	2001/07/31 02:10:11	1.7
  @@ -145,6 +145,69 @@
   fi
   ])
   
  +dnl
  +dnl Checks the definition of gethostbyname_r and gethostbyaddr_r
  +dnl which are different for glibc, solaris and assorted other operating
  +dnl systems
  +dnl
  +dnl Note that this test is executed too early to see if we have all of
  +dnl the headers.
  +AC_DEFUN(APR_CHECK_GETHOSTBYNAME_R_STYLE,[
  +
  +dnl Try and compile a glibc2 gethostbyname_r piece of code, and set the
  +dnl style of the routines to glibc2 on success
  +AC_CACHE_CHECK([style of gethostbyname_r routine], ac_cv_gethostbyname_r_style,
  +APR_TRY_COMPILE_NO_WARNING([
  +#ifdef HAVE_SYS_TYPES_H
  +#include <sys/types.h>
  +#endif
  +#ifdef HAVE_NETINET_IN_H
  +#include <netinet/in.h>
  +#endif
  +#ifdef HAVE_ARPA_INET_H
  +#include <arpa/inet.h>
  +#endif
  +#ifdef HAVE_NETDB_H
  +#include <netdb.h>
  +#endif
  +#ifdef HAVE_STDLIB_H
  +#include <stdlib.h>
  +#endif
  +],[
  +int tmp = gethostbyname_r((const char *) 0, (struct hostent *) 0, 
  +                          (char *) 0, 0, (struct hostent **) 0, &tmp);
  +], ac_cv_gethostbyname_r_style=glibc2, ac_cv_gethostbyname_r_style=none))
  +
  +if test "$ac_cv_gethostbyname_r_style" = "glibc2"; then
  +    AC_DEFINE(GETHOSTBYNAME_R_GLIBC2, 1, [Define if gethostbyname_r has the glibc style])
  +fi
  +
  +AC_CACHE_CHECK([3rd argument to the gethostbyname_r routines], ac_cv_gethostbyname_r_arg,
  +APR_TRY_COMPILE_NO_WARNING([
  +#ifdef HAVE_SYS_TYPES_H
  +#include <sys/types.h>
  +#endif
  +#ifdef HAVE_NETINET_IN_H
  +#include <netinet/in.h>
  +#endif
  +#ifdef HAVE_ARPA_INET_H
  +#include <arpa/inet.h>
  +#endif
  +#ifdef HAVE_NETDB_H
  +#include <netdb.h>
  +#endif
  +#ifdef HAVE_STDLIB_H
  +#include <stdlib.h>
  +#endif
  +],[
  +int tmp = gethostbyname_r((const char *) 0, (struct hostent *) 0, 
  +                          (struct hostent_data *) 0);],
  +ac_cv_gethostbyname_r_arg=hostent_data, ac_cv_gethostbyname_r_arg=char))
  +
  +if test "$ac_cv_gethostbyname_r_arg" = "hostent_data"; then
  +    AC_DEFINE(GETHOSTBYNAME_R_HOSTENT_DATA, 1, [Define if gethostbyname_r has the hostent_data
for the third argument])
  +fi
  +])
   
   dnl
   dnl see if TCP_NODELAY setting is inherited from listening sockets
  
  
  
  1.40      +55 -5     apr/network_io/unix/sa_common.c
  
  Index: sa_common.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sa_common.c,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- sa_common.c	2001/07/24 22:18:34	1.39
  +++ sa_common.c	2001/07/31 02:10:11	1.40
  @@ -394,7 +394,11 @@
           int curaddr;
   #if APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \
       defined(HAVE_GETHOSTBYNAME_R) && !defined(BEOS)
  +#ifdef GETHOSTBYNAME_R_HOSTENT_DATA
  +        struct hostent_data hd;
  +#else
           char tmp[GETHOSTBYNAME_BUFLEN];
  +#endif
           int hosterror;
           struct hostent hs;
   #endif
  @@ -415,8 +419,19 @@
   #endif
   #if APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \
       defined(HAVE_GETHOSTBYNAME_R) && !defined(BEOS)
  -        hp = gethostbyname_r(hostname, &hs, tmp, GETHOSTBYNAME_BUFLEN - 1, 
  +#if defined(GETHOSTBYNAME_R_HOSTENT_DATA)
  +        /* AIX, HP/UX, D/UX et alia */
  +        gethostbyname_r(hostname, &hs, &hd);
  +        hp = &hs;
  +#elif defined(GETHOSTBYNAME_R_GLIBC2)
  +        /* Linux glibc2+ */
  +        gethostbyname_r(hostname, &hs, tmp, GETHOSTBYNAME_BUFLEN - 1, 
  +                        &hp, &hosterror);
  +#else
  +        /* Solaris, Irix et alia */
  +        hp = gethostbyname_r(hostname, &hs, tmp, GETHOSTBYNAME_BUFLEN - 1,
                                &hosterror);
  +#endif
   #else
           hp = gethostbyname(hostname);
   #endif
  @@ -426,9 +441,13 @@
               apr_get_netos_error();
   #elif APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \
       defined(HAVE_GETHOSTBYNAME_R) && !defined(BEOS)
  +#ifdef GETHOSTBYNAME_R_HOSTENT_DATA
  +            return (h_errno + APR_OS_START_SYSERR);
  +#else
               /* If you see ERANGE, that means GETHOSBYNAME_BUFLEN needs to be
                * bumped. */
               return (hosterror + APR_OS_START_SYSERR);
  +#endif
   #else
               return (h_errno + APR_OS_START_SYSERR);
   #endif
  @@ -502,17 +521,48 @@
                                                    tmphostname);
       return APR_SUCCESS;
   #else
  -    struct hostent *hptr;
  +#if APR_HAS_THREADS && !defined(GETHOSTBYADDR_IS_THREAD_SAFE) && \
  +    defined(HAVE_GETHOSTBYADDR_R) && !defined(BEOS)
  +#ifdef GETHOSTBYNAME_R_HOSTENT_DATA
  +    struct hostent_data hd;
  +#else
  +    char tmp[GETHOSTBYNAME_BUFLEN];
  +#endif
  +    int hosterror;
  +    struct hostent hs, *hptr;
   
  +#if defined(GETHOSTBYNAME_R_HOSTENT_DATA)
  +    /* AIX, HP/UX, D/UX et alia */
  +    gethostbyaddr_r((char *)&sockaddr->sa.sin.sin_addr, 
  +                  sizeof(struct in_addr), AF_INET, &hs, &hd);
  +    hptr = &hs;
  +#elif defined(GETHOSTBYNAME_R_GLIBC2)
  +    /* Linux glibc2+ */
  +    gethostbyaddr_r((char *)&sockaddr->sa.sin.sin_addr, 
  +                    sizeof(struct in_addr), AF_INET,
  +                    &hs, tmp, GETHOSTBYNAME_BUFLEN - 1, &hptr, &hosterror);
  +#else
  +    /* Solaris, Irix et alia */
  +    hptr = gethostbyaddr_r((char *)&sockaddr->sa.sin.sin_addr, 
  +                           sizeof(struct in_addr), AF_INET,
  +                           &hs, tmp, GETHOSTBYNAME_BUFLEN, &hosterror);
  +#endif
  +#else
  +    struct hostent *hptr;
       hptr = gethostbyaddr((char *)&sockaddr->sa.sin.sin_addr, 
  -                         sizeof(struct in_addr), 
  -                         AF_INET);
  +                         sizeof(struct in_addr), AF_INET);
  +#endif
  +
       if (hptr) {
           *hostname = sockaddr->hostname = apr_pstrdup(sockaddr->pool, hptr->h_name);
           return APR_SUCCESS;
       }
       *hostname = NULL;
  -#if defined(WIN32)
  +#if APR_HAS_THREADS && !defined(GETHOSTBYADDR_IS_THREAD_SAFE) && \
  +    defined(HAVE_GETHOSTBYADDR_R) && !defined(BEOS) && \
  +    !defined(GETHOSTBYNAME_R_HOSTENT_DATA)
  +    return hosterror + APR_OS_START_SYSERR;
  +#elif defined(WIN32)
       return apr_get_netos_error();
   #elif defined(OS2)
       return h_errno;
  
  
  

Mime
View raw message