2003-06-30 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Mon, 30 Jun 2003 12:34:26 +0000 (12:34 -0000)
committerZoltan Varga <vargaz@gmail.com>
Mon, 30 Jun 2003 12:34:26 +0000 (12:34 -0000)
* FileStream.cs (Dispose): Flush the buffer even if we don't own the
handle.
* FileStream.cs: Add a new constructor parameter to turn off buffering.
This is used by the Console.OpenStandard...() methods. Also fix
argument checking in InitBuffer(), so a zero buffer size is also
rejected.

svn path=/trunk/mcs/; revision=15743

mcs/class/corlib/System.IO/ChangeLog
mcs/class/corlib/System.IO/FileStream.cs

index cbb752b3af4c072d03ddade6415951911c13b797..a0bfd8ef649ec2758f6ef7b57cfca95d278b8019 100644 (file)
@@ -1,3 +1,12 @@
+2003-06-30  Zoltan Varga  <vargaz@freemail.hu>
+
+       * FileStream.cs (Dispose): Flush the buffer even if we don't own the
+       handle.
+       * FileStream.cs: Add a new constructor parameter to turn off buffering.
+       This is used by the Console.OpenStandard...() methods. Also fix
+       argument checking in InitBuffer(), so a zero buffer size is also 
+       rejected.
+
 2003-06-27  Dietmar Maurer  <dietmar@ximian.com>
 
        * Stream.cs: use async.delegate invoke 
index e29fd3b4e13b6603e1a7f371abfbc71fbecaff3b..8f845a00ca9363e201fabd76f992a62d138771a1 100644 (file)
@@ -30,6 +30,9 @@ namespace System.IO
                        : this (handle, access, ownsHandle, bufferSize, false) {}\r
 
                public FileStream (IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync)
+                       : this (handle, access, ownsHandle, bufferSize, isAsync, false) {}
+
+               internal FileStream (IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool noBuffering)
                {
                        if (access < FileAccess.Read || access > FileAccess.ReadWrite)
                                throw new ArgumentOutOfRangeException ("access");
@@ -49,8 +52,8 @@ namespace System.IO
                        } else {
                                this.canseek = false;
                        }
-                       
-                       InitBuffer (bufferSize);
+
+                       InitBuffer (bufferSize, noBuffering);
 
                        /* Can't set append mode */
                        this.append_startpos=0;
@@ -97,7 +100,7 @@ namespace System.IO
                                throw new UnauthorizedAccessException ("Access to the path '" + Path.GetFullPath (name) + "' is denied.");
                        }
 
-                       InitBuffer (bufferSize);
+                       InitBuffer (bufferSize, false);
 
                        /* Append streams can't be read (see FileMode
                         * docs)
@@ -497,16 +500,18 @@ namespace System.IO
                }\r
 
                protected virtual void Dispose (bool disposing) {
-                       if (owner && handle != MonoIO.InvalidHandle) {
+                       if (handle != MonoIO.InvalidHandle) {
                                lock(this) {
                                        FlushBuffer ();
                                }
 
-                               MonoIOError error;
+                               if (owner) {
+                                       MonoIOError error;
                                
-                               MonoIO.Close (handle, out error);
+                                       MonoIO.Close (handle, out error);
 
-                               handle = MonoIO.InvalidHandle;
+                                       handle = MonoIO.InvalidHandle;
+                               }
                        }
 
                        canseek = false;
@@ -615,15 +620,18 @@ namespace System.IO
                        
                        return(amount);
                }
-               
-               
-               private void InitBuffer (int size)\r
+                               
+               private void InitBuffer (int size, bool noBuffering)\r
                {\r
-                       if (size < 0)\r
-                               throw new ArgumentOutOfRangeException ("Buffer size cannot be negative.");\r
-                       if (size < 8)\r
-                               size = 8;\r
-               \r
+                       if (noBuffering)
+                               size = 0;
+                       else {
+                               if (size <= 0)
+                                       throw new ArgumentOutOfRangeException ("bufferSize", "Positive number required.");
+                               if (size < 8)
+                                       size = 8;
+                       }
+                                       
                        buf = new byte [size];\r
                        buf_size = size;\r
                        buf_start = 0;\r