+2003-06-11 Zoltan Varga <vargaz@freemail.hu>
+
+ * FileStream.cs: Fix errors in previous checkins:
+ (Write): Only take the shortcut route if the data is longer than the
+ buffer length.
+ (Write): Flush the buffer before writing out the new data
+ (Write): Flush the buffer after writing out a segment since otherwise
+ we will go into an infinite loop.
+ (FlushBuffer): Remove my last change since it was clearly wrong.
+ (Seek): Run FlushBuffer () after the in-buffer seek optimization.
+ (Seek): Only use the in-buffer optimization if the buffer is not
+ empty.
+ (Length): Call FlushBuffer () since buffer data might change the size
+ of the stream.
+
2003-06-09 Ville Palo <vi64pa@kolumbus.fi>
* FileStream.cs:
if (!canseek)
throw new NotSupportedException ("The stream does not support seeking");
+ // Buffered data might change the length of the stream
+ FlushBufferIfDirty ();
+
MonoIOError error;
return MonoIO.GetLength (handle, out error);
if (!CanWrite)
throw new NotSupportedException ("Stream does not support writing");
-
-
if (count > buf_size) {
// shortcut for long writes
MonoIOError error;
-
+
+ FlushBuffer ();
+
MonoIO.Write (handle, src, src_offset, count, out error);
buf_start += count;
} else {
int n = WriteSegment (src, src_offset + copied, count);
copied += n;
count -= n;
-
+
if (count == 0) {
break;
}
+
+ FlushBuffer ();
}
}
}
lock(this) {
- FlushBuffer ();
-
switch (origin) {
case SeekOrigin.End:
pos = Length + offset;
/* More undocumented crap */
throw new IOException("Can't seek back over pre-existing data in append mode");
}
-
- if (pos >= buf_start &&
- pos <= buf_start + buf_length) {
- buf_offset = (int) (pos - buf_start);
- return pos;
+
+ if (buf_length > 0) {
+ if (pos >= buf_start &&
+ pos <= buf_start + buf_length) {
+ buf_offset = (int) (pos - buf_start);
+ return pos;
+ }
}
+ FlushBuffer ();
+
MonoIOError error;
buf_start = MonoIO.Seek (handle, pos,
MonoIO.Write (handle, buf, 0,
buf_length, out error);
}
-
+
buf_start += buf_offset;
buf_offset = buf_length = 0;
buf_dirty = false;
}
+ private void FlushBufferIfDirty ()
+ {
+ if (buf_dirty)
+ FlushBuffer ();
+ }
+
private void RefillBuffer ()
{
FlushBuffer();