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

Async::<TcpStream>::connect fails on windows #182

Closed
gzmorell opened this issue Jan 25, 2024 · 4 comments
Closed

Async::<TcpStream>::connect fails on windows #182

gzmorell opened this issue Jan 25, 2024 · 4 comments

Comments

@gzmorell
Copy link

connect fails on windows with "Either the application has not called WSAStartup, or WSAStartup failed."

According to "https://docs.rs/rustix/0.38.30/x86_64-pc-windows-msvc/rustix/net/fn.wsa_startup.html"
pub fn wsa_startup() -> Result
"On Windows, it’s necessary to initialize the sockets subsystem before using sockets APIs. The function performs the necessary initialization."
Calling this function before trying to connect solves the problem.

@notgull
Copy link
Member

notgull commented Jan 25, 2024

Ah right. With rustix's socket functions you need to call wsa_startup manually.

This can be fixed by either calling that function or by creating and destroying a TcpStream.

@gzmorell
Copy link
Author

But rustix function is not in the api of async-io, so I think it should be called internally. Not by the user of the library. This problem affects smol, as you cannot connect to a socket on windows. This example in smol crate fails to run on windows:
https://github.com/smol-rs/smol/blob/master/examples/tcp-client.rs

@notgull
Copy link
Member

notgull commented Jan 25, 2024

Yes. I'll accept a PR that creates a network socket internally in order to set up networking. If not I'll file one later.

@gzmorell
Copy link
Author

gzmorell commented Jan 25, 2024

As far as I understand this: ""On Windows, it’s necessary to initialize the sockets subsystem before using sockets APIs" means that at least the function should be called once. So it can be called only once. I have no idea what can happen if it is called more than once.
Should a kind of lazy static initialization a bad idea?
Furthermore calling wsa_startup can fail

notgull added a commit that referenced this issue Jan 26, 2024
This commit adds a setup_networking function. On most platforms it does
nothing. However, on Windows it calls `wsa_startup`. This ensures that
all networking is set up before anything else is called.

Closes #182

Signed-off-by: John Nunley <dev@notgull.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants