You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by co...@apache.org on 2005/10/18 17:12:01 UTC
svn commit: r326118 - in /apr/apr/trunk: apr.dsp file_io/win32/buffer.c
file_io/win32/filedup.c file_io/win32/open.c file_io/win32/readwrite.c
include/arch/win32/apr_arch_file_io.h libapr.dsp
Author: colm
Date: Tue Oct 18 08:10:53 2005
New Revision: 326118
URL: http://svn.apache.org/viewcvs?rev=326118&view=rev
Log:
Initial win32 implementation of the variable file-io buffer size functions.
Added:
apr/apr/trunk/file_io/win32/buffer.c (with props)
Modified:
apr/apr/trunk/apr.dsp
apr/apr/trunk/file_io/win32/filedup.c
apr/apr/trunk/file_io/win32/open.c
apr/apr/trunk/file_io/win32/readwrite.c
apr/apr/trunk/include/arch/win32/apr_arch_file_io.h
apr/apr/trunk/libapr.dsp
Modified: apr/apr/trunk/apr.dsp
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/apr.dsp?rev=326118&r1=326117&r2=326118&view=diff
==============================================================================
--- apr/apr/trunk/apr.dsp (original)
+++ apr/apr/trunk/apr.dsp Tue Oct 18 08:10:53 2005
@@ -105,6 +105,10 @@
# PROP Default_Filter ""
# Begin Source File
+SOURCE=.\file_io\win32\buffer.c
+# End Source File
+# Begin Source File
+
SOURCE=.\file_io\unix\copy.c
# End Source File
# Begin Source File
Added: apr/apr/trunk/file_io/win32/buffer.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/win32/buffer.c?rev=326118&view=auto
==============================================================================
--- apr/apr/trunk/file_io/win32/buffer.c (added)
+++ apr/apr/trunk/file_io/win32/buffer.c Tue Oct 18 08:10:53 2005
@@ -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 "win32/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;
+}
\ No newline at end of file
Propchange: apr/apr/trunk/file_io/win32/buffer.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: apr/apr/trunk/file_io/win32/filedup.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/win32/filedup.c?rev=326118&r1=326117&r2=326118&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/filedup.c (original)
+++ apr/apr/trunk/file_io/win32/filedup.c Tue Oct 18 08:10:53 2005
@@ -145,7 +145,8 @@
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);
+ (*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);
}
Modified: apr/apr/trunk/file_io/win32/open.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/win32/open.c?rev=326118&r1=326117&r2=326118&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/open.c (original)
+++ apr/apr/trunk/file_io/win32/open.c Tue Oct 18 08:10:53 2005
@@ -386,7 +386,8 @@
}
if (flag & APR_BUFFERED) {
(*new)->buffered = 1;
- (*new)->buffer = apr_palloc(pool, APR_FILE_BUFSIZE);
+ (*new)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
+ (*new)->bufsize = APR_FILE_DEFAULT_BUFSIZE;
}
/* Need the mutex to handled buffered and O_APPEND style file i/o */
if ((*new)->buffered || (*new)->append) {
@@ -528,7 +529,8 @@
}
if (flags & APR_BUFFERED) {
(*file)->buffered = 1;
- (*file)->buffer = apr_palloc(pool, APR_FILE_BUFSIZE);
+ (*file)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
+ (*file)->bufsize = APR_FILE_DEFAULT_BUFSIZE;
}
if ((*file)->append || (*file)->buffered) {
Modified: apr/apr/trunk/file_io/win32/readwrite.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/win32/readwrite.c?rev=326118&r1=326117&r2=326118&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/readwrite.c (original)
+++ apr/apr/trunk/file_io/win32/readwrite.c Tue Oct 18 08:10:53 2005
@@ -177,7 +177,7 @@
if (thefile->bufpos >= thefile->dataRead) {
apr_size_t read;
rv = read_with_timeout(thefile, thefile->buffer,
- APR_FILE_BUFSIZE, &read);
+ thefile->bufsize, &read);
if (read == 0) {
if (rv == APR_EOF)
thefile->eof_hit = TRUE;
@@ -251,10 +251,11 @@
rv = 0;
while (rv == 0 && size > 0) {
- if (thefile->bufpos == APR_FILE_BUFSIZE) // write buffer is full
+ if (thefile->bufpos == thefile->bufsize) // write buffer is full
rv = 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;
Modified: apr/apr/trunk/include/arch/win32/apr_arch_file_io.h
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/include/arch/win32/apr_arch_file_io.h?rev=326118&r1=326117&r2=326118&view=diff
==============================================================================
--- apr/apr/trunk/include/arch/win32/apr_arch_file_io.h (original)
+++ apr/apr/trunk/include/arch/win32/apr_arch_file_io.h Tue Oct 18 08:10:53 2005
@@ -84,7 +84,9 @@
#define APR_FILE_MAX MAX_PATH
-#define APR_FILE_BUFSIZE 4096
+#define APR_FILE_DEFAULT_BUFSIZE 4096
+/* For backwards-compat */
+#define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE
/* obscure ommissions from msvc's sys/stat.h */
#ifdef _MSC_VER
@@ -173,6 +175,7 @@
/* Stuff for buffered mode */
char *buffer;
apr_size_t bufpos; // Read/Write position in buffer
+ apr_size_t bufsize; // The size of the buffer
apr_size_t dataRead; // amount of valid data read into buffer
int direction; // buffer being used for 0 = read, 1 = write
apr_off_t filePtr; // position in file of handle
Modified: apr/apr/trunk/libapr.dsp
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/libapr.dsp?rev=326118&r1=326117&r2=326118&view=diff
==============================================================================
--- apr/apr/trunk/libapr.dsp (original)
+++ apr/apr/trunk/libapr.dsp Tue Oct 18 08:10:53 2005
@@ -111,6 +111,10 @@
# PROP Default_Filter ""
# Begin Source File
+SOURCE=.\file_io\win32\buffer.c
+# End Source File
+# Begin Source File
+
SOURCE=.\file_io\unix\copy.c
# End Source File
# Begin Source File