apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r326120 - in /apr/apr/trunk: file_io/os2/buffer.c file_io/os2/filedup.c file_io/os2/open.c file_io/os2/readwrite.c include/arch/os2/apr_arch_file_io.h
Date Tue, 18 Oct 2005 15:16:47 GMT
Author: colm
Date: Tue Oct 18 08:16:37 2005
New Revision: 326120

URL: http://svn.apache.org/viewcvs?rev=326120&view=rev
Log:
Initial implementation of the variable file-io buffer sizes functions on the
OS2 platform; entirely guesswork base, untested. 

Added:
    apr/apr/trunk/file_io/os2/buffer.c   (with props)
Modified:
    apr/apr/trunk/file_io/os2/filedup.c
    apr/apr/trunk/file_io/os2/open.c
    apr/apr/trunk/file_io/os2/readwrite.c
    apr/apr/trunk/include/arch/os2/apr_arch_file_io.h

Added: apr/apr/trunk/file_io/os2/buffer.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/os2/buffer.c?rev=326120&view=auto
==============================================================================
--- apr/apr/trunk/file_io/os2/buffer.c (added)
+++ apr/apr/trunk/file_io/os2/buffer.c Tue Oct 18 08:16:37 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 "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;
+}

Propchange: apr/apr/trunk/file_io/os2/buffer.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: apr/apr/trunk/file_io/os2/filedup.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/os2/filedup.c?rev=326120&r1=326119&r2=326120&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/filedup.c (original)
+++ apr/apr/trunk/file_io/os2/filedup.c Tue Oct 18 08:16:37 2005
@@ -91,7 +91,8 @@
     (*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/os2/open.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/os2/open.c?rev=326120&r1=326119&r2=326120&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/open.c (original)
+++ apr/apr/trunk/file_io/os2/open.c Tue Oct 18 08:16:37 2005
@@ -59,7 +59,8 @@
     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 @@
     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)

Modified: apr/apr/trunk/file_io/os2/readwrite.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/os2/readwrite.c?rev=326120&r1=326119&r2=326120&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/readwrite.c (original)
+++ apr/apr/trunk/file_io/os2/readwrite.c Tue Oct 18 08:16:37 2005
@@ -52,7 +52,7 @@
             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 @@
         }
 
         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;

Modified: apr/apr/trunk/include/arch/os2/apr_arch_file_io.h
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/include/arch/os2/apr_arch_file_io.h?rev=326120&r1=326119&r2=326120&view=diff
==============================================================================
--- apr/apr/trunk/include/arch/os2/apr_arch_file_io.h (original)
+++ apr/apr/trunk/include/arch/os2/apr_arch_file_io.h Tue Oct 18 08:16:37 2005
@@ -31,7 +31,8 @@
  */
 #undef HAVE_MKSTEMP
 
-#define APR_FILE_BUFSIZE 4096
+#define APR_FILE_DEFAULT_BUFSIZE 4096
+#define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE
 
 struct apr_file_t {
     apr_pool_t *pool;
@@ -48,7 +49,8 @@
 
     /* Stuff for buffered mode */
     char *buffer;
-    int bufpos;               // Read/Write position in buffer
+    apr_size_t bufsize;       // Read/Write position in buffer
+    apr_size_t bufpos;        // Read/Write position in buffer
     unsigned long dataRead;   // amount of valid data read into buffer
     int direction;            // buffer being used for 0 = read, 1 = write
     unsigned long filePtr;    // position in file of handle



Mime
View raw message