dgaudet     99/06/24 01:58:06

  Modified:    mpm/src/include ap_iol.h buff.h
               mpm/src/main Makefile.tmpl alloc.c buff.c
               mpm/src/modules/mpm/prefork prefork.c
               mpm/src/os/unix Makefile.tmpl
  Added:       mpm/src/main iol_file.c
               mpm/src/os/unix iol_socket.c iol_socket.h
  Removed:     mpm/src/main iol_unix.c
  Log:
  I think this is a better i/o layer interface.
  
  - move main/iol_unix.c to os/unix/iol_socket.c
  - create main/iol_file.c ... use APR methods eventually
  - remove iol_data from ap_iol, instead the ap_iol is just embedded into
    the private data of the i/o layer
  - remove ap_bpushfd(), replace with ap_bpush_iol()
  
  Revision  Changes    Path
  1.3       +6 -4      apache-2.0/mpm/src/include/ap_iol.h
  
  Index: ap_iol.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/include/ap_iol.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ap_iol.h  1999/06/19 20:40:16     1.2
  +++ ap_iol.h  1999/06/24 08:57:58     1.3
  @@ -107,8 +107,10 @@
       /* TODO: accept, connect, ... */
   };
   
  +/* it is expected that each io layer will extend this structure as they
  +    require; they must only ensure that the methods pointer remains in
  +    the indicated position. */
   struct ap_iol {
  -    void *iol_data;
       const ap_iol_methods *methods;
   };
   
  @@ -120,8 +122,8 @@
   #define iol_setopt(iol, a, b) ((iol)->methods->setopt((iol), (a), (b)))
   #define iol_getopt(iol, a, b) ((iol)->methods->getopt((iol), (a), (b)))
   
  -/* clean this up later as well */
  -
  -void unix_attach_fd(ap_iol *, int fd);
  +/* the file iol */
  +/* TODO: use APR instead of unix semantics for this */
  +ap_iol *ap_open_file(const char *name, int flags, int mask);
   
   #endif
  
  
  
  1.5       +3 -2      apache-2.0/mpm/src/include/buff.h
  
  Index: buff.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/include/buff.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- buff.h    1999/06/24 07:29:29     1.4
  +++ buff.h    1999/06/24 08:57:58     1.5
  @@ -145,7 +145,7 @@
   
       ap_pool *pool;
   
  -    ap_iol iol;
  +    ap_iol *iol;
   };
   
   /* Options to bset/getopt */
  @@ -155,7 +155,8 @@
   
   /* Stream creation and modification */
   API_EXPORT(BUFF *) ap_bcreate(pool *p, int flags);
  -API_EXPORT(void) ap_bpushfd(BUFF *fb, int fd);
  +
  +API_EXPORT(void) ap_bpush_iol(BUFF *fb, ap_iol *iol);
   
   /* XXX - unused right now - mvsk */
   API_EXPORT(BUFF *) ap_bopenf(pool *a, const char *name, int flg, int mode);
  
  
  
  1.6       +1 -1      apache-2.0/mpm/src/main/Makefile.tmpl
  
  Index: Makefile.tmpl
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/main/Makefile.tmpl,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Makefile.tmpl     1999/06/20 23:49:32     1.5
  +++ Makefile.tmpl     1999/06/24 08:58:00     1.6
  @@ -11,7 +11,7 @@
         http_config.o http_core.o http_log.o \
         http_main.o http_protocol.o http_request.o http_vhost.o \
         util.o util_date.o util_script.o util_uri.o util_md5.o \
  -      rfc1413.o http_connection.o iol_unix.o
  +      rfc1413.o http_connection.o iol_file.o
   
   .c.o:
        $(CC) -c $(INCLUDES) $(CFLAGS) $<
  
  
  
  1.5       +4 -0      apache-2.0/mpm/src/main/alloc.c
  
  Index: alloc.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/main/alloc.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- alloc.c   1999/06/22 22:26:10     1.4
  +++ alloc.c   1999/06/24 08:58:00     1.5
  @@ -2370,6 +2370,9 @@
                                enum kill_conditions kill_how,
                                BUFF **pipe_in, BUFF **pipe_out, BUFF 
**pipe_err)
   {
  +    return 0;
  +    /* TODO: need to abstract the spawning stuff in a more clean manner */
  +#if 0
   #ifdef WIN32
       SECURITY_ATTRIBUTES sa = {0};  
       HANDLE hPipeOutputRead  = NULL;
  @@ -2588,6 +2591,7 @@
   #endif
   
       return pid;
  +#endif
   }
   
   static void free_proc_chain(struct process_chain *procs)
  
  
  
  1.6       +13 -14    apache-2.0/mpm/src/main/buff.c
  
  Index: buff.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/main/buff.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- buff.c    1999/06/24 07:29:31     1.5
  +++ buff.c    1999/06/24 08:58:00     1.6
  @@ -177,17 +177,16 @@
   {
       BUFF *fb = v;
   
  -    iol_close(&fb->iol);
  +    iol_close(fb->iol);
   }
   
   /*
    * Push some I/O file descriptors onto the stream
    */
  -API_EXPORT(void) ap_bpushfd(BUFF *fb, APRFile fd)
  +API_EXPORT(void) ap_bpush_iol(BUFF *fb, ap_iol *iol)
   {
  -    ap_kill_cleanups_for_fd(fb->pool, fd);
  +    fb->iol = iol;
       ap_register_cleanup(fb->pool, fb, bcleanup, bcleanup);
  -    unix_attach_fd(&fb->iol, fd);
   }
   
   API_EXPORT(int) ap_bsetopt(BUFF *fb, int optname, const void *optval)
  @@ -203,7 +202,7 @@
            fb->flags |= B_NONBLOCK;
            /* XXX: should remove B_WR now... */
        }
  -     return iol_setopt(&fb->iol, AP_IOL_TIMEOUT, optval);
  +     return iol_setopt(fb->iol, AP_IOL_TIMEOUT, optval);
       }
       errno = EINVAL;
       return -1;
  @@ -222,7 +221,7 @@
        return 0;
   
       case BO_TIMEOUT:
  -     return iol_getopt(&fb->iol, AP_IOL_TIMEOUT, optval);
  +     return iol_getopt(fb->iol, AP_IOL_TIMEOUT, optval);
       }
       errno = EINVAL;
       return -1;
  @@ -313,7 +312,7 @@
   {
       int rv;
   
  -    rv = iol_read(&fb->iol, buf, nbyte);
  +    rv = iol_read(fb->iol, buf, nbyte);
       if (rv == 0) {
        fb->flags |= B_EOF;
       }
  @@ -533,7 +532,7 @@
   {
       int rv;
   
  -    rv = iol_writev(&fb->iol, vec, nvec);
  +    rv = iol_writev(fb->iol, vec, nvec);
       if (rv == -1) {
        fb->saved_errno = errno;
        if (errno != EAGAIN) {
  @@ -678,7 +677,7 @@
   {
       int rv;
   
  -    rv = iol_write(&fb->iol, buf, nbyte);
  +    rv = iol_write(fb->iol, buf, nbyte);
       if (rv == -1) {
        fb->saved_errno = errno;
        if (errno != EAGAIN) {
  @@ -803,7 +802,7 @@
       else
        rc1 = 0;
       ap_kill_cleanup(fb->pool, fb, bcleanup);
  -    rc2 = iol_close(&fb->iol);
  +    rc2 = iol_close(fb->iol);
   
       fb->inptr = fb->inbase;
       fb->incnt = 0;
  @@ -926,15 +925,15 @@
   
   API_EXPORT(BUFF *) ap_bopenf(pool *a, const char *name, int flg, int mode)
   {
  -    int fd;
  +    ap_iol *iol;
       BUFF *fb;
   
  -    fd = ap_popenf(a, name, flg, mode);
  -    if (!fd) {
  +    iol = ap_open_file(name, flg, mode);
  +    if (!iol) {
           return NULL;
       }
       fb = ap_bcreate(a, ((flg &(B_RD|B_RDWR)) ? B_RD : 0)
                     | ((flg & (B_WR|B_RDWR)) ? B_WR : 0));
  -    ap_bpushfd(fb, fd);
  +    ap_bpush_iol(fb, iol);
       return fb;
   }
  
  
  
  1.1                  apache-2.0/mpm/src/main/iol_file.c
  
  Index: iol_file.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 "httpd.h"
  #include "ap_iol.h"
  
  #include <sys/uio.h>
  
  typedef struct {
      ap_iol iol;
      int fd;
  } iol_file;
  
  #define method(syscall, args) \
      static int file_##syscall args \
      { \
        iol_file *iol = (iol_file *)viol; \
        int rv; \
        /* try writing, ignoring EINTR, the upper layer has to handle \
            partial read/writes anyhow, so we can return early */ \
        do { \
            rv = syscall(iol->fd, arg1, arg2); \
        } while (rv == -1 && errno == EINTR); \
        return rv; \
      }
  
  method(write, (ap_iol *viol, const char *arg1, int arg2))
  method(writev, (ap_iol *viol, const struct iovec *arg1, int arg2))
  method(read, (ap_iol *viol, char *arg1, int arg2))
  method(readv, (ap_iol *viol, struct iovec *arg1, int arg2))
  
  static int file_close(ap_iol *viol)
  {
      iol_file *iol = (iol_file *)viol;
      int rv;
      int saved_errno;
  
      rv = close(iol->fd);
      saved_errno = errno;
      free(iol);
      errno = saved_errno;
      return rv;
  }
  
  static int file_setopt(ap_iol *viol, ap_iol_option opt, const void *value)
  {
      errno = EINVAL;
      return -1;
  }
  
  static int file_getopt(ap_iol *viol, ap_iol_option opt, void *value)
  {
      errno = EINVAL;
      return -1;
  }
  
  static const ap_iol_methods file_methods = {
      file_close,
      file_write,
      file_writev,
      file_read,
      file_readv,
      file_setopt,
      file_getopt
  };
  
  ap_iol *ap_open_file(const char *name, int flags, int mask)
  {
      int rv;
      iol_file *iol;
  
      rv = open(name, flags, mask);
      if (rv < 0) {
        return NULL;
      }
      iol = malloc(sizeof(iol_file));
      iol->iol.methods = &file_methods;
      iol->fd = rv;
      return (ap_iol *)iol;
  }
  
  
  
  1.3       +20 -24    apache-2.0/mpm/src/modules/mpm/prefork/prefork.c
  
  Index: prefork.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/prefork/prefork.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- prefork.c 1999/06/24 07:29:32     1.2
  +++ prefork.c 1999/06/24 08:58:03     1.3
  @@ -97,6 +97,7 @@
   #include "scoreboard_prefork.h"
   #include "ap_mpm.h"
   #include "unixd.h"
  +#include "iol_socket.h"
   #ifdef USE_SHMGET_SCOREBOARD
   #include <sys/types.h>
   #include <sys/ipc.h>
  @@ -2395,6 +2396,7 @@
       listen_rec *lr;
       pool *ptrans;
       conn_rec *current_conn;
  +    ap_iol *iol;
   
       my_pid = getpid();
       csd = -1;
  @@ -2601,19 +2603,6 @@
         */
        signal(SIGUSR1, SIG_IGN);
   
  -     ap_note_cleanups_for_fd(ptrans, csd);
  -
  -     /* protect various fd_sets */
  -#ifdef CHECK_FD_SETSIZE
  -     if (csd >= FD_SETSIZE) {
  -         ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL,
  -             "[csd] filedescriptor (%u) larger than FD_SETSIZE (%u) "
  -             "found, you probably need to rebuild Apache with a "
  -             "larger FD_SETSIZE", csd, FD_SETSIZE);
  -         continue;
  -     }
  -#endif
  -
        /*
         * We now have a connection, so set it up with the appropriate
         * socket options, file descriptors, and read/write buffers.
  @@ -2622,27 +2611,34 @@
        clen = sizeof(sa_server);
        if (getsockname(csd, &sa_server, &clen) < 0) {
            ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, "getsockname");
  +         close(csd);
            continue;
        }
   
        sock_disable_nagle(csd);
   
  +     iol = unix_attach_socket(csd);
  +     if (iol == NULL) {
  +         if (errno == EBADF) {
  +             ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL,
  +                 "filedescriptor (%u) larger than FD_SETSIZE (%u) "
  +                 "found, you probably need to rebuild Apache with a "
  +                 "larger FD_SETSIZE", csd, FD_SETSIZE);
  +         }
  +         else {
  +             ap_log_error(APLOG_MARK, APLOG_WARNING, NULL,
  +                 "error attaching to socket");
  +         }
  +         close(csd);
  +         continue;
  +     }
  +
        (void) ap_update_child_status(my_child_num, SERVER_BUSY_READ,
                                   (request_rec *) NULL);
   
        conn_io = ap_bcreate(ptrans, B_RDWR);
  -
  -#ifdef B_SFIO
  -     (void) sfdisc(conn_io->sf_in, SF_POPDISC);
  -     sfdisc(conn_io->sf_in, bsfio_new(conn_io->pool, conn_io));
  -     sfsetbuf(conn_io->sf_in, NULL, 0);
  -
  -     (void) sfdisc(conn_io->sf_out, SF_POPDISC);
  -     sfdisc(conn_io->sf_out, bsfio_new(conn_io->pool, conn_io));
  -     sfsetbuf(conn_io->sf_out, NULL, 0);
  -#endif
   
  -     ap_bpushfd(conn_io, csd);
  +     ap_bpush_iol(conn_io, iol);
   
        current_conn = new_connection(ptrans, server_conf, conn_io,
                                          (struct sockaddr_in *) &sa_client,
  
  
  
  1.5       +1 -1      apache-2.0/mpm/src/os/unix/Makefile.tmpl
  
  Index: Makefile.tmpl
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/os/unix/Makefile.tmpl,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Makefile.tmpl     1999/06/20 23:14:35     1.4
  +++ Makefile.tmpl     1999/06/24 08:58:04     1.5
  @@ -3,7 +3,7 @@
   INCLUDES=$(INCLUDES1) $(INCLUDES0) $(EXTRA_INCLUDES)
   LDFLAGS=$(LDFLAGS1) $(EXTRA_LDFLAGS)
   
  -OBJS=        os.o os-inline.o unixd.o
  +OBJS=        os.o os-inline.o unixd.o iol_socket.o
   
   LIB= libos.a
   
  
  
  
  1.1                  apache-2.0/mpm/src/os/unix/iol_socket.c
  
  Index: iol_socket.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 "httpd.h"
  #include "ap_iol.h"
  
  #include <errno.h>
  #include <sys/types.h>
  #include <sys/uio.h>
  
  #define FD_NONBLOCKING_SET    (1)
  
  typedef struct {
      ap_iol iol;
      int fd;
      int flags;
      int timeout;
  } iol_socket;
  
  static int unix_setopt(ap_iol *viol, ap_iol_option opt, const void *value)
  {
      iol_socket *iol = (iol_socket *)viol;
  
      switch (opt) {
      case AP_IOL_TIMEOUT:
        iol->timeout = *(const int *)value;
        break;
      default:
        errno = EINVAL;
        return -1;
      }
      return 0;
  }
  
  static int unix_getopt(ap_iol *viol, ap_iol_option opt, void *value)
  {
      iol_socket *iol = (iol_socket *)viol;
  
      switch (opt) {
      case AP_IOL_TIMEOUT:
        *(int *)value = iol->timeout;
        break;
      default:
        errno = EINVAL;
        return -1;
      }
      return 0;
  }
  
  static int set_nonblock(int fd)
  {
      int fd_flags;
  
      fd_flags = fcntl(fd, F_GETFL, 0);
  #if defined(O_NONBLOCK)
      fd_flags |= O_NONBLOCK;
      return fcntl(fd, F_SETFL, fd_flags);
  #elif defined(O_NDELAY)
      fd_flags |= O_NDELAY;
      return fcntl(fd, F_SETFL, fd_flags);
  #elif defined(FNDELAY)
      fd_flags |= O_FNDELAY;
      return fcntl(fd, F_SETFL, fd_flags);
  #else
  #error "your unix lacks non-blocking i/o, you lose"
  #endif
  }
  
  /* the timeout code is a separate routine because it requires
      a stack frame... and we don't want to pay that setup cost
      on every call */
  
  /* this macro expands into the four basic i/o methods */
  
  #define method(name, args, syscall, selread, selwrite)        \
      static int unix_##name##_timeout args \
      { \
        iol_socket *iol = (iol_socket *)viol; \
        fd_set fdset; \
        struct timeval tv; \
        int rv; \
   \
        FD_ZERO(&fdset); \
        FD_SET(iol->fd, &fdset); \
        tv.tv_sec = iol->timeout; \
        tv.tv_usec = 0; \
        do { \
            rv = select(iol->fd + 1, selread, selwrite, NULL, iol->timeout < 0 
? NULL : &tv); \
        } while (rv == -1 && errno == EINTR); \
        if (!FD_ISSET(iol->fd, &fdset)) { \
            errno = ETIMEDOUT; \
            return -1; \
        } \
        do { \
            rv = syscall(iol->fd, arg1, arg2); \
        } while (rv == -1 && errno == EINTR); \
        return rv; \
      } \
   \
      static int unix_##name args \
      { \
        iol_socket *iol = (iol_socket *)viol; \
        int rv; \
   \
        if (!(iol->flags & FD_NONBLOCKING_SET)) { \
            if (iol->timeout < 0) { \
                return syscall(iol->fd, arg1, arg2); \
            } \
            /* must shift descriptor to blocking mode now */ \
            if (set_nonblock(iol->fd)) { \
                return -1; \
            } \
            iol->flags |= FD_NONBLOCKING_SET; \
        } \
   \
        /* try writing, ignoring EINTR, the upper layer has to handle \
            partial read/writes anyhow, so we can return early */ \
        do { \
            rv = syscall(iol->fd, arg1, arg2); \
        } while (rv == -1 && errno == EINTR); \
        if (rv >= 0) { \
            return rv; \
        } \
        if (errno == EWOULDBLOCK && iol->timeout != 0) { \
            return unix_##name##_timeout(viol, arg1, arg2); \
        } \
        return -1; \
      } \
  
  method(write, (ap_iol *viol, const char *arg1, int arg2), write, NULL, &fdset)
  method(writev, (ap_iol *viol, const struct iovec *arg1, int arg2), writev, 
NULL, &fdset)
  method(read, (ap_iol *viol, char *arg1, int arg2), read, &fdset, NULL)
  method(readv, (ap_iol *viol, struct iovec *arg1, int arg2), readv, &fdset, 
NULL)
  
  static int unix_close(ap_iol *viol)
  {
      iol_socket *iol = (iol_socket *)viol;
      int rv;
      int saved_errno;
  
      rv = close(iol->fd);
      saved_errno = errno;
      free(iol);
      errno = saved_errno;
      return rv;
  }
  
  static const ap_iol_methods socket_methods = {
      unix_close,
      unix_write,
      unix_writev,
      unix_read,
      unix_readv,
      unix_setopt,
      unix_getopt
  };
  
  ap_iol *unix_attach_socket(int fd)
  {
      iol_socket *iol;
  
      if (fd >= FD_SETSIZE) {
        errno = EBADF;
        return NULL;
      }
      iol = malloc(sizeof(iol_socket));
      iol->iol.methods = &socket_methods;
      iol->fd = fd;
      iol->timeout = -1;
      iol->flags = 0;
      return (ap_iol *)iol;
  }
  
  
  
  1.1                  apache-2.0/mpm/src/os/unix/iol_socket.h
  
  Index: iol_socket.h
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1998-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/>.
   *
   */
  
  #ifndef OS_UNIX_IOL_SOCKET_H
  #define OS_UNIX_IOL_SOCKET_H
  
  ap_iol *unix_attach_socket(int fd);
  
  #endif
  
  
  

Reply via email to