apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: apr/file_io/win32 filedup.c
Date Tue, 02 Jul 2002 23:40:37 GMT
brianp      2002/07/02 16:40:37

  Modified:    include  apr_file_io.h apr_mmap.h
               file_io/unix filedup.c
               file_io/win32 filedup.c
  Log:
  Added apr_file_setaside() function to move an apr_file_t from
  one pool to another without a dup of the file descriptor.
  Also added apr_mmap_setaside() for consistency, per Cliff's suggestion
  
  Revision  Changes    Path
  1.129     +15 -0     apr/include/apr_file_io.h
  
  Index: apr_file_io.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_file_io.h,v
  retrieving revision 1.128
  retrieving revision 1.129
  diff -u -r1.128 -r1.129
  --- apr_file_io.h	29 Jun 2002 22:53:30 -0000	1.128
  +++ apr_file_io.h	2 Jul 2002 23:40:37 -0000	1.129
  @@ -458,6 +458,21 @@
                                           apr_pool_t *p);
   
   /**
  + * move the specified file descriptor to a new pool
  + * @param new_file Pointer in which to return the new apr_file_t
  + * @param old_file The file to move
  + * @param p        The pool to which the descriptor is to be moved
  + * @remark Unlike apr_file_dup2(), this function doesn't do an
  + *         OS dup() operation on the underlying descriptor; it just
  + *         moves the descriptor's apr_file_t wrapper to a new pool.
  + * @remark The new pool need not be an ancestor of old_file's pool.
  + * @remark After calling this function, old_file may not be used
  + */
  +APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
  +                                            apr_file_t *old_file,
  +                                            apr_pool_t *p);
  +
  +/**
    * Move the read/write file offset to a specified byte within a file.
    * @param thefile The file descriptor
    * @param where How to move the pointer, one of:
  
  
  
  1.32      +18 -2     apr/include/apr_mmap.h
  
  Index: apr_mmap.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_mmap.h,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- apr_mmap.h	13 Mar 2002 20:39:14 -0000	1.31
  +++ apr_mmap.h	2 Jul 2002 23:40:37 -0000	1.32
  @@ -163,8 +163,8 @@
   /**
    * Duplicate the specified MMAP.
    * @param new_mmap The structure to duplicate into. 
  - * @param old_mmap The file to duplicate.
  - * @param p The pool to use for the new file.
  + * @param old_mmap The mmap to duplicate.
  + * @param p The pool to use for new_mmap.
    * @param transfer_ownership  Whether responsibility for destroying
    *  the memory-mapped segment is transferred from old_mmap to new_mmap
    */         
  @@ -172,6 +172,22 @@
                                          apr_mmap_t *old_mmap,
                                          apr_pool_t *p,
                                          int transfer_ownership);
  +
  +#if defined(DOXYGEN)
  +/**
  + * Transfer the specified MMAP to a different pool
  + * @param new_mmap The structure to duplicate into. 
  + * @param old_mmap The file to transfer.
  + * @param p The pool to use for new_mmap.
  + * @remark After this call, old_mmap cannot be used
  + */
  +APR_DECLARE(apr_status_t) apr_mmap_setaside(apr_mmap_t **new_mmap,
  +                                            apr_mmap_t *old_mmap,
  +                                            apr_pool_t *p);
  +#else
  +#define apr_mmap_setaside(new_mmap, old_mmap, p) apr_mmap_dup(new_mmap, old_mmap, p, 1)
  +#endif /* DOXYGEN */
  +
   
   /**
    * Remove a mmap'ed.
  
  
  
  1.49      +35 -0     apr/file_io/unix/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/filedup.c,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- filedup.c	8 Jun 2002 22:32:11 -0000	1.48
  +++ filedup.c	2 Jul 2002 23:40:37 -0000	1.49
  @@ -148,3 +148,38 @@
   #endif
   }
   
  +APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
  +                                            apr_file_t *old_file,
  +                                            apr_pool_t *p)
  +{
  +    *new_file = (apr_file_t *)apr_palloc(p, sizeof(apr_file_t));
  +    memcpy(*new_file, old_file, sizeof(apr_file_t));
  +    (*new_file)->pool = p;
  +    if (old_file->buffered) {
  +        (*new_file)->buffer = apr_palloc(p, APR_FILE_BUFSIZE);
  +        if (old_file->direction == 1) {
  +            memcpy((*new_file)->buffer, old_file->buffer, old_file->bufpos);
  +        }
  +        else {
  +            memcpy((*new_file)->buffer, old_file->buffer, old_file->dataRead);
  +        }
  +        if (old_file->thlock) {
  +            apr_thread_mutex_create(&((*new_file)->thlock),
  +                                    APR_THREAD_MUTEX_DEFAULT, p);
  +            apr_thread_mutex_destroy(old_file->thlock);
  +        }
  +    }
  +    if (old_file->fname) {
  +        (*new_file)->fname = apr_pstrdup(p, old_file->fname);
  +    }
  +    if (!(old_file->flags & APR_FILE_NOCLEANUP)) {
  +        apr_pool_cleanup_register(p, (void *)(*new_file), 
  +                                  apr_unix_file_cleanup,
  +                                  apr_unix_file_cleanup);
  +    }
  +
  +    old_file->filedes = -1;
  +    apr_pool_cleanup_kill(old_file->pool, (void *)old_file,
  +                          apr_unix_file_cleanup);
  +    return APR_SUCCESS;
  +}
  
  
  
  1.46      +35 -0     apr/file_io/win32/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/filedup.c,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- filedup.c	20 Mar 2002 08:54:42 -0000	1.45
  +++ filedup.c	2 Jul 2002 23:40:37 -0000	1.46
  @@ -150,3 +150,38 @@
   #endif /* !defined(_WIN32_WCE) */
   }
   
  +APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
  +                                            apr_file_t *old_file,
  +                                            apr_pool_t *p)
  +{
  +    *new_file = (apr_file_t *)apr_palloc(p, sizeof(apr_file_t));
  +    memcpy(*new_file, old_file, sizeof(apr_file_t));
  +    (*new_file)->pool = p;
  +    if (old_file->buffered) {
  +        (*new_file)->buffer = apr_palloc(p, APR_FILE_BUFSIZE);
  +        if (old_file->direction == 1) {
  +            memcpy((*new_file)->buffer, old_file->buffer, old_file->bufpos);
  +        }
  +        else {
  +            memcpy((*new_file)->buffer, old_file->buffer, old_file->dataRead);
  +        }
  +        if (old_file->thlock) {
  +            apr_thread_mutex_create(&((*new_file)->thlock),
  +                                    APR_THREAD_MUTEX_DEFAULT, p);
  +            apr_thread_mutex_destroy(old_file->thlock);
  +        }
  +    }
  +    if (old_file->fname) {
  +        (*new_file)->fname = apr_pstrdup(p, old_file->fname);
  +    }
  +    if (!(old_file->flags & APR_FILE_NOCLEANUP)) {
  +        apr_pool_cleanup_register(p, (void *)(*new_file), 
  +                                  file_cleanup,
  +                                  file_cleanup);
  +    }
  +
  +    old_file->filedes = -1;
  +    apr_pool_cleanup_kill(old_file->pool, (void *)old_file,
  +                          file_cleanup);
  +    return APR_SUCCESS;
  +}
  
  
  

Mime
View raw message