From 6bf4eea8b295841f92a2080d90889f24dc2ff56d Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Mon, 30 Jun 2003 12:34:26 +0000 Subject: [PATCH] 2003-06-30 Zoltan Varga * 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 | 9 ++++++ mcs/class/corlib/System.IO/FileStream.cs | 38 ++++++++++++++---------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/mcs/class/corlib/System.IO/ChangeLog b/mcs/class/corlib/System.IO/ChangeLog index cbb752b3af4..a0bfd8ef649 100644 --- a/mcs/class/corlib/System.IO/ChangeLog +++ b/mcs/class/corlib/System.IO/ChangeLog @@ -1,3 +1,12 @@ +2003-06-30 Zoltan Varga + + * 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 * Stream.cs: use async.delegate invoke diff --git a/mcs/class/corlib/System.IO/FileStream.cs b/mcs/class/corlib/System.IO/FileStream.cs index e29fd3b4e13..8f845a00ca9 100644 --- a/mcs/class/corlib/System.IO/FileStream.cs +++ b/mcs/class/corlib/System.IO/FileStream.cs @@ -30,6 +30,9 @@ namespace System.IO : this (handle, access, ownsHandle, bufferSize, false) {} 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 } 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) + + private void InitBuffer (int size, bool noBuffering) { - if (size < 0) - throw new ArgumentOutOfRangeException ("Buffer size cannot be negative."); - if (size < 8) - size = 8; - + if (noBuffering) + size = 0; + else { + if (size <= 0) + throw new ArgumentOutOfRangeException ("bufferSize", "Positive number required."); + if (size < 8) + size = 8; + } + buf = new byte [size]; buf_size = size; buf_start = 0; -- 2.25.1