Don't pass FILE_FLAG_OVERLAPPED to CreateFile()
commit1c6422e455a7fe461c25da7a7c1514e65a7f0477
authorNiklas Therning <niklas@therning.org>
Wed, 24 Aug 2016 08:49:23 +0000 (24 10:49 +0200)
committerNiklas Therning <niklas@therning.org>
Wed, 24 Aug 2016 08:49:23 +0000 (24 10:49 +0200)
tree79c7d383456aea98481f31f57c22ebeed737727f
parent82b02262cf729c28deda588a17c60fb71a478998
Don't pass FILE_FLAG_OVERLAPPED to CreateFile()

When a FileStream is opened with the FileOptions.Asynchronous flag set the
code in file-io.c will pass FILE_FLAG_OVERLAPPED to the CreateFile() function.
On Windows this means the file will be in asynchronous mode and when
ReadFile()/WriteFile() are called an OVERLAPPED struct has to be passed. Mono
doesn't do this which means that when reading/writing asynchronous FileStreams
Windows returns an ERROR_INVALID_PARAMETER and an exception is raised in
managed code.

This patch simply removes the code which passes the FILE_FLAG_OVERLAPPED to
CreateFile(). This will work since asynchronous I/O is handled in managed code
anyway, using threads. On the OS level the I/O is still synchronous. The patch
won't affect other platforms since the implementation of
ReadFile()/WriteFile()/etc in mono/io-layer/, which is used on non-Windows, is
always synchronous and ignores the FILE_FLAG_OVERLAPPED.

This bug was triggered by the
MonoTests.System.IO.BinaryWriterTest.AsynchronousModeWrites test.
mono/metadata/file-io.c