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

Signed vs. unsigned flags types in winsock2 APIs #849

Closed
sunfishcode opened this issue Mar 23, 2022 · 7 comments · Fixed by #893
Closed

Signed vs. unsigned flags types in winsock2 APIs #849

sunfishcode opened this issue Mar 23, 2022 · 7 comments · Fixed by #893
Assignees
Labels
usability Touch-up to improve the user experience for a language projection

Comments

@sunfishcode
Copy link

sunfishcode commented Mar 23, 2022

Receive flag values such as MSG_WAITALL have type u32.

The flags argument of the recv function it's meant to be passed to has type i32.

send's flags argument has a dedicated type for its flags parameter called SEND_FLAGS. SEND_FLAGS is a u32.

The doc links above reference the latest version of windows-sys, which as of this post is 0.34.0.

In the POSIX specifications for send and recv, as well as the send and recv functions on all popular
Unix-family platforms, the flags argument is int, which is i32 in practice. And in winapi it's i32 as well.

In light of the above, the following would make the API more convenient:

  • The recv flag values should have the same type as the recv's flags parameter so that the can be passed in without casting.
  • send's and recv's flags parameters should have the same type as it does on Unix-family platforms, to make it easier to write portable code.
@riverar
Copy link
Collaborator

riverar commented Mar 23, 2022

Transferring to win32metadata.

@riverar riverar transferred this issue from microsoft/windows-rs Mar 23, 2022
@mikebattista
Copy link
Collaborator

So you'd prefer we remove the SEND_FLAGS enum and just use i32 constants for both send and recv, rather than introduce RECV_FLAGS and switch both enums to i32?

@riverar
Copy link
Collaborator

riverar commented Mar 24, 2022

I'd keep the enums and just ensure they are both i32 so no casting is necessary. (Note that the MSG_OOB flag is used by both APIs.)

@mikebattista
Copy link
Collaborator

We can't have members with the same name across enums or that will also cause problems particularly for Rust. We probably need to keep loose constants here if some values are shared across both.

@riverar
Copy link
Collaborator

riverar commented Mar 24, 2022

Had a chat with @kennykerr and we settled on merging the two enums into a SEND_RECV_FLAGS enum.

@mikebattista
Copy link
Collaborator

If that works for everybody, we can do that.

@mikebattista mikebattista self-assigned this Mar 28, 2022
@riverar riverar added the usability Touch-up to improve the user experience for a language projection label Apr 16, 2022
@kennykerr
Copy link
Contributor

0.36.0 of the windows crate has been released and includes this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Touch-up to improve the user experience for a language projection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants