dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

Async wrappers for overlapped I/O #500

Closed qmfrederik closed 1 year ago

qmfrederik commented 4 years ago

Overlapped I/O in Win32 maps to async I/O in .NET.

There's some boilerplate code that needs to be written to make overlapped I/O functions behave as async methods in .NET. For example, here's how .NET Core does it for the FileStream.

Are these async wrappers for I/O operations in scope for dotnet/pinvoke?

AArnott commented 4 years ago

Helper methods are documented in our contributing guidelines as enabling such things as IEnumerable<T>, so returning Task may fit. But I would hesitate to recreate an full async I/O stack, particularly if it's redundant with what .NET has. Would it be?

qmfrederik commented 4 years ago

Methods for which I have a personal interest in adding them:

AArnott commented 4 years ago

I took a look at your PR and it looks like something that may belong in the repo. But I'm still curious whether async IO is something you could just do with the .NET base class libraries as opposed to requiring a p/invoke level API.

AArnott commented 4 years ago

Never mind. I guess DeviceIoControl is a very low-level API that likely isn't exposed by the .NET BCL.

qmfrederik commented 4 years ago

Correct; I looked for DeviceIoControl in .NET Core. It was there, but it was dead code: dotnet/runtime#38861 . WinUSB is not in .NET at all.

On the other hand, there's a bunch of P/Invoke code at https://github.com/dotnet/runtime/tree/master/src/libraries/Common/src/Interop/Windows which may serve as a reference for dotnet/pinvoke.

AArnott commented 4 years ago

Oh wow. What a great resource, @qmfrederik. Thanks for sharing. I've added the link to our contributing doc.