apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: apr/support/unix waitio.c
Date Mon, 24 Nov 2003 00:17:24 GMT
trawick     2003/11/23 16:17:24

  Modified:    .        configure.in
               file_io/unix filedup.c open.c pipe.c
               include/arch/unix apr_arch_file_io.h apr_arch_networkio.h
               network_io/unix sockets.c
               support/unix waitio.c
  Log:
  on Unix-ish platforms, apr_wait_for_io_or_timeout() can just use poll(2)
  
  it is a perfect match for the feature set needed and avoids the setup
  code at object creation time currently required to use apr_pollset_poll()
  instead of poll(2)
  
  future:
    select()-based function is trivial too
  
    is any platform then left needing the support in
    apr/(network_io|file_io)/unix for allocating a pollset any time we
    create a file or socket just in case apr_wait_for_io_or_timeout()
    will be called?
  
  Revision  Changes    Path
  1.557     +5 -0      apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /home/cvs/apr/configure.in,v
  retrieving revision 1.556
  retrieving revision 1.557
  diff -u -r1.556 -r1.557
  --- configure.in	17 Nov 2003 13:51:25 -0000	1.556
  +++ configure.in	24 Nov 2003 00:17:23 -0000	1.557
  @@ -1720,6 +1720,11 @@
   AC_SUBST(have_in_addr)
   AC_SUBST(file_as_socket)
   
  +if test "$ac_cv_func_poll $file_as_socket" = "yes 1"; then
  +    AC_DEFINE(WAITIO_USES_POLL, 1,
  +              [Define if apr_wait_for_io_or_timeout() uses poll(2)])
  +fi
  +
   # Check the types only if we have gethostbyname_r
   if test "$ac_cv_func_gethostbyname_r" = "yes"; then
       APR_CHECK_GETHOSTBYNAME_R_STYLE
  
  
  
  1.66      +4 -4      apr/file_io/unix/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/filedup.c,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- filedup.c	17 Nov 2003 11:31:01 -0000	1.65
  +++ filedup.c	24 Nov 2003 00:17:23 -0000	1.66
  @@ -130,11 +130,11 @@
       apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),
                                 apr_unix_file_cleanup, 
                                 apr_unix_file_cleanup);
  -
  +#ifndef WAITIO_USES_POLL
       /* Create a pollset with room for one descriptor. */
       /* ### check return codes */
       (void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0);
  -
  +#endif
       return APR_SUCCESS;
   }
   
  @@ -187,10 +187,10 @@
       old_file->filedes = -1;
       apr_pool_cleanup_kill(old_file->pool, (void *)old_file,
                             apr_unix_file_cleanup);
  -
  +#ifndef WAITIO_USES_POLL
       /* Create a pollset with room for one descriptor. */
       /* ### check return codes */
       (void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0);
  -
  +#endif
       return APR_SUCCESS;
   }
  
  
  
  1.113     +2 -2      apr/file_io/unix/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/open.c,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -r1.112 -r1.113
  --- open.c	17 Nov 2003 01:41:17 -0000	1.112
  +++ open.c	24 Nov 2003 00:17:23 -0000	1.113
  @@ -188,11 +188,11 @@
       (*new)->bufpos = 0;
       (*new)->dataRead = 0;
       (*new)->direction = 0;
  -
  +#ifndef WAITIO_USES_POLL
       /* Create a pollset with room for one descriptor. */
       /* ### check return codes */
       (void) apr_pollset_create(&(*new)->pollset, 1, pool, 0);
  -
  +#endif
       if (!(flag & APR_FILE_NOCLEANUP)) {
           apr_pool_cleanup_register((*new)->pool, (void *)(*new), 
                                     apr_unix_file_cleanup, 
  
  
  
  1.66      +6 -3      apr/file_io/unix/pipe.c
  
  Index: pipe.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/pipe.c,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- pipe.c	17 Nov 2003 01:41:17 -0000	1.65
  +++ pipe.c	24 Nov 2003 00:17:23 -0000	1.66
  @@ -198,10 +198,11 @@
                                     apr_unix_file_cleanup,
                                     apr_pool_cleanup_null);
       }
  -
  +#ifndef WAITIO_USES_POLL
       /* Create a pollset with room for one descriptor. */
       /* ### check return codes */
       (void) apr_pollset_create(&(*file)->pollset, 1, pool, 0);
  +#endif
       return APR_SUCCESS;
   }
   
  @@ -233,8 +234,9 @@
   #if APR_HAS_THREADS
       (*in)->thlock = NULL;
   #endif
  +#ifndef WAITIO_USES_POLL
       (void) apr_pollset_create(&(*in)->pollset, 1, pool, 0);
  -
  +#endif
       (*out) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
       (*out)->pool = pool;
       (*out)->filedes = filedes[1];
  @@ -247,8 +249,9 @@
   #if APR_HAS_THREADS
       (*out)->thlock = NULL;
   #endif
  +#ifndef WAITIO_USES_POLL
       (void) apr_pollset_create(&(*out)->pollset, 1, pool, 0);
  -
  +#endif
       apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup,
                            apr_pool_cleanup_null);
       apr_pool_cleanup_register((*out)->pool, (void *)(*out), apr_unix_file_cleanup,
  
  
  
  1.5       +4 -2      apr/include/arch/unix/apr_arch_file_io.h
  
  Index: apr_arch_file_io.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/unix/apr_arch_file_io.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- apr_arch_file_io.h	17 Nov 2003 01:41:17 -0000	1.4
  +++ apr_arch_file_io.h	24 Nov 2003 00:17:23 -0000	1.5
  @@ -64,7 +64,9 @@
   #include "apr_errno.h"
   #include "apr_lib.h"
   #include "apr_thread_mutex.h"
  +#ifndef WAITIO_USES_POLL
   #include "apr_poll.h"
  +#endif
   
   /* System headers the file I/O library needs */
   #if APR_HAVE_FCNTL_H
  @@ -131,10 +133,10 @@
       int buffered;
       enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking;
       int ungetchar;    /* Last char provided by an unget op. (-1 = no char)*/
  -
  +#ifndef WAITIO_USES_POLL
       /* if there is a timeout set, then this pollset is used */
       apr_pollset_t *pollset;
  -
  +#endif
       /* Stuff for buffered mode */
       char *buffer;
       int bufpos;               /* Read/Write position in buffer */
  
  
  
  1.7       +4 -1      apr/include/arch/unix/apr_arch_networkio.h
  
  Index: apr_arch_networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/unix/apr_arch_networkio.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- apr_arch_networkio.h	17 Nov 2003 01:41:17 -0000	1.6
  +++ apr_arch_networkio.h	24 Nov 2003 00:17:23 -0000	1.7
  @@ -61,7 +61,9 @@
   #include "apr_errno.h"
   #include "apr_general.h"
   #include "apr_lib.h"
  +#ifndef WAITIO_USES_POLL
   #include "apr_poll.h"
  +#endif
   
   /* System headers the network I/O library needs */
   #if APR_HAVE_SYS_TYPES_H
  @@ -153,9 +155,10 @@
       apr_int32_t options;
       apr_int32_t inherit;
       sock_userdata_t *userdata;
  -
  +#ifndef WAITIO_USES_POLL
       /* if there is a timeout set, then this pollset is used */
       apr_pollset_t *pollset;
  +#endif
   };
   
   const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size);
  
  
  
  1.116     +2 -1      apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sockets.c,v
  retrieving revision 1.115
  retrieving revision 1.116
  diff -u -r1.115 -r1.116
  --- sockets.c	20 Nov 2003 17:40:16 -0000	1.115
  +++ sockets.c	24 Nov 2003 00:17:24 -0000	1.116
  @@ -103,10 +103,11 @@
       (*new)->remote_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt,
                                                           sizeof(apr_sockaddr_t));
       (*new)->remote_addr->pool = p;
  -
  +#ifndef WAITIO_USES_POLL
       /* Create a pollset with room for one descriptor. */
       /* ### check return codes */
       (void) apr_pollset_create(&(*new)->pollset, 1, p, 0);
  +#endif
   }
   
   apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol)
  
  
  
  1.8       +36 -0     apr/support/unix/waitio.c
  
  Index: waitio.c
  ===================================================================
  RCS file: /home/cvs/apr/support/unix/waitio.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- waitio.c	17 Nov 2003 01:41:18 -0000	1.7
  +++ waitio.c	24 Nov 2003 00:17:24 -0000	1.8
  @@ -66,6 +66,41 @@
   
   #ifdef USE_WAIT_FOR_IO
   
  +#ifdef WAITIO_USES_POLL
  +
  +#ifdef HAVE_POLL_H
  +#include <poll.h>
  +#endif
  +#ifdef HAVE_SYS_POLL_H
  +#include <sys/poll.h>
  +#endif
  +
  +apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
  +                                        int for_read)
  +{
  +    struct pollfd pfd;
  +    int rc, timeout;
  +
  +    timeout    = f        ? f->timeout / 1000 : s->timeout / 1000;
  +    pfd.fd     = f        ? f->filedes        : s->socketdes;
  +    pfd.events = for_read ? POLLIN            : POLLOUT;
  +
  +    do {
  +        rc = poll(&pfd, 1, timeout);
  +    } while (rc == -1 && errno == EINTR);
  +    if (rc == 0) {
  +        return APR_TIMEUP;
  +    }
  +    else if (rc > 0) {
  +        return APR_SUCCESS;
  +    }
  +    else {
  +        return errno;
  +    }
  +}
  +
  +#else
  +
   apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
                                           int for_read)
   {
  @@ -114,5 +149,6 @@
   
       return status;
   }
  +#endif /* WAITIO_USES_POLL */
   
   #endif /* USE_WAIT_FOR_IO */
  
  
  

Mime
View raw message