tags:

views:

85

answers:

2

I would like to use the Overlapped IO functions in a .Net app, specifically WriteFileGather. Is this supported through the standard class library?

Bonus points: does it work in Mono?

A: 

FileStream Class exposes a stream around a file, supporting both synchronous and asynchronous read and write operations. The default implementation of BeginWrite on a stream calls the Write method synchronously, which means that Write might block on some streams. However, instances of classes such as FileStream and NetworkStream fully support asynchronous operations if the instances have been opened asynchronously. Therefore, calls to BeginWrite will not block on those streams. The FileStream Class should work exactly the same on mono.

almog.ori
Not quite what I was looking for, the asynchronous methods still handle single buffers. I was looking for something similar to Java's GatheringByteChannel.
Michael Barker
+1  A: 

There is no direct function in .NET BCL, but there are some classes that can help you with Windows I/O. 1) Initialize an instance of Overlapped class.

2) Call Pack with the callback.

3) Pass the resulting NativeOverlapped (the return value of Pack) to the WriteFileGather.

4) As I understand, your callback should be called on a worker thread when the operation is complete.

Be sure to read MSDN docs on WriteFileGather as there are some requirements, e.g. the data must be aligned on the system's page boundary (I think 4K on x86-x64, 8K on Itanium) etc. etc.

liggett78