Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DBLouis
Copy link

@DBLouis DBLouis commented Jul 19, 2025

This allows to create socket with the WSA_FLAG_REGISTERED_IO flag.

@@ -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 = []
Copy link
Collaborator

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?

Copy link
Author

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 {
Copy link
Collaborator

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?

Copy link
Author

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.
Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Collaborator

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).

Copy link
Author

@DBLouis DBLouis Jul 21, 2025

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.

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

Successfully merging this pull request may close these issues.

2 participants