-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Set SO_REUSEADDR by default in libnative. #11845
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This should also fix the rust-http libnative thingy. cc @alexcrichton |
According to this description I'd be wary of setting this option on windows as well. It looks like SO_REUSEADDR on windows essentially steals ports from any other application, which seems bad. Otherwise, my current understanding of SO_REUSEADDR for tcp sockets is such that this is a good thing. Taking notes out of libuv's book, it looks like we don't need to do much on windows at all, so I think it's fine to wrap this in a Additionally, I don't think that we should ignore the error from the Thanks for doing this! |
@@ -96,7 +96,10 @@ fn socket(addr: ip::SocketAddr, ty: libc::c_int) -> IoResult<sock_t> { | |||
}; | |||
match libc::socket(fam, ty, 0) { | |||
-1 => Err(super::last_error()), | |||
fd => Ok(fd), | |||
fd => { | |||
setsockopt(fd, libc::SOL_SOCKET, libc::SO_REUSEADDR, 1 as libc::c_int); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code path is executed by both clients (connect
) and servers (bind
), but I think that we only want this as part of bind
, could you move the logic into the bind
function of the TcpListener
?
Fixes std::net test error when re-running too quickly.
I thought that the proper way of avoiding "address already in use" error is to disconnect gracefully:
See e.g. http://hea-www.harvard.edu/~fine/Tech/addrinuse.html |
This doesn't help for rust-http or some other use cases where the process On Tue, Jan 28, 2014 at 3:28 AM, Vadim Chugunov notifications@github.heygears.comwrote:
|
This may be appropriate for some apps, but just setting it by default seems... a bit dubious. |
For now I'd like to explore this route rather than using Also, @xales, feel free to comment on PRs when you force-push update them. Sadly github doesn't send out any notifications on a force-push. |
Fixes std::net test error when re-running too quickly. Suggested by @cmr
…ion-extension, r=flip1995 Extend `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)` Fixes rust-lang/rust-clippy#10365. As indicated in the title, it extends the `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)`. changelog: extension of the `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)` r? `@blyxyas`
Fixes std::net test error when re-running too quickly.
Suggested by @cmr