* Marking code as unchecked (pt 9)
Additional unchecked for new test code and missed cases in BitConverter
* Marking code as unchecked (pt 9a)
Added unchecked to two casts in ManagedWebSocket
* CI test failure fixes
Overflow exceptions in:
- Windows NT Debug dotnet/corefx#3458
- OS X Debug dotnet/corefx#3357
* CI test failure fixes
Overflow exceptions in:
- Windows 7 Debug Outerloop (build 8)
- OS X Debug Outerloop (build 45)
* CI test failure fixes
Fixed overflow exception from OS X Debug Outerloop (build 46)
Commit migrated from https://github.com/dotnet/corefx/commit/7f6ac8bf97a84666ed3e7ef6b77c1a9470ae78c8
Adds negative tests for Begin/End, removes unnecessary block for `\\.\`
paths.
(The block for `\\.\` paths fulfills a need that predates our supported
Windows OSes. You cannot inadvertently mess up "raw" drives. In addition
we currently allow `\\?\` which is another form of device path access.)
Commit migrated from https://github.com/dotnet/corefx/commit/5376c25bea9523265696ed5806f3dc8b51bbbf25
Adds:
- File.WriteAllLines(string, string[])
- File.WriteAllLines(string, string[], Encoding)
- File.Replace(string, string, string)
- File.Replace(string, string, string, bool)
- File.Encrypt(string)
- File.Decrypt(string)
- FileInfo.Encrypt()
- FileInfo.Decrypt()
- FileStream.Handle
- FileStream.Lock(long, long)
- FileStream.Unlock(long, long)
Currently throws PlatformNotSupportedException from:
- Encrypt/Decrypt on all platforms. These can be implemented on Win32, but the APIs needed are not currently exposed as allowed in buildtools.
- Lock/Unlock on Unix and WinRT. These can be implemented on Unix; I just didn't in this commit.
Commit migrated from https://github.com/dotnet/corefx/commit/2fbc772ea8bd83a37b9f26c1a7c928a6be2d2c0b
The new FileStreamBase.Begin/End overloads do argument and state validation similar to that of desktop. There is a subtle but critical difference, however: in this validation, desktop checks to see whether the stream is closed via ```_handle.IsClosed```, whereas FileStreamBase does it via ```SafeFileHandle.IsClosed```. ```SafeFileHandle``` is an abstract property that returns the handle... but it also flushes. The base Stream's Begin/End implementation has synchronization to ensure that only one async operation is in flight at a time, but this call to ```SafeFileHandle.IsClosed``` comes before that synchronization kicks in (it's in the base), and as such we end up potentially having a Flush invocations concurrently with Write invocations (Write is called asynchronously from the base BeginWrite), which is very unsafe.
This commit fixes it by adding an IsClosed property that goes directly to the underlying handle, bypassing the publicly exposed SafeFileHandle (that flushes so that direct access to the file via the handle is consistent with operations already performed on the FileStream).
(I also fixed a small issue in the ManyConcurrentWriteAsyncs that highlighted the issue. Order of async read/write operations is only guaranteed on FileStream when in async mode; in non-async mode, it's theoretically possible (though unlikely) for operations to complete out-of-order, but the test is validating that the operations completed in order. While I've never seen this fail, I'm proactively fixing it.)
Commit migrated from https://github.com/dotnet/corefx/commit/5afb9f69400cbb61971a7eeb4fcfc49fbbc1080b
FileStream can be used with any arbitrary file descriptor on Unix. FileStream.Flush may use FSync to try to synchronize the file's state with the storage device, but that only makes sense and works for certain kinds of file descriptors. For other file descriptors, currently we're throwing an exception if the operation fails, when really we should just ignore the failure, as there's no work to be done.
Commit migrated from https://github.com/dotnet/corefx/commit/1994ac4a43105cda48c2fbcdf967d6ae48330e0e
Changes:
- An outerloop test verifying that we would throw when trying to use File.ReadAllBytes to read a > 2GB file was first writing out 2GB worth of data to disk. We can instead just create a FileStream and explicitly change its length. On my machine, this changes the execution time of that test from ~25s to just a few milliseconds.
- Two "mini stress" tests are enabled in outerloop and are explicitly coded to run for 30 seconds doing lots of reading and writing. I've changed these to be 10 seconds.
Commit migrated from https://github.com/dotnet/corefx/commit/e4c1fed1843c2dc80b9b345d6fac0251e865a227
FileStream's ctors allow the creator of the stream to specify whether asynchronous I/O should be used. The default in the full framework is false. When FileStream was ported to corefx, the default was changed to true.
Such a default of true can be beneficial, as it means that ReadAsync/WriteAsync calls on streams created without overriding that default will naturally use overlapped I/O on Windows, which can lead to better scalability and performance. However, there are other ramifications, in particular for existing code and code written to be portable across .NET implementations. For example:
- Using Read/Write on a stream created with useAsync=true ends up blocking as calls around Read/WriteAsync, making them more expensive than they'd otherwise be. So existing code that uses a FileStream for simple read/writes may actually get slower.
- The SafeFileHandle exposed from the FileStream naturally is associated with that particular async setting, such that attempting to use it to construct a FileStream with a conflicting setting will fail with an exception.
- FileStreams constructed with useAsync=true have special behaviors around how the position of the stream is updated after an async operation is initiated, which means code written expecting one default may fail when run with a different default.
- Etc.
While there are benefits to changing the default, the cons outweigh the pros. A developer can always opt-in to useAsync=true, but it's better to keep the default consistent across all implementations, especially for code written to be portable across those implementations. This commit changes it back to be false.
Commit migrated from https://github.com/dotnet/corefx/commit/08991e80aa6ce5ab7e43265b30824a91f6112db4
flock on OSX can fail with ENOTSUP if "the referenced descriptor is not of the correct type", e.g. if it's a FIFO. Since we don't want to entirely prevent usage of FileStream with such file types on OSX, and since locking is already advisory only, this change just ignores rather than throws when flock fails with ENOTSUP.
Commit migrated from https://github.com/dotnet/corefx/commit/38177bc1de3a73ef5e8b5f449478ea588406a4b4
The default CopyToAsync on Stream uses an 80K temporary buffer, making it a good candidate for buffer pooling. But Stream is in mscorlib and can't rely on System.Buffers. So this commit introduces an implementation that streams in mscorlib can use, just by overriding CopyToAsync and delegating. It then uses that in DeflateStream, GZipStream, FileStream, PipeStream, and UnmanagedMemoryStream.
Commit migrated from https://github.com/dotnet/corefx/commit/34ce38bc1517e8b7693223a9e41479dd24abc59a
Currently, the tests System.IO.Tests.FileStream_SafeFileHandle.
ThrowWhenHandlePositionIsChanged and System.Net.NetworkInformation.
Tests.UnixPingUtilityTests.PacketSizeIsRespected hang when running on a
Unix machine with 1 thread. Declaring the tests async fixes this issue.
Commit migrated from https://github.com/dotnet/corefx/commit/6d15aa69e332866e6282994edfd2de5ca0192899
Three tests were consuming the vast majority of the time:
- DirectoryLongerThanMaxLongPathWithExtendedSyntax_ThrowsPathTooLongException. It was taking 70 seconds on my machine. I moved it to outer loop.
- ManyConcurrentWriteAsyncs. It uses a MemberData that results in it executing ~40 times, for a combined time of around 7 seconds on my machine. I made one combination run in inner loop and moved the rest to outer.
- CopyToAsyncBetweenFileStreams. Same MemberData, same solution.
Commit migrated from https://github.com/dotnet/corefx/commit/03205295cc6834b1fdcd8b7ba364515f4ec7164a
- Mainly, I added several tests (with lots of theory-based parameterized inputs) to stress WriteAsync: many concurrent writes, long chains of writes, etc., for various size inputs and buffers, async vs not, etc.
- There were multiple variations on Flush tests based on whether to use Flush(), Flush(false), or False(true). I combined these all into single theories.
- I then added some more Flush tests for some missing cases highlighted by code coverage, e.g. flushing reads.
- I then duplicated these tests for FlushAsync, and added some additional tests specific to FlushAsync, e.g. cancellation.
- I added a few tests for pipes.
Commit migrated from https://github.com/dotnet/corefx/commit/bb34d5a458613faa39d3808a8a352e62e3bcf52f
1) Internal buffer overflows, but write can fit in next buffer - Fill the existing buffer, copy the remaining data into a new buffer, and flush the original to disk
2) Internal buffer is non-empty, overflows, and the remaining data won't fit in a second buffer - Chain the flush operation to a second write operation which writes the entire incoming block directly to disk.
Additionally, adds a new unit test to ensure the different buffering cases are being covered.
Commit migrated from https://github.com/dotnet/corefx/commit/b69caa929d3cb3b87574ee31a651d799f61e3a75