apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@apache.org
Subject cvs commit: apr/file_io/win32 filedup.c open.c readwrite.c
Date Tue, 29 Oct 2002 01:28:33 GMT
stoddard    2002/10/28 17:28:32

  Modified:    .        CHANGES
               file_io/win32 filedup.c open.c readwrite.c
  Log:
  Win32: Get APR_APPEND file i/o working correctly.
  
  Revision  Changes    Path
  1.351     +1 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.350
  retrieving revision 1.351
  diff -u -r1.350 -r1.351
  --- CHANGES	25 Oct 2002 17:15:36 -0000	1.350
  +++ CHANGES	29 Oct 2002 01:28:32 -0000	1.351
  @@ -1,4 +1,5 @@
   Changes with APR 0.9.2
  +  *) Win32: Fix APR_APPEND file i/o. [Bill Stoddard]
   
     *) Fix a problem retrieving the remote socket address for sockets
        created via apr_os_sock_put() or apr_os_sock_make().  [Jeff Trawick]
  
  
  
  1.50      +5 -5      apr/file_io/win32/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/filedup.c,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- filedup.c	4 Jul 2002 00:06:23 -0000	1.49
  +++ filedup.c	29 Oct 2002 01:28:32 -0000	1.50
  @@ -165,11 +165,11 @@
           else {
               memcpy((*new_file)->buffer, old_file->buffer, old_file->dataRead);
           }
  -        if (old_file->mutex) {
  -            apr_thread_mutex_create(&((*new_file)->mutex),
  -                                    APR_THREAD_MUTEX_DEFAULT, p);
  -            apr_thread_mutex_destroy(old_file->mutex);
  -        }
  +    }
  +    if (old_file->mutex) {
  +        apr_thread_mutex_create(&((*new_file)->mutex),
  +                                APR_THREAD_MUTEX_DEFAULT, p);
  +        apr_thread_mutex_destroy(old_file->mutex);
       }
       if (old_file->fname) {
           (*new_file)->fname = apr_pstrdup(p, old_file->fname);
  
  
  
  1.111     +17 -30    apr/file_io/win32/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/open.c,v
  retrieving revision 1.110
  retrieving revision 1.111
  diff -u -r1.110 -r1.111
  --- open.c	14 Oct 2002 20:05:58 -0000	1.110
  +++ open.c	29 Oct 2002 01:28:32 -0000	1.111
  @@ -380,21 +380,21 @@
       (*new)->filehand = handle;
       (*new)->fname = apr_pstrdup(pool, fname);
       (*new)->flags = flag;
  +    (*new)->timeout = -1;
  +    (*new)->ungetchar = -1;
   
       if (flag & APR_APPEND) {
           (*new)->append = 1;
           SetFilePointer((*new)->filehand, 0, NULL, FILE_END);
       }
  -    else {
  -        (*new)->append = 0;
  -    }
  -
       if (flag & APR_BUFFERED) {
           (*new)->buffered = 1;
           (*new)->buffer = apr_palloc(pool, APR_FILE_BUFSIZE);
  -        rv = apr_thread_mutex_create(&(*new)->mutex, APR_THREAD_MUTEX_DEFAULT,
  -                                     pool);
  -
  +    }
  +    /* Need the mutex to handled buffered and O_APPEND style file i/o */
  +    if ((*new)->buffered || (*new)->append) {
  +        rv = apr_thread_mutex_create(&(*new)->mutex, 
  +                                     APR_THREAD_MUTEX_DEFAULT, pool);
           if (rv) {
               if (file_cleanup(*new) == APR_SUCCESS) {
                   apr_pool_cleanup_kill(pool, *new, file_cleanup);
  @@ -402,22 +402,6 @@
               return rv;
           }
       }
  -    else {
  -        (*new)->buffered = 0;
  -        (*new)->buffer = NULL;
  -        (*new)->mutex = NULL;
  -    }
  -
  -    (*new)->pipe = 0;
  -    (*new)->timeout = -1;
  -    (*new)->ungetchar = -1;
  -    (*new)->eof_hit = 0;
  -
  -    /* Buffered mode fields not initialized above */
  -    (*new)->bufpos = 0;
  -    (*new)->dataRead = 0;
  -    (*new)->direction = 0;
  -    (*new)->filePtr = 0;
   
       if (!(flag & APR_FILE_NOCLEANUP)) {
           apr_pool_cleanup_register((*new)->pool, (void *)(*new), file_cleanup,
  @@ -432,8 +416,9 @@
       if ((stat = file_cleanup(file)) == APR_SUCCESS) {
           apr_pool_cleanup_kill(file->pool, file, file_cleanup);
   
  -        if (file->buffered)
  +        if (file->mutex) {
               apr_thread_mutex_destroy(file->mutex);
  +        }
   
           return APR_SUCCESS;
       }
  @@ -536,17 +521,19 @@
       (*file)->ungetchar = -1; /* no char avail */
       (*file)->timeout = -1;
       (*file)->flags = flags;
  -    if (flags & APR_APPEND)
  -        (*file)->append = 1;
   
  +    if (flags & APR_APPEND) {
  +        (*file)->append = 1;
  +    }
       if (flags & APR_BUFFERED) {
  -        apr_status_t rv;
  -
           (*file)->buffered = 1;
           (*file)->buffer = apr_palloc(pool, APR_FILE_BUFSIZE);
  -        rv = apr_thread_mutex_create(&(*file)->mutex, APR_THREAD_MUTEX_DEFAULT,
  -                                     pool);
  +    }
   
  +    if ((*file)->append || (*file)->buffered) {
  +        apr_status_t rv;
  +        rv = apr_thread_mutex_create(&(*file)->mutex, 
  +                                     APR_THREAD_MUTEX_DEFAULT, pool);
           if (rv) {
               if (file_cleanup(*file) == APR_SUCCESS) {
                   apr_pool_cleanup_kill(pool, *file, file_cleanup);
  
  
  
  1.70      +34 -7     apr/file_io/win32/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/readwrite.c,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- readwrite.c	15 Jul 2002 07:24:34 -0000	1.69
  +++ readwrite.c	29 Oct 2002 01:28:32 -0000	1.70
  @@ -303,15 +303,42 @@
           apr_thread_mutex_unlock(thefile->mutex);
           return rv;
       } else {
  -        if (thefile->pOverlapped && !thefile->pipe) {
  -            thefile->pOverlapped->Offset     = (DWORD)thefile->filePtr;
  -            thefile->pOverlapped->OffsetHigh = (DWORD)(thefile->filePtr >>
32);
  +        if (!thefile->pipe) {
  +            apr_off_t offset = 0;
  +            apr_status_t rc;
  +            if (thefile->pOverlapped) {
  +                thefile->pOverlapped->Offset     = (DWORD)thefile->filePtr;
  +                thefile->pOverlapped->OffsetHigh = (DWORD)(thefile->filePtr >>
32);
  +            }
  +            if (thefile->append) {
  +                apr_thread_mutex_lock(thefile->mutex);
  +                if (!thefile->pOverlapped) {
  +                    rc = apr_file_lock(thefile, APR_FLOCK_EXCLUSIVE);
  +                    if (rc != APR_SUCCESS) {
  +                        apr_thread_mutex_unlock(thefile->mutex);
  +                        return rc;
  +                    }
  +                }
  +                rc = apr_file_seek(thefile, APR_END, &offset);
  +                if (rc != APR_SUCCESS) {
  +                    apr_thread_mutex_unlock(thefile->mutex);
  +                    return rc;
  +                }
  +            }
  +            rv = WriteFile(thefile->filehand, buf, *nbytes, &bwrote,
  +                           thefile->pOverlapped);
  +            if (thefile->append) {
  +                if (!thefile->pOverlapped) {
  +                    apr_file_unlock(thefile);
  +                }
  +                apr_thread_mutex_unlock(thefile->mutex);
  +            }
           }
  -        else if (!thefile->pipe && thefile->append) {
  -            SetFilePointer(thefile->filehand, 0, NULL, FILE_END);
  +        else {
  +            rv = WriteFile(thefile->filehand, buf, *nbytes, &bwrote,
  +                           thefile->pOverlapped);
           }
  -        if (WriteFile(thefile->filehand, buf, *nbytes, &bwrote, 
  -                      thefile->pOverlapped)) {
  +        if (rv) {
               *nbytes = bwrote;
               rv = APR_SUCCESS;
           }
  
  
  

Mime
View raw message