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

Need AllocateReadBuffer() #125

Open
rodrigc opened this issue Oct 28, 2017 · 4 comments
Open

Need AllocateReadBuffer() #125

rodrigc opened this issue Oct 28, 2017 · 4 comments

Comments

@rodrigc
Copy link
Contributor

rodrigc commented Oct 28, 2017

In Twisted, I tried to replace pywin32 with pywincffi: twisted/twisted#920

I found that winfile.AllocateReadBuffer() is not in pywincffi.

@opalmer can you add it?

@opalmer
Copy link
Owner

opalmer commented Oct 29, 2017

I don't think it's needed? That's not a standard win32 function and it appears to be a helper created for pywin32 as an abstraction. Twisted is calling ReadFile() and using AllocateReadBuffer() in _win32serialport.py to create a buffer to write the data to it appears.

pywincffi also has the ReadFile() function but instead of requiring a buffer to write a result to, which does not mirror the win32 api signature, you need to tell it how much data to read and then ReadFile() should be able to return the read data.

@exvito
Copy link
Contributor

exvito commented Oct 29, 2017

Chiming in with a note:

From a quick read of Twisted's _win32serialport.py it seems to be using Overlapped I/O on ReadFile(), that's why it needs a buffer. I'm not sure the current ReadFile() implementation supports overlapped I/O, but #116 is still pending...

@opalmer
Copy link
Owner

opalmer commented Oct 29, 2017

Yeah I was looking at that.....ReadFile() may need some modification or we might need a new function like ReadFileEx. This honestly needs some more research first to figure out how to accomplish Overlapped I/O correctly with cffi. Most of the structures and things like GetOverlappedResult are there but building a test case/fix around win32serialport.py is probably what needs to happen just to make sure everything works as expected.

@opalmer
Copy link
Owner

opalmer commented Nov 23, 2017

So looking at the tests:

https://github.com/opalmer/pywincffi/blob/master/tests/test_kernel32/test_overlapped.py#L20

overlapped IO is possible right now just not through ReadFile like @exvito said. I'm going to look updating ReadFile() to support overrlapped IO like it's supposed to.

As for AllocateReadBuffer, I may or may not create a similar function for pywincffi. Reason being is looking at pywin32's source code AllocateReadBuffer appears to just return a standard python buffer object which is something pywincffi does not have an analog for (we're using cffi rather making a C-extension). Regardless, given we're working with _win32serialport here getting overlapped support into ReadFile is probably the thing that needs to be done to resolve this issue.

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

3 participants