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

Socket::keepalive doesn't work on Windows #24

Closed
sfackler opened this issue Apr 15, 2018 · 4 comments · Fixed by #148
Closed

Socket::keepalive doesn't work on Windows #24

sfackler opened this issue Apr 15, 2018 · 4 comments · Fixed by #148

Comments

@sfackler
Copy link
Member

There is apparently not any way of reading these values.

@alexcrichton
Copy link
Member

Weird, does the ioctl we execute do anything at all?

And for posterity I think the relevant test which is the impetus for this is here:

https://github.com/alexcrichton/socket2-rs/blob/f1952af36473cbd0934a660fde2f0851c5941033/src/socket.rs#L974-L984

@sfackler
Copy link
Member Author

It fails because the input pointer is invalid.

@yorickpeterse
Copy link
Contributor

I also ran into this issue. When obtaining the keepalive value, an error is returned with the following message:

The system detected an invalid pointer address in attempting to use a pointer argument in a call. (os error 10014)

Unfortunately, I know next to nothing about the winsocks API so I'm not sure how to determine what the root cause is, and how to fix it.

@hawkw
Copy link

hawkw commented Nov 5, 2020

I did some research, and as far as I can tell, the Microsoft documentation doesn't make any mention of accessing the keepalive values using WSAIoctl, or via any other function. However, it never clearly states that this is not possible.

The closest thing to a definitive answer I could find is this StackOverflow answer (admittedly, not the most reliable source), which states:

The system doesn't have any method of checking the current values of the tcp_keepalive structure passed to WSAIoctl for SIO_KEEPALIVE_VALS. You can set them to the values you want, but you cannot interrogate what they are presently.

Of course, it's still possible to test whether or not keepalive is enabled for a socket on Windows, by using getsockopt(SOL_SOCKET, SO_KEEPALIVE, ...), as one would on Linux. However, it's not possible to retrieve the keepalive time. The only good solution I can think of is splitting the API into two methods, one of which returns a bool indicating whether or not TCP keepalive is enabled, and another which returns the configured keepalive idle duration. The second would have to be #[cfg(not(windows))].

Thomasdezeeuw added a commit to Thomasdezeeuw/socket2 that referenced this issue Dec 18, 2020
Originally implemented by @hawkw here in
tokio-rs/mio#1385.

Closed rust-lang#79.
Fixes rust-lang#24.
Thomasdezeeuw added a commit that referenced this issue Dec 19, 2020
Originally implemented by @hawkw here in
tokio-rs/mio#1385.

Closed #79.
Fixes #24.
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 a pull request may close this issue.

4 participants