Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadFile - Change to support overlapped IO #116

Open
exvito opened this issue Jul 26, 2016 · 1 comment
Open

ReadFile - Change to support overlapped IO #116

exvito opened this issue Jul 26, 2016 · 1 comment

Comments

@exvito
Copy link
Contributor

exvito commented Jul 26, 2016

In #115 I mentioned what I believe are current limitations to support overlapped IO in ReadFile.

I investigated a bit and, maybe, if...

  • ReadFile instantiates a Python bytearray (which is mutable) as the read buffer.
  • Uses ffi.from_buffer(bytearray) as the lpBuffer for ReadFile
  • Returns that bytearray as the result

...then the OS will be able to write the data there and the caller, now holding a reference to that mutable bytearray, can access it (after GetOverlappedResult or equivalent signals its ok, of course).

I'm just not sure about:

  • Memory ownership / leaks that can result from this approach (needs thinking).
  • How Pythonic such an approach is: call ReadFile and get a muttable buffer which will change under your feet, once the overlapped IO is completed.
@opalmer
Copy link
Owner

opalmer commented Jul 27, 2016

Memory ownership / leaks that can result from this approach (needs thinking).

I think that's managed by cffi, but it's probably something we could test.

How Pythonic such an approach is: call ReadFile and get a muttable buffer which will change under your feet, once the overlapped IO is completed.

I wouldn't call it Pythonic but I would said it's probably fairly standard from a Windows perspective. Considering pywincffi is wrapping Windows functions it's probably better to be more windows-like in cases like this than Pythonic (which should make the behavior more predictable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants