diff options
author | Colm MacCarthaigh <colm@apache.org> | 2005-10-18 15:16:37 +0000 |
---|---|---|
committer | Colm MacCarthaigh <colm@apache.org> | 2005-10-18 15:16:37 +0000 |
commit | 149c903e5f897f9285428306668041311494f1a9 (patch) | |
tree | db886a11a1fd2a6b70f47b732c152d7d857fd311 /file_io | |
parent | 111bd75ce10e93aced2e64c939e3fac1ff7ba6ce (diff) | |
download | apr-149c903e5f897f9285428306668041311494f1a9.tar.gz |
Initial implementation of the variable file-io buffer sizes functions on the
OS2 platform; entirely guesswork base, untested.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@326120 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io')
-rw-r--r-- | file_io/os2/buffer.c | 59 | ||||
-rw-r--r-- | file_io/os2/filedup.c | 3 | ||||
-rw-r--r-- | file_io/os2/open.c | 6 | ||||
-rw-r--r-- | file_io/os2/readwrite.c | 6 |
4 files changed, 68 insertions, 6 deletions
diff --git a/file_io/os2/buffer.c b/file_io/os2/buffer.c new file mode 100644 index 000000000..2e56b9933 --- /dev/null +++ b/file_io/os2/buffer.c @@ -0,0 +1,59 @@ +/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_arch_file_io.h" +#include "apr_thread_mutex.h" + +APR_DECLARE(apr_status_t) apr_file_buffer_set(apr_file_t *file, + char * buffer, + apr_size_t bufsize) +{ + apr_status_t rv; + + apr_thread_mutex_lock(file->mutex); + + if(file->buffered) { + /* Flush the existing buffer */ + rv = apr_file_flush(file); + if (rv != APR_SUCCESS) { + apr_thread_mutex_unlock(file->mutex); + return rv; + } + } + + file->buffer = buffer; + file->bufsize = bufsize; + file->buffered = 1; + file->bufpos = 0; + file->direction = 0; + file->dataRead = 0; + + if (file->bufsize == 0) { + /* Setting the buffer size to zero is equivalent to turning + * buffering off. + */ + file->buffered = 0; + } + + apr_thread_mutex_unlock(file->mutex); + + return APR_SUCCESS; +} + +APR_DECLARE(apr_size_t) apr_file_buffer_size_get(apr_file_t *file) +{ + return file->bufsize; +} diff --git a/file_io/os2/filedup.c b/file_io/os2/filedup.c index d592033a0..859b45a6a 100644 --- a/file_io/os2/filedup.c +++ b/file_io/os2/filedup.c @@ -91,7 +91,8 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, (*new_file)->pool = p; if (old_file->buffered) { - (*new_file)->buffer = apr_palloc(p, APR_FILE_BUFSIZE); + (*new_file)->buffer = apr_palloc(p, old_file->bufsize); + (*new_file)->bufsize = old_file->bufsize; if (old_file->direction == 1) { memcpy((*new_file)->buffer, old_file->buffer, old_file->bufpos); diff --git a/file_io/os2/open.c b/file_io/os2/open.c index ef3bc06ec..4b1666bdc 100644 --- a/file_io/os2/open.c +++ b/file_io/os2/open.c @@ -59,7 +59,8 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr dafile->buffered = (flag & APR_BUFFERED) > 0; if (dafile->buffered) { - dafile->buffer = apr_palloc(pool, APR_FILE_BUFSIZE); + dafile->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); + dafile->bufsize = APR_FILE_DEFAULT_BUFSIZE; rv = apr_thread_mutex_create(&dafile->mutex, 0, pool); if (rv) @@ -193,7 +194,8 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thef if ((*file)->buffered) { apr_status_t rv; - (*file)->buffer = apr_palloc(pool, APR_FILE_BUFSIZE); + (*file)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); + (*file)->bufsize = APR_FILE_DEFAULT_BUFSIZE; rv = apr_thread_mutex_create(&(*file)->mutex, 0, pool); if (rv) diff --git a/file_io/os2/readwrite.c b/file_io/os2/readwrite.c index 81f50f978..b7b97931c 100644 --- a/file_io/os2/readwrite.c +++ b/file_io/os2/readwrite.c @@ -52,7 +52,7 @@ APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size if (thefile->bufpos >= thefile->dataRead) { ULONG bytesread; rc = DosRead(thefile->filedes, thefile->buffer, - APR_FILE_BUFSIZE, &bytesread); + thefile->bufsize, &bytesread); if (bytesread == 0) { if (rc == 0) @@ -143,10 +143,10 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a } while (rc == 0 && size > 0) { - if (thefile->bufpos == APR_FILE_BUFSIZE) // write buffer is full + if (thefile->bufpos == thefile->bufsize) // write buffer is full rc = apr_file_flush(thefile); - blocksize = size > APR_FILE_BUFSIZE - thefile->bufpos ? APR_FILE_BUFSIZE - thefile->bufpos : size; + blocksize = size > thefile->bufsize - thefile->bufpos ? thefile->bufsize - thefile->bufpos : size; memcpy(thefile->buffer + thefile->bufpos, pos, blocksize); thefile->bufpos += blocksize; pos += blocksize; |