pinvoke icon indicating copy to clipboard operation
pinvoke copied to clipboard

Async wrappers for overlapped I/O

Open qmfrederik opened this issue 5 years ago • 6 comments

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?

qmfrederik avatar Jul 07 '20 11:07 qmfrederik

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?

AArnott avatar Jul 08 '20 15:07 AArnott

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

  • DeviceIoControl
  • WinUsb_ReadPipe
  • WinUsb_WritePipe

qmfrederik avatar Jul 10 '20 07:07 qmfrederik

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 avatar Jul 12 '20 19:07 AArnott

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

AArnott avatar Jul 12 '20 21:07 AArnott

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.

qmfrederik avatar Jul 12 '20 21:07 qmfrederik

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

AArnott avatar Jul 12 '20 21:07 AArnott