httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@locus.apache.org
Subject cvs commit: apache-2.0/src/modules/dav/fs repos.c
Date Sat, 15 Jul 2000 02:07:21 GMT
gstein      00/07/14 19:07:21

  Modified:    src/lib/apr/include apr_file_io.h
               src/lib/apr/file_io/unix Makefile.in
               src/lib/sdbm sdbm.c
               src/modules/dav/fs repos.c
  Added:       src/lib/apr/file_io/unix fullrw.c
  Log:
  add ap_full_read() and ap_full_write(). they guarantee to read/write the
      full buffer unless an error occurs.
  use the new functions in SDBM and DAV. [and Subversion]
  Win32 and OS/2 can directly include/use file_io/unix/fullrw.c since it is
      written in terms of other APR functions.
  
  Revision  Changes    Path
  1.61      +53 -1     apache-2.0/src/lib/apr/include/apr_file_io.h
  
  Index: apr_file_io.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_file_io.h,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- apr_file_io.h	2000/07/08 11:15:48	1.60
  +++ apr_file_io.h	2000/07/15 02:07:19	1.61
  @@ -281,7 +281,7 @@
       arg 1) The file descriptor to write to.
       arg 2) The buffer which contains the data.
       arg 3) On entry, the number of bytes to write; on exit, the number
  -           of bytes write.
  +           of bytes written.
   
   B<NOTE>:  ap_write will write up to the specified number of bytes, but never
      more.  If the OS cannot write that many bytes, it will write as many as it
  @@ -322,6 +322,58 @@
    */
   ap_status_t ap_writev(ap_file_t *thefile, const struct iovec *vec, 
                         ap_size_t nvec, ap_ssize_t *nbytes);
  +
  +/*
  +
  +=head1 ap_status_t ap_full_read(ap_file_t *thefile, void *buf, ap_size_t nbytes, ap_size_t
*bytes_read)
  +
  +B<Read data from the specified file.>
  +
  +    arg 1) The file descriptor to read from.
  +    arg 2) The buffer to store the data to.
  +    arg 3) The number of bytes to read.
  +    arg 4) If non-NULL, this will contain the number of bytes read.
  +
  +B<NOTE>:  ap_read will read up to the specified number of bytes, but never
  +   more.  If there isn't enough data to fill that number of bytes, then the
  +   process/thread will block until it is available or EOF is reached.  If a
  +   char was put back into the stream via ungetc, it will be the first
  +   character returned. 
  +
  +   It is possible for both bytes to be read and an APR_EOF or other error
  +   to be returned.
  +   
  +   APR_EINTR is never returned.
  +
  +=cut
  + */
  +ap_status_t ap_full_read(ap_file_t *thefile, void *buf, ap_size_t nbytes,
  +                         ap_size_t *bytes_read);
  +
  +/*
  +
  +=head1 ap_status_t ap_full_write(ap_file_t *thefile, const void *buf, ap_size_t nbytes,
ap_size_t *bytes_written)
  +
  +B<Write data to the specified file.>
  +
  +    arg 1) The file descriptor to write to.
  +    arg 2) The buffer which contains the data.
  +    arg 3) The number of bytes to write.
  +    arg 4) If non-NULL, this will contain the number of bytes written.
  +
  +B<NOTE>:  ap_write will write up to the specified number of bytes, but never
  +   more.  If the OS cannot write that many bytes, the process/thread will
  +   block until they can be written. Exceptional error such as "out of space"
  +   or "pipe closed" will terminate with an error.
  +  
  +   It is possible for both bytes to be written and an error to be returned.
  +  
  +   APR_EINTR is never returned.
  +
  +=cut
  + */
  +ap_status_t ap_full_write(ap_file_t *thefile, const void *buf,
  +                          ap_size_t nbytes, ap_size_t *bytes_written);
   
   /*
   
  
  
  
  1.14      +4 -0      apache-2.0/src/lib/apr/file_io/unix/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/Makefile.in,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Makefile.in	2000/07/07 19:20:45	1.13
  +++ Makefile.in	2000/07/15 02:07:20	1.14
  @@ -18,6 +18,7 @@
   	fileacc.o \
   	filedup.o \
   	filestat.o \
  +	fullrw.o \
   	open.o \
   	pipe.o \
   	readwrite.o \
  @@ -82,6 +83,9 @@
    $(INCDIR)/apr_time.h $(INCDIR)/apr_lib.h \
    $(INCDIR)/apr_pools.h $(INCDIR)/apr_thread_proc.h \
    $(INCDIR)/apr_tables.h
  +fullrw.o: fullrw.c $(INCDIR)/apr_file_io.h \
  + $(INCDIR)/apr_general.h $(INCDIR)/apr.h \
  + $(INCDIR)/apr_errno.h $(INCDIR)/apr_time.h
   open.o: open.c fileio.h $(INCDIR)/apr.h \
    $(INCDIR)/apr_private.h $(INCDIR)/apr_general.h \
    $(INCDIR)/apr_errno.h $(INCDIR)/apr_file_io.h \
  
  
  
  1.1                  apache-2.0/src/lib/apr/file_io/unix/fullrw.c
  
  Index: fullrw.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  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. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" 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 name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``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 SOFTWARE FOUNDATION 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 Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "apr_file_io.h"
  
  
  ap_status_t ap_full_read(ap_file_t *thefile, void *buf, ap_size_t nbytes,
                           ap_size_t *bytes_read)
  {
      ap_status_t status;
      ap_size_t total_read = 0;
  
      do {
  	ap_ssize_t amt = (ap_ssize_t)nbytes;
  
  	status = ap_read(thefile, buf, &amt);
  	buf += amt;
          nbytes -= amt;
          total_read += amt;
      } while (status == APR_SUCCESS && nbytes > 0);
  
      if (bytes_read != NULL)
          *bytes_read = total_read;
  
      return status;
  }
  
  ap_status_t ap_full_write(ap_file_t *thefile, const void *buf,
                            ap_size_t nbytes, ap_size_t *bytes_written)
  {
      ap_status_t status;
      ap_size_t total_written = 0;
  
      do {
  	ap_ssize_t amt = (ap_ssize_t)nbytes;
  
  	status = ap_write(thefile, buf, &amt);
  	buf += amt;
          nbytes -= amt;
          total_written += amt;
      } while (status == APR_SUCCESS && nbytes > 0);
  
      if (bytes_written != NULL)
          *bytes_written = total_written;
  
      return status;
  }
  
  
  
  1.5       +6 -38     apache-2.0/src/lib/sdbm/sdbm.c
  
  Index: sdbm.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/sdbm/sdbm.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sdbm.c	2000/07/13 10:56:31	1.4
  +++ sdbm.c	2000/07/15 02:07:21	1.5
  @@ -78,9 +78,6 @@
   static ap_status_t getpage(SDBM *db, long);
   static sdbm_datum getnext(SDBM *db);
   static ap_status_t makroom(SDBM *, long, int);
  -static ap_status_t full_read(ap_file_t *f, void *buf, ap_size_t bufsize);
  -static ap_status_t full_write(ap_file_t *f, const void *buf, 
  -			      ap_size_t bufsize);
   
   /*
    * useful macros
  @@ -207,7 +204,7 @@
       ap_off_t off = OFF_PAG(pagno);
       
       if ((status = ap_seek(db->pagf, APR_SET, &off)) != APR_SUCCESS ||
  -	(status = full_write(db->pagf, buf, PBLKSIZ)) != APR_SUCCESS) {
  +	(status = ap_full_write(db->pagf, buf, PBLKSIZ, NULL)) != APR_SUCCESS) {
   	ioerr(db);
   	return status;
       }
  @@ -386,7 +383,7 @@
       ap_status_t status;
   
       if ((status = ap_seek(f, APR_SET, &off)) != APR_SUCCESS ||
  -	((status = full_read(f, buf, len)) != APR_SUCCESS)) {
  +	((status = ap_full_read(f, buf, len, NULL)) != APR_SUCCESS)) {
   	/* if EOF is reached, pretend we read all zero's */
   	if (status == APR_EOF) {
   	    memset(buf, 0, len);
  @@ -524,8 +521,10 @@
   
   	off = OFF_DIR(dirb);
   	if (((status = ap_seek(db->dirf, APR_SET, &off)) != APR_SUCCESS)
  -	    || (status = full_write(db->dirf, db->dirbuf, DBLKSIZ)) != APR_SUCCESS)
  +	    || (status = ap_full_write(db->dirf, db->dirbuf, DBLKSIZ,
  +                                       NULL)) != APR_SUCCESS) {
   	    return status;
  +        }
   
   	return APR_SUCCESS;
   }
  @@ -558,7 +557,7 @@
   
   		db->pagbno = db->blkptr;
   		/* ### EOF acceptable here too? */
  -		if (full_read(db->pagf, db->pagbuf, PBLKSIZ) != APR_SUCCESS)
  +		if (ap_full_read(db->pagf, db->pagbuf, PBLKSIZ, NULL) != APR_SUCCESS)
   			break;
   		if (!chkpage(db->pagbuf))
   			break;
  @@ -568,37 +567,6 @@
   	return sdbm_nullitem;
   }
   
  -
  -/* ### borrowed from mod_dav... put it in APR? */
  -static ap_status_t full_write(ap_file_t *f, const void *buf, ap_size_t bufsize)
  -{
  -    ap_status_t status;
  -    ap_ssize_t amt;
  -    
  -    do {
  -	amt = bufsize;
  -	status = ap_write(f, buf, &amt);
  -	bufsize -= amt;
  -	buf += amt;
  -    } while (status == APR_SUCCESS && bufsize > 0);
  -
  -    return status;
  -}
  -
  -static ap_status_t full_read(ap_file_t *f, void *buf, ap_size_t bufsize)
  -{
  -    ap_status_t status;
  -    ap_ssize_t amt;
  -   
  -    do {
  -	amt = bufsize;
  -	status = ap_read(f, buf, &amt);
  -	bufsize -= amt;
  -	buf += amt;
  -    } while (status == APR_SUCCESS && bufsize > 0);
  -
  -    return status;
  -}
   
   int sdbm_rdonly(SDBM *db)
   {
  
  
  
  1.15      +2 -18     apache-2.0/src/modules/dav/fs/repos.c
  
  Index: repos.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/dav/fs/repos.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- repos.c	2000/07/10 07:49:45	1.14
  +++ repos.c	2000/07/15 02:07:21	1.15
  @@ -254,22 +254,6 @@
              tms.tm_hour, tms.tm_min, tms.tm_sec);
   }
   
  -static ap_status_t dav_sync_write(ap_file_t *f, const char *buf,
  -                                  ap_size_t bufsize)
  -{
  -    ap_status_t status;
  -    ap_ssize_t amt;
  -    
  -    do {
  -	amt = bufsize;
  -	status = ap_write(f, buf, &amt);
  -	bufsize -= amt;
  -	buf += amt;
  -    } while (status == APR_SUCCESS && bufsize > 0);
  -
  -    return status;
  -}
  -
   static dav_error * dav_fs_copymove_file(
       int is_move,
       ap_pool_t * p,
  @@ -328,7 +312,7 @@
   	}
   
           /* write any bytes that were read (applies to APR_EOF, too) */
  -        if (dav_sync_write(outf, pbuf->buf, len) != APR_SUCCESS) {
  +        if (ap_full_write(outf, pbuf->buf, len, NULL) != APR_SUCCESS) {
               int save_errno = errno;
   
   	    ap_close(inf);
  @@ -825,7 +809,7 @@
   {
       ap_status_t status;
   
  -    status = dav_sync_write(stream->f, buf, bufsize);
  +    status = ap_full_write(stream->f, buf, bufsize, NULL);
       if (status == APR_ENOSPC) {
           return dav_new_error(stream->p, HTTP_INSUFFICIENT_STORAGE, 0,
                                "There is not enough storage to write to "
  
  
  

Mime
View raw message