httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgau...@hyperreal.org
Subject cvs commit: apache-2.0/mpm/src/include ap_buf.h
Date Sat, 19 Jun 1999 20:42:03 GMT
dgaudet     99/06/19 13:42:01

  Modified:    mpm/src/ap Makefile.tmpl
  Added:       mpm/src/ap ap_buf.c
               mpm/src/include ap_buf.h
  Log:
  this is where I'm going with the zero-copy stuff
  
  Revision  Changes    Path
  1.3       +1 -1      apache-2.0/mpm/src/ap/Makefile.tmpl
  
  Index: Makefile.tmpl
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/ap/Makefile.tmpl,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Makefile.tmpl	1999/06/18 19:07:57	1.2
  +++ Makefile.tmpl	1999/06/19 20:41:59	1.3
  @@ -6,7 +6,7 @@
   LIB=libap.a
   
   OBJS=ap_cpystrn.o ap_execve.o ap_fnmatch.o ap_getpass.o ap_md5c.o ap_signal.o \
  -     ap_slack.o ap_snprintf.o
  +     ap_slack.o ap_snprintf.o ap_buf.o
   
   .c.o:
   	$(CC) -c $(INCLUDES) $(CFLAGS) $<
  
  
  
  1.1                  apache-2.0/mpm/src/ap/ap_buf.c
  
  Index: ap_buf.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
   *    apache@apache.org.
   *
   * 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 "ap_config.h"
  #include <stdlib.h>
  #include <sys/uio.h>
  #include "ap_buf.h"
  
  API_EXPORT(ap_bufel *) ap_bufel_new(void)
  {
      /* TODO: keep a free list of ap_bufels... and allocate them in big chunks */
      return malloc(sizeof(ap_bufel));
  }
  
  API_EXPORT(void) ap_bufel_destroy(ap_bufel *e)
  {
      e->free(e);
      free(e);
  }
  
  API_EXPORT(void) ap_buf_init(ap_buf *b)
  {
      b->head = NULL;
      b->tail = &b->head;
  }
  
  API_EXPORT(void) ap_buf_append(ap_buf *b, ap_bufel *e)
  {
      e->next = *b->tail;
      b->tail = &e->next;
  }
  
  API_EXPORT(void) ap_buf_consume(ap_buf *b, int nbytes)
  {
      ap_bufel *e;
      ap_bufel *n;
      int amt;
  
      e = b->head;
      while (e && nbytes) {
  	amt = e->end - e->start;
  	if (nbytes < amt) {
  	    e->start += nbytes;
  	    break;
  	}
  	n = e->next;
  	ap_bufel_destroy(e);
  	nbytes -= amt;
  	e = n;
      }
      b->head = e;
      if (!e) {
  	b->tail = &b->head;
      }
  }
  
  API_EXPORT(int) ap_buf_to_iovec(ap_buf *b, struct iovec *vec, int nvec)
  {
      ap_bufel *e;
      struct iovec *orig;
  
      orig = vec;
      e = b->head;
      while (e && nvec) {
  	vec->iov_base = e->start;
  	vec->iov_len = e->end - e->start;
  	e = e->next;
  	--nvec;
  	++vec;
      }
      return vec - orig;
  }
  
  
  
  1.1                  apache-2.0/mpm/src/include/ap_buf.h
  
  Index: ap_buf.h
  ===================================================================
  /* ====================================================================
   * 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
   *    apache@apache.org.
   *
   * 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 AP_BUF_H
  #define AP_BUF_H
  
  #include <sys/uio.h>	/* for struct iovec */
  
  typedef struct ap_bufel ap_bufel;
  struct ap_bufel {
      ap_bufel *next;
      char *start;			/* first byte */
      char *end;				/* last byte + 1 */
      void (*free)(ap_bufel *e);		/* never NULL */
      void *data;				/* for use by free() */
  };
  
  typedef struct ap_buf ap_buf;
  struct ap_buf {
      ap_bufel *head;
      ap_bufel **tail;
  };
  
  /* allocate a bufel */
  API_EXPORT(ap_bufel *) ap_bufel_new(void);
  
  /* destroy a bufel */
  API_EXPORT(void) ap_bufel_destroy(ap_bufel *);
  
  /* initialize a buf */
  API_EXPORT(void) ap_buf_init(ap_buf *);
  
  /* append a bufel to buf */
  API_EXPORT(void) ap_buf_append(ap_buf *, ap_bufel *);
  
  /* consume nbytes from beginning of buf -- call ap_bufel_destroy as
      appropriate, and/or modify start on last element */
  API_EXPORT(void) ap_buf_consume(ap_buf *, int nbytes);
  
  /* create an iovec of the elements in buf... return number of elements used */
  API_EXPORT(int) ap_buf_to_iovec(ap_buf *, struct iovec *vec, int nvec);
  
  #endif
  
  
  

Mime
View raw message