Return-Path: Delivered-To: apmail-apache-cvs-archive@apache.org Received: (qmail 94610 invoked by uid 500); 6 Apr 2000 23:25:10 -0000 Mailing-List: contact apache-cvs-help@apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list apache-cvs@apache.org Received: (qmail 94595 invoked by uid 500); 6 Apr 2000 23:25:08 -0000 Delivered-To: apmail-apache-2.0-cvs@apache.org Date: 6 Apr 2000 23:25:07 -0000 Message-ID: <20000406232507.94589.qmail@locus.apache.org> From: rbb@locus.apache.org To: apache-2.0-cvs@apache.org Subject: cvs commit: apache-2.0/src/lib/apr/mmap/unix mmap.c rbb 00/04/06 16:25:07 Modified: src/lib/apr/file_io/unix filedup.c fileio.h filestat.c open.c pipe.c readwrite.c seek.c src/lib/apr/include apr_file_io.h src/lib/apr/mmap/unix mmap.c Log: Remove all the buffered I/O code from APR. APR supports buffered I/O only on platforms that only support FILE *'s, not ints. Of course, this is only true on POSIX systems. Other systems can do what they want. Revision Changes Path 1.15 +3 -25 apache-2.0/src/lib/apr/file_io/unix/filedup.c Index: filedup.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/filedup.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- filedup.c 2000/04/03 19:44:30 1.14 +++ filedup.c 2000/04/06 23:25:05 1.15 @@ -80,35 +80,13 @@ } (*new_file)->cntxt = old_file->cntxt; - if (old_file->buffered) { - switch (old_file->oflags) { - case O_RDONLY: - buf_oflags = "r"; - break; - case O_WRONLY: - buf_oflags = "w"; - break; - case O_RDWR: - buf_oflags = "r+"; - break; - default: - return APR_BADARG; - } - (*new_file)->filehand = freopen(old_file->fname, buf_oflags, - old_file->filehand); - if ((*new_file)->filehand == NULL) - return errno; + if (have_file) { + dup2(old_file->filedes, (*new_file)->filedes); } else { - if (have_file) { - dup2(old_file->filedes, (*new_file)->filedes); - } - else { - (*new_file)->filedes = dup(old_file->filedes); - } + (*new_file)->filedes = dup(old_file->filedes); } (*new_file)->fname = ap_pstrdup(old_file->cntxt, old_file->fname); - (*new_file)->buffered = old_file->buffered; ap_register_cleanup((*new_file)->cntxt, (void *)(*new_file), file_cleanup, ap_null_cleanup); return APR_SUCCESS; 1.14 +0 -2 apache-2.0/src/lib/apr/file_io/unix/fileio.h Index: fileio.h =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/fileio.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- fileio.h 2000/04/06 21:38:04 1.13 +++ fileio.h 2000/04/06 23:25:05 1.14 @@ -103,10 +103,8 @@ struct ap_file_t { ap_context_t *cntxt; int filedes; - FILE *filehand; char * fname; int oflags; - int buffered; int eof_hit; int pipe; int timeout; 1.21 +1 -7 apache-2.0/src/lib/apr/file_io/unix/filestat.c Index: filestat.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/filestat.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- filestat.c 2000/04/06 16:11:33 1.20 +++ filestat.c 2000/04/06 23:25:05 1.21 @@ -94,13 +94,7 @@ if (finfo == NULL || thefile == NULL) return APR_EBADARG; - if (thefile->filehand == NULL) { - rv = fstat(thefile->filedes, &info); - } else { - rv = stat(thefile->fname, &info); - } - - if (rv == 0) { + if ((rv = fstat(thefile->filedes, &info)) == 0) { finfo->protection = info.st_mode; finfo->filetype = filetype_from_mode(info.st_mode); finfo->user = info.st_uid; 1.41 +11 -53 apache-2.0/src/lib/apr/file_io/unix/open.c Index: open.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/open.c,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- open.c 2000/04/06 21:38:05 1.40 +++ open.c 2000/04/06 23:25:05 1.41 @@ -60,16 +60,10 @@ ap_file_t *file = thefile; int rv; - if (file->buffered) { - rv = fclose(file->filehand); - } - else { - rv = close(file->filedes); - } + rv = close(file->filedes); if (rv == 0) { file->filedes = -1; - file->filehand = NULL; return APR_SUCCESS; } else { @@ -115,31 +109,20 @@ (*new)->cntxt = cont; (*new)->oflags = oflags; (*new)->filedes = -1; - (*new)->filehand = NULL; - (*new)->ungetchar = -1; if ((flag & APR_READ) && (flag & APR_WRITE)) { - buf_oflags = ap_pstrdup(cont, "r+"); oflags = O_RDWR; } else if (flag & APR_READ) { - buf_oflags = ap_pstrdup(cont, "r"); oflags = O_RDONLY; } else if (flag & APR_WRITE) { - buf_oflags = ap_pstrdup(cont, "w"); oflags = O_WRONLY; } else { return APR_EACCES; } - if (flag & APR_BUFFERED) { - (*new)->buffered = TRUE; - } - else { - (*new)->buffered = FALSE; - } (*new)->fname = ap_pstrdup(cont, fname); if (flag & APR_CREATE) { @@ -153,26 +136,20 @@ } if (flag & APR_APPEND) { - buf_oflags[0] = 'a'; oflags |= O_APPEND; } if (flag & APR_TRUNCATE) { oflags |= O_TRUNC; } - if ((*new)->buffered) { - (*new)->filehand = fopen(fname, buf_oflags); + if (perm == APR_OS_DEFAULT) { + (*new)->filedes = open(fname, oflags, 0777); } - else { - if (perm == APR_OS_DEFAULT) { - (*new)->filedes = open(fname, oflags, 0777); - } - else { - (*new)->filedes = open(fname, oflags, get_fileperms(perm)); - } - } + else { + (*new)->filedes = open(fname, oflags, get_fileperms(perm)); + } - if ((*new)->filedes < 0 && (*new)->filehand == NULL) { + if ((*new)->filedes < 0) { (*new)->filedes = -1; (*new)->eof_hit = 1; return errno; @@ -243,12 +220,7 @@ return APR_ENOFILE; } - if (file->buffered) { - *thefile = fileno(file->filehand); - } - else { - *thefile = file->filedes; - } + *thefile = file->filedes; return APR_SUCCESS; } @@ -274,11 +246,6 @@ (*file) = ap_pcalloc(cont, sizeof(ap_file_t)); (*file)->cntxt = cont; } - /* if we are putting in a new file descriptor, then we don't really - * have any of this information. - * We don't allow put'ing buffered files, so we can set that value. - */ - (*file)->buffered = 0; (*file)->eof_hit = 0; (*file)->timeout = -1; (*file)->filedes = *dafile; @@ -296,12 +263,6 @@ if (fptr == NULL) return APR_EBADARG; - if (fptr->buffered) { - if (feof(fptr->filehand) == 0) { - return APR_SUCCESS; - } - return APR_EOF; - } if (fptr->eof_hit == 1) { return APR_EOF; } @@ -316,13 +277,12 @@ */ ap_status_t ap_ferror(ap_file_t *fptr) { +/* Thist function should be removed ASAP. It is next on my list once + * I am sure nobody is using it. + */ if (fptr == NULL) return APR_EBADARG; - if (ferror(fptr->filehand)) { - return (-1); - } - return APR_SUCCESS; } @@ -344,8 +304,6 @@ (*thefile)->filedes = STDERR_FILENO; (*thefile)->cntxt = cont; (*thefile)->fname = NULL; - (*thefile)->filehand = NULL; - (*thefile)->buffered = 0; (*thefile)->eof_hit = 0; return APR_SUCCESS; 1.22 +0 -2 apache-2.0/src/lib/apr/file_io/unix/pipe.c Index: pipe.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/pipe.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- pipe.c 2000/04/06 16:11:33 1.21 +++ pipe.c 2000/04/06 23:25:05 1.22 @@ -118,7 +118,6 @@ (*in) = (ap_file_t *)ap_palloc(cont, sizeof(ap_file_t)); (*in)->cntxt = cont; (*in)->filedes = filedes[0]; - (*in)->buffered = 0; (*in)->pipe = 1; (*in)->fname = ap_pstrdup(cont, "PIPE"); (*in)->timeout = -1; @@ -126,7 +125,6 @@ (*out) = (ap_file_t *)ap_palloc(cont, sizeof(ap_file_t)); (*out)->cntxt = cont; (*out)->filedes = filedes[1]; - (*out)->buffered = 0; (*out)->pipe = 1; (*out)->fname = ap_pstrdup(cont, "PIPE"); (*out)->timeout = -1; 1.34 +48 -116 apache-2.0/src/lib/apr/file_io/unix/readwrite.c Index: readwrite.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/readwrite.c,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- readwrite.c 2000/04/06 21:38:05 1.33 +++ readwrite.c 2000/04/06 23:25:05 1.34 @@ -101,50 +101,39 @@ if(thefile == NULL || nbytes == NULL || (buf == NULL && *nbytes != 0)) return APR_EBADARG; - if (thefile->filedes < 0 && !thefile->buffered) { - *nbytes = 0; - return APR_EBADF; - } - if(*nbytes <= 0) { *nbytes = 0; return APR_SUCCESS; } - if (thefile->buffered) { - rv = fread(buf, 1, *nbytes, thefile->filehand); + if (thefile->ungetchar != -1) { + used_unget = TRUE; + *(char *)buf++ = (char)thefile->ungetchar; + (*nbytes)--; + thefile->ungetchar == -1; } - else { - if(thefile->ungetchar != -1){ - used_unget = TRUE; - *(char *)buf++ = (char)thefile->ungetchar; - (*nbytes)--; - thefile->ungetchar == -1; - } - do { - rv = read(thefile->filedes, buf, *nbytes); - } while (rv == -1 && errno == EINTR); - - if (rv == -1 && errno == EAGAIN && thefile->timeout != 0) { - ap_status_t arv = wait_for_io_or_timeout(thefile, 1); - if (arv != APR_SUCCESS) { - *nbytes = 0; - return arv; - } - else { - do { - rv = read(thefile->filedes, buf, *nbytes); - } while (rv == -1 && errno == EINTR); - } - } - } /* buffered? */ - + do { + rv = read(thefile->filedes, buf, *nbytes); + } while (rv == -1 && errno == EINTR); + + if (rv == -1 && errno == EAGAIN && thefile->timeout != 0) { + ap_status_t arv = wait_for_io_or_timeout(thefile, 1); + if (arv != APR_SUCCESS) { + *nbytes = 0; + return arv; + } + else { + do { + rv = read(thefile->filedes, buf, *nbytes); + } while (rv == -1 && errno == EINTR); + } + } /* getting less data than requested does not signify an EOF when dealing with a pipe. */ if ((*nbytes != rv) && ((errno == EPIPE && thefile->pipe == 1) - || (errno != EINTR && !thefile->buffered && thefile->pipe == 0 ))) { + || (errno != EINTR && thefile->pipe == 0 ))) { thefile->eof_hit = 1; } if (rv == -1) { @@ -152,9 +141,9 @@ return errno; } *nbytes = rv; - if(used_unget){ - thefile->ungetchar = -1; - *nbytes += 1; + if (used_unget) { + thefile->ungetchar = -1; + *nbytes += 1; } return APR_SUCCESS; } @@ -176,33 +165,23 @@ if(thefile == NULL || nbytes == NULL || (buf == NULL && *nbytes != 0)) return APR_EBADARG; - - if (thefile->filedes < 0 && !thefile->buffered) { - *nbytes = 0; - return APR_EBADF; - } - if (thefile->buffered) { - rv = fwrite(buf, *nbytes, 1, thefile->filehand); - } - else { - do { - rv = write(thefile->filedes, buf, *nbytes); - } while (rv == -1 && errno == EINTR); - - if (rv == -1 && errno == EAGAIN && thefile->timeout != 0) { - ap_status_t arv = wait_for_io_or_timeout(thefile, 0); - if (arv != APR_SUCCESS) { - *nbytes = 0; - return arv; - } - else { - do { - rv = write(thefile->filedes, buf, *nbytes); - } while (rv == -1 && errno == EINTR); - } - } - } /* BUFFERED ?? */ + do { + rv = write(thefile->filedes, buf, *nbytes); + } while (rv == -1 && errno == EINTR); + + if (rv == -1 && errno == EAGAIN && thefile->timeout != 0) { + ap_status_t arv = wait_for_io_or_timeout(thefile, 0); + if (arv != APR_SUCCESS) { + *nbytes = 0; + return arv; + } + else { + do { + rv = write(thefile->filedes, buf, *nbytes); + } while (rv == -1 && errno == EINTR); + } + } if (rv == -1) { (*nbytes) = 0; @@ -254,12 +233,6 @@ if(thefile == NULL) return APR_EBADARG; - if (thefile->buffered) { - if (fputc(ch, thefile->filehand) == ch) { - return APR_SUCCESS; - } - return errno; - } if (write(thefile->filedes, &ch, 1) != 1) { return errno; } @@ -277,14 +250,7 @@ if(thefile == NULL) return APR_EBADARG; - if (thefile->buffered) { - if (ungetc(ch, thefile->filehand) == ch) { - return APR_SUCCESS; - } - return errno; - } else { - thefile->ungetchar = (unsigned char)ch; - } + thefile->ungetchar = (unsigned char)ch; return APR_SUCCESS; } @@ -301,22 +267,7 @@ if(thefile == NULL || ch == NULL) return APR_EBADARG; - if (thefile->buffered) { - int r; - - r=fgetc(thefile->filehand); - if(r != EOF) - { - *ch=(char)r; - return APR_SUCCESS; - } - if (feof(thefile->filehand)) { - return APR_EOF; - } - return errno; - } - - if(thefile->ungetchar != -1){ + if (thefile->ungetchar != -1) { *ch = (char) thefile->ungetchar; thefile->ungetchar = -1; return APR_SUCCESS; @@ -346,12 +297,6 @@ if(thefile == NULL || str == NULL) return APR_EBADARG; - if (thefile->buffered) { - if (fputs(str, thefile->filehand)) { - return APR_SUCCESS; - } - return errno; - } len = strlen(str); rv = write(thefile->filedes, str, len); if (rv != len) { @@ -367,15 +312,12 @@ */ ap_status_t ap_flush(ap_file_t *thefile) { +/* Another function to get rid of once we finish removing buffered I/O + * and we are sure nobody is using it. + */ if(thefile == NULL) return APR_EBADARG; - if (thefile->buffered) { - if (!fflush(thefile->filehand)) { - return APR_SUCCESS; - } - return errno; - } /* There isn't anything to do if we aren't buffering the output * so just return success. */ @@ -400,16 +342,6 @@ if(len <= 1) /* as per fgets() */ return APR_SUCCESS; - if (thefile->buffered) { - if (fgets(str, len, thefile->filehand)) { - return APR_SUCCESS; - } - if (feof(thefile->filehand)) { - return APR_EOF; - } - return errno; - } - if(thefile->ungetchar != -1){ str[0] = thefile->ungetchar; used_unget = TRUE; @@ -436,8 +368,8 @@ if (str[i] == '\n' || str[i] == '\r') break; } - if(i < len-1) - str[i+1] = '\0'; + if (i < len-1) + str[i+1] = '\0'; return APR_SUCCESS; } 1.9 +1 -6 apache-2.0/src/lib/apr/file_io/unix/seek.c Index: seek.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/seek.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- seek.c 2000/04/03 19:44:31 1.8 +++ seek.c 2000/04/06 23:25:05 1.9 @@ -70,12 +70,7 @@ ap_status_t ap_seek(ap_file_t *thefile, ap_seek_where_t where, ap_off_t *offset) { ap_off_t rv; - if (thefile->buffered) { - rv = fseek(thefile->filehand, *offset, where); - } - else { - rv = lseek(thefile->filedes, *offset, where); - } + rv = lseek(thefile->filedes, *offset, where); if (rv == -1) { *offset = -1; return errno; 1.39 +1 -2 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.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- apr_file_io.h 2000/04/03 18:37:05 1.38 +++ apr_file_io.h 2000/04/06 23:25:06 1.39 @@ -76,8 +76,7 @@ #define APR_APPEND 8 /* Append to the end of the file */ #define APR_TRUNCATE 16 /* Open the file and truncate to 0 length */ #define APR_BINARY 32 /* Open the file in binary mode */ -#define APR_BUFFERED 64 /* Buffer the data when reading or writing */ -#define APR_EXCL 128 /* Open should fail if APR_CREATE and file +#define APR_EXCL 64 /* Open should fail if APR_CREATE and file exists. */ #define APR_DELONCLOSE 256 /* Delete the file after close */ 1.15 +1 -1 apache-2.0/src/lib/apr/mmap/unix/mmap.c Index: mmap.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/mmap/unix/mmap.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- mmap.c 2000/04/03 19:45:01 1.14 +++ mmap.c 2000/04/06 23:25:07 1.15 @@ -90,7 +90,7 @@ { caddr_t mm; - if (file == NULL || file->buffered || file->filedes == -1) + if (file == NULL || file->filedes == -1) return APR_EBADF; (*new) = (ap_mmap_t *)ap_palloc(cont, sizeof(ap_mmap_t));