httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@locus.apache.org
Subject cvs commit: apache-2.0/src/ap ap_buckets_pipe.c
Date Thu, 14 Sep 2000 02:27:17 GMT
fanf        00/09/13 19:27:15

  Modified:    src/include ap_buckets.h
               src/ap   ap_buckets_pipe.c
  Log:
  Fix the handling of EOF when reading from a pipe bucket (in this context
  I think we want to return APR_SUCCESS rather than APR_EOF, and we don't
  want to return early), and remove the pointless ap_bucket_pipe structure
  which also kills a little memory leak.
  Inspired by:	Jeff Trawick
  
  Revision  Changes    Path
  1.27      +0 -12     apache-2.0/src/include/ap_buckets.h
  
  Index: ap_buckets.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/include/ap_buckets.h,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -u -r1.26 -r1.27
  --- ap_buckets.h	2000/09/13 01:59:34	1.26
  +++ ap_buckets.h	2000/09/14 02:27:13	1.27
  @@ -348,18 +348,6 @@
       apr_mmap_t *mmap;
   };
   
  -/*  *****  Pipe buckets  *****  */
  -
  -
  -typedef struct ap_bucket_pipe ap_bucket_pipe;
  -
  -/**
  - * A bucket referring to a pipe.
  - */
  -struct ap_bucket_pipe {
  -    apr_file_t *thepipe;
  -};
  -
   /*  *****  Bucket Brigade Functions  *****  */
   
   /**
  
  
  
  1.10      +32 -31    apache-2.0/src/ap/ap_buckets_pipe.c
  
  Index: ap_buckets_pipe.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/ap/ap_buckets_pipe.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -u -r1.9 -r1.10
  --- ap_buckets_pipe.c	2000/09/09 06:48:07	1.9
  +++ ap_buckets_pipe.c	2000/09/14 02:27:14	1.10
  @@ -57,64 +57,65 @@
   #include "ap_buckets.h"
   #include <stdlib.h>
   
  -static apr_status_t pipe_split(ap_bucket *a, apr_off_t point)
  -{
  -    /* Splitting a pipe doesn't really make any sense, because as we read
  -     * it becomes a heap bucket.  I am leaving this in because I may be wrong,
  -     * but it just returns an error, and I expect it to go away immediately
  -     */
  -    return APR_ENOTIMPL;
  -}
  -
  -/* Ignore the block arg for now.  We can fix that tomorrow. */
  +/* XXX: We should obey the block flag */
   static apr_status_t pipe_read(ap_bucket *a, const char **str,
   			      apr_ssize_t *len, int block)
   {
  -    ap_bucket_pipe *d = a->data;
  +    apr_file_t *p = a->data;
       ap_bucket *b;
       char *buf;
       apr_status_t rv;
   
  -    /*
  -     * XXX: We need to obey the block flag
  -     */
  -    buf = malloc(IOBUFSIZE);
  +    buf = malloc(IOBUFSIZE); /* XXX: check for failure? */
       *str = buf;
       *len = IOBUFSIZE;
  -    if ((rv = apr_read(d->thepipe, buf, len)) != APR_SUCCESS) {
  +    rv = apr_read(p, buf, len);
  +    if (rv != APR_SUCCESS && rv != APR_EOF) {
   	free(buf);
           return rv;
       }
  +    /*
  +     * Change the current bucket to refer to what we read,
  +     * even if we read nothing because we hit EOF.
  +     */
  +    ap_bucket_make_heap(a, buf, *len, 0, NULL);  /* XXX: check for failure? */
  +    /*
  +     * If there's more to read we have to keep the rest of the pipe
  +     * for later. XXX: Note that more complicated bucket types that
  +     * refer to data not in memory and must therefore have a read()
  +     * function similar to this one should be wary of copying this
  +     * code because if they have a destroy function they probably
  +     * want to migrate the bucket's subordinate structure from the
  +     * old bucket to a raw new one and adjust it as appropriate,
  +     * rather than destroying the old one and creating a completely
  +     * new bucket.
  +     */
       if (*len > 0) {
  -        b = ap_bucket_create_pipe(d->thepipe);
  -        a = ap_bucket_make_heap(a, buf, *len, 0, NULL);
  +        b = ap_bucket_create_pipe(p);
   	AP_BUCKET_INSERT_AFTER(a, b);
       }
       return APR_SUCCESS;
   }
   
  -API_EXPORT(ap_bucket *) ap_bucket_make_pipe(ap_bucket *b, apr_file_t *thispipe)
  +API_EXPORT(ap_bucket *) ap_bucket_make_pipe(ap_bucket *b, apr_file_t *p)
   {
  -    ap_bucket_pipe *bd;
  -
  -    bd = malloc(sizeof(*bd));
  -    if (bd == NULL) {
  -	return NULL;
  -    }
  -    bd->thepipe = thispipe;
  -
  +    /*
  +     * XXX: We rely on a cleanup on some pool or other to actually
  +     * destroy the pipe. We should probably explicitly call apr to
  +     * destroy it instead.
  +     */
       b->type     = AP_BUCKET_PIPE;
       b->length   = -1;
       b->setaside = NULL;
  -    b->destroy  = free;
  +    b->destroy  = NULL;
       b->split    = NULL;
       b->read     = pipe_read;
  -    b->data     = bd;
  +    b->data     = p;
   
       return b;
   }
   
  -API_EXPORT(ap_bucket *) ap_bucket_create_pipe(apr_file_t *thispipe)
  +API_EXPORT(ap_bucket *) ap_bucket_create_pipe(apr_file_t *p)
   {
  -    ap_bucket_do_create(ap_bucket_make_pipe(b, thispipe));
  +    ap_bucket_do_create(ap_bucket_make_pipe(b, p));
   }
  
  
  

Mime
View raw message