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

UdpSocket is missing the shutdown method #23194

Closed
alexcrichton opened this issue Mar 8, 2015 · 6 comments
Closed

UdpSocket is missing the shutdown method #23194

alexcrichton opened this issue Mar 8, 2015 · 6 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@alexcrichton
Copy link
Member

Should be easy enough to implement! Good first bug for anyone and I'd be willing to mentor.

@alexcrichton alexcrichton added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-io E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Mar 8, 2015
@aatxe
Copy link
Member

aatxe commented Mar 8, 2015

I've made an attempt at implementing this that builds, but the information I've found on the matter seems to indicate that shutting down a UDP socket doesn't really make sense. That being said, resources indicate that shutdown does work on UDP sockets. So, I'm admittedly rather confused.

It's not useful.

See step 5: https://www.cs.rutgers.edu/~pxk/417/notes/sockets/udp.html
https://lists.apple.com/archives/macnetworkprog/2008/Jan/msg00002.html

It works.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms740481(v=vs.85).aspx
http://linux.die.net/man/3/shutdown

@LorenVS
Copy link

LorenVS commented Mar 8, 2015

I think the goal here is a way to terminate a thread that is dedicated to reading from a UDP socket. Currently, recv_from blocks indefinitely and there is no way to signal it to terminate for a clean shutdown. I believe setting Shutdown::Read would cause the currently blocking recv_from to return with an error, which could be handled to implement clean shutdown.

There was a similar discussion on #14926 regarding close_read/close_write. I believe the agreement was that Shutdown::Write isn't horribly useful for UDP sockets. Even if you have a dedicated thread for sending out of a UdpSocket, you are more likely to signal termination by dropping the channel which sends data to that thread, rather than shutting down the socket itself.

@KiChjang
Copy link
Member

KiChjang commented Mar 9, 2015

I'd like to give this one a try. I have a basic understanding of how UDP works, but I still don't understand where everything is in the source code.

@alexcrichton
Copy link
Member Author

@aatxe yes as @LorenVS mentioned it may not have the best semantics in all situations, but it definitely does something on supported platforms and we largely want to expose it for symmetry with the TCP primitives.

@KiChjang the methods would be added to src/libstd/net/udp.rs and you could follow similar delegation patterns to add the implementations themselves to src/libstd/sys/common/net2.rs. You could then do basically the same as TcpStream::shutdown in that file, although I would recommend refactoring into a helper method.

@alexcrichton
Copy link
Member Author

Given the outcome of #23214 it looks like we may not actually want to implement this at this time. @aatxe's investigation didn't turn up many reliable use cases for doing this, so we can probably hold off until we have a motivating example.

@flaub
Copy link
Contributor

flaub commented May 14, 2015

In my experience, simply closing the fd/handle of the socket is enough to cause blocking recv calls to return with a failure (which is different on each platform). This implies that a UdpSocket might be in a state of Active vs Inactive depending on whether the fd has been closed or not. This is essential for being able to cancel pending recv calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

6 participants