-
Notifications
You must be signed in to change notification settings - Fork 259
Add support for Windows Registered I/O #604
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
@@ -65,6 +65,8 @@ features = [ | |||
[features] | |||
# Enable all API, even ones not available on all OSs. | |||
all = [] | |||
# Enable Windows Registered I/O support. | |||
registered-io = [] |
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.
Why are you adding a feature for this?
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.
Not sure, I can remove it.
self._registered_io() | ||
} | ||
|
||
pub(crate) const fn _registered_io(self) -> Type { |
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.
Why is this function needed? Can't it be inline into registered_io
?
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.
I just copied how they done it for the other custom flag, but I guess it is not needed.
@@ -136,6 +136,19 @@ impl Type { | |||
pub(crate) const fn _no_inherit(self) -> Type { | |||
Type(self.0 | Type::NO_INHERIT) | |||
} | |||
|
|||
/// Our custom flag to set `WSA_FLAG_REGISTERED_IO` on socket creation. | |||
const REGISTERED_IO: c_int = 1 << ((size_of::<c_int>() * 8) - 2); // Second last bit. |
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.
Is this defined window_sys
crate? I don't want to maintain constant values.
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.
My understanding is that those custom flags are not real values for Type, just a "hack" to be able to set socket flags without changing the signature of Socket::new
.
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.
It's fine to work to similar to WSA_FLAG_NO_HANDLE_INHERIT
. But let's use windows::Win32::Networking::WinSock::WSA_FLAG_REGISTERED_IO (https://docs.rs/windows-sys/latest/windows_sys/Win32/Networking/WinSock/constant.WSA_FLAG_REGISTERED_IO.html).
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.
I think there is a misunderstanding here. I am using WSA_FLAG_REGISTERED_IO
. Like for WSA_FLAG_NO_HANDLE_INHERIT
, those are windows-only bitflags passed into the flags argument of the WSASocket
function. They are not valid bits in the type parameter. The socket
function doesn't have an additional flags parameter, so this crate has one (now two) custom Type
values, which allows setting those flags, by using unused bits at the end of the Type
value.
This allows to create socket with the
WSA_FLAG_REGISTERED_IO
flag.