-
Notifications
You must be signed in to change notification settings - Fork 81
Add file handle support for overlapped I/O #248
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
base: master
Are you sure you want to change the base?
Conversation
d0cf4d3
to
5e24b6b
Compare
5e24b6b
to
d60ff79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I imagine this was a significant effort. I appreciate you writing this. However, I definitely need to read through this and understand this. So this review may take some time.
The immediate thing that jumps out at me is the weird pointer offsets in the FileOverlapped
traits. This seems fragile to me. I would prefer them to be direct pointers; I think that would be better when it comes to strict provenance.
Also, have you run this code under Miri on Windows?
Hi @notgull Thanks for reviewing. FileCompletionHandle trait would provide conversion from overlapped pointer to packet which will depends on FileOverlapped trait providing pointer offset to packet. Maybe should rename FileOverlapped to FileOverlappedOffset. I do not run the code with miri. Currently I am writing NamedPipe code in async_io crate. I found the code need some change in order for better integration with async_io. I also found a problem that is IOCP port still can receive event after the file handle is removed from the poller and file handle is closed as long as there is I/O operation with overlapped pointer. But the packet has been dropped at this time. This will cause memory access violation I will request review after the issue is fixed. I will also run code in miri and solve your comments. |
59c489c
to
4089e77
Compare
Hi @notgull I have updated the code to solve IocpFilePacket returned by add_file lifetime issue. The idea is IocpFilePacket will increase reference count of Packet, so the Pakcet is still valid when the Poller is dropped. And for every success overlapped I/O operation ((the operation return TRUE or ERROR_IO_PENDING) will also add reference count, the reference count will decrease after the IOCP event is received. This will make sure the IOCP returned overlapped pointer still valid even the packet is remove from the poller and IocpFilePacket is dropped. I also update the code according your previous comments. I implmeneted NamedPipe in async-io according the updated polling code. The test code is https://github.com/klu-dev/async-io/blob/kail/windows_named_pipe/tests/windows_named_pipe.rs . The main function has completed. I am thinking adding MESSAGE mode and configurable parameter when create named pipe. I try to run miri, but get the following error. Miri do not support code calling native OS API. So the code add an IocpFilePacket::test_ref_count method used in test case to check Packet Arc count. test writable_after_register ... error: unsupported operation: CreateFileW: Unsupported flags_and_attributes: 1073741824 |
24eb900
to
550d1eb
Compare
550d1eb
to
f7d8dad
Compare
Noting that I've seen this patch, I'm doing research to ensure everything is sound. |
Closes #97
This is an implementation to support Windows file handle overlapped I/O. The basic idea is: