You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by st...@locus.apache.org on 2000/06/22 06:42:52 UTC

cvs commit: apache-2.0/src/lib/apr/file_io/win32 open.c pipe.c readwrite.c

stoddard    00/06/21 21:42:52

  Modified:    src/lib/apr/file_io/win32 open.c pipe.c readwrite.c
  Log:
  Win32: Handle ap_ungetchar in the posix way (can only issue it once). Also,
  ap_ungetc will work on buffered of unbuffered i/o. Bring ap_open more in-line
  with the Uni implementation. Next todo: timeouts for ap_read()
  
  Revision  Changes    Path
  1.42      +31 -19    apache-2.0/src/lib/apr/file_io/win32/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/open.c,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- open.c	2000/06/15 17:39:17	1.41
  +++ open.c	2000/06/22 04:42:51	1.42
  @@ -74,7 +74,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t ap_open(ap_file_t **dafile, const char *fname, 
  +ap_status_t ap_open(ap_file_t **new, const char *fname, 
                       ap_int32_t flag, ap_fileperms_t perm, ap_pool_t *cont)
   {
       DWORD oflags = 0;
  @@ -84,9 +84,11 @@
       ap_oslevel_e level;
       ap_status_t rv;
   
  -    (*dafile) = (ap_file_t *)ap_pcalloc(cont, sizeof(ap_file_t));
  +    if ((*new) == NULL) {
  +        (*new) = (ap_file_t *)ap_pcalloc(cont, sizeof(ap_file_t));
  +    }
   
  -    (*dafile)->cntxt = cont;
  +    (*new)->cntxt = cont;
   
       if (flag & APR_READ) {
           oflags |= GENERIC_READ;
  @@ -95,24 +97,24 @@
           oflags |= GENERIC_WRITE;
       }
       if (!(flag & APR_READ) && !(flag & APR_WRITE)) {
  -        (*dafile)->filehand = INVALID_HANDLE_VALUE;
  +        (*new)->filehand = INVALID_HANDLE_VALUE;
           return APR_EACCES;
       }
   
  -    (*dafile)->buffered = (flag & APR_BUFFERED) > 0;
  +    (*new)->buffered = (flag & APR_BUFFERED) > 0;
   
  -    if ((*dafile)->buffered) {
  -        (*dafile)->buffer = ap_palloc(cont, APR_FILE_BUFSIZE);
  -        rv = ap_create_lock(&(*dafile)->mutex, APR_MUTEX, APR_INTRAPROCESS, NULL, cont);
  +    if ((*new)->buffered) {
  +        (*new)->buffer = ap_palloc(cont, APR_FILE_BUFSIZE);
  +        rv = ap_create_lock(&(*new)->mutex, APR_MUTEX, APR_INTRAPROCESS, NULL, cont);
   
           if (rv)
               return rv;
       }
   
  -    (*dafile)->fname = ap_pstrdup(cont, fname);
  +    (*new)->fname = ap_pstrdup(cont, fname);
   
  -    (*dafile)->demonfname = canonical_filename((*dafile)->cntxt, fname);
  -    (*dafile)->lowerdemonfname = strlwr((*dafile)->demonfname);
  +    (*new)->demonfname = canonical_filename((*new)->cntxt, fname);
  +    (*new)->lowerdemonfname = strlwr((*new)->demonfname);
    
       if (ap_get_oslevel(cont, &level) == APR_SUCCESS && level >= APR_WIN_NT) {
           sharemode |= FILE_SHARE_DELETE;
  @@ -138,15 +140,15 @@
       }
   
       if ((flag & APR_EXCL) && !(flag & APR_CREATE)) {
  -        (*dafile)->filehand = INVALID_HANDLE_VALUE;
  +        (*new)->filehand = INVALID_HANDLE_VALUE;
           return APR_EACCES;
       }   
   
       if (flag & APR_APPEND) {
  -        (*dafile)->append = 1;
  +        (*new)->append = 1;
       }
       else {
  -        (*dafile)->append = 0;
  +        (*new)->append = 0;
       }
   
       attributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN;
  @@ -154,18 +156,28 @@
           attributes |= FILE_FLAG_DELETE_ON_CLOSE;
       }
   
  -    (*dafile)->filehand = CreateFile(fname, oflags, sharemode,
  +    (*new)->filehand = CreateFile(fname, oflags, sharemode,
                                        NULL, createflags, attributes, 0);
   
  -    if ((*dafile)->filehand == INVALID_HANDLE_VALUE) {
  +    if ((*new)->filehand == INVALID_HANDLE_VALUE) {
           return GetLastError();
       }
       if (flag & APR_APPEND) {
  -        SetFilePointer((*dafile)->filehand, 0, NULL, FILE_END);
  +        SetFilePointer((*new)->filehand, 0, NULL, FILE_END);
       }
  +
  +    (*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;
   
  -    (*dafile)->eof_hit = 0;
  -    ap_register_cleanup((*dafile)->cntxt, (void *)(*dafile), file_cleanup,
  +    ap_register_cleanup((*new)->cntxt, (void *)(*new), file_cleanup,
                           ap_null_cleanup);
       return APR_SUCCESS;
   }
  
  
  
  1.22      +14 -2     apache-2.0/src/lib/apr/file_io/win32/pipe.c
  
  Index: pipe.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/pipe.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- pipe.c	2000/06/20 18:50:00	1.21
  +++ pipe.c	2000/06/22 04:42:51	1.22
  @@ -116,15 +116,27 @@
   
       (*in) = (ap_file_t *)ap_pcalloc(cont, sizeof(ap_file_t));
       (*in)->cntxt = cont;
  -    (*in)->pipe = 1;
       (*in)->fname = ap_pstrdup(cont, "PIPE");
  +    (*in)->pipe = 1;
       (*in)->timeout = -1;
  +    (*in)->ungetchar = -1;
  +    (*in)->eof_hit = 0;
  +    (*in)->filePtr = 0;
  +    (*in)->bufpos = 0;
  +    (*in)->dataRead = 0;
  +    (*in)->direction = 0;
   
       (*out) = (ap_file_t *)ap_pcalloc(cont, sizeof(ap_file_t));
       (*out)->cntxt = cont;
  -    (*out)->pipe = 1;
       (*out)->fname = ap_pstrdup(cont, "PIPE");
  +    (*out)->pipe = 1;
       (*out)->timeout = -1;
  +    (*out)->ungetchar = -1;
  +    (*out)->eof_hit = 0;
  +    (*out)->filePtr = 0;
  +    (*out)->bufpos = 0;
  +    (*out)->dataRead = 0;
  +    (*out)->direction = 0;
   
       if (!CreatePipe(&(*in)->filehand, &(*out)->filehand, &sa, 0)) {
           return GetLastError();
  
  
  
  1.42      +22 -20    apache-2.0/src/lib/apr/file_io/win32/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/readwrite.c,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- readwrite.c	2000/06/20 18:03:15	1.41
  +++ readwrite.c	2000/06/22 04:42:51	1.42
  @@ -60,18 +60,28 @@
   #include <malloc.h>
   #include "atime.h"
   
  -#define GetFilePointer(hfile) SetFilePointer(hfile,0,NULL, FILE_CURRENT)
  -
   ap_status_t ap_read(ap_file_t *thefile, void *buf, ap_ssize_t *nbytes)
   {
  -    DWORD bread;
  -    int rv;
  +    ap_ssize_t rv;
  +    DWORD bytes_read = 0;
   
       if (*nbytes <= 0) {
           *nbytes = 0;
           return APR_SUCCESS;
       }
   
  +    /* Handle the ungetchar if there is one */
  +    if (thefile->ungetchar != -1) {
  +        bytes_read = 1;
  +        *(char *)buf = (char)thefile->ungetchar;
  +        buf = (char *)buf + 1;
  +        (*nbytes)--;
  +        thefile->ungetchar = -1;
  +        if (*nbytes == 0) {
  +            *nbytes = bytes_read;
  +            return APR_SUCCESS;
  +        }
  +    }
       if (thefile->buffered) {
           char *pos = (char *)buf;
           ap_ssize_t blocksize;
  @@ -90,7 +100,6 @@
           while (rv == 0 && size > 0) {
               if (thefile->bufpos >= thefile->dataRead) {
                   rv = ReadFile(thefile->filehand, thefile->buffer, APR_FILE_BUFSIZE, &thefile->dataRead, NULL ) ? 0 : GetLastError();
  -
                   if (thefile->dataRead == 0) {
                       if (rv == 0) {
                           thefile->eof_hit = TRUE;
  @@ -115,10 +124,12 @@
               rv = 0;
           }
           ap_unlock(thefile->mutex);
  -    } else {
  -        if (ReadFile(thefile->filehand, buf, *nbytes, &bread, NULL)) {
  -            *nbytes = bread;
  -            if (bread) {
  +    } else {  
  +        /* Unbuffered i/o */
  +        DWORD dwBytesRead;
  +        if (ReadFile(thefile->filehand, buf, *nbytes, &dwBytesRead, NULL)) {
  +            *nbytes = bytes_read + dwBytesRead;
  +            if (*nbytes) {
                   return APR_SUCCESS;
               }
               else {
  @@ -223,17 +234,8 @@
   
   ap_status_t ap_ungetc(char ch, ap_file_t *thefile)
   {
  -    /* ungetc only makes sense when using buffered i/o */
  -    if (thefile->buffered) {
  -        ap_lock(thefile->mutex);        
  -        if (thefile->bufpos > 0){
  -            thefile->bufpos--;
  -        }
  -        ap_unlock(thefile->mutex);
  -        return APR_SUCCESS;
  -    }
  -
  -    return APR_ENOTIMPL;
  +    thefile->ungetchar = (unsigned char) ch;
  +    return APR_SUCCESS;
   }
   
   ap_status_t ap_getc(char *ch, ap_file_t *thefile)