diff options
| author | bors <bors@rust-lang.org> | 2020-05-02 23:35:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-05-02 23:35:09 +0000 |
| commit | c1e05528696ca523055b0f7ce94b8033dcbaa39e (patch) | |
| tree | 5ef41fa793e67902ae17dfc43fb52756b5000cbf /src/libstd/sys_common | |
| parent | f05a5240440b3eaef1684a7965860fab40301947 (diff) | |
| parent | 97cf378f543813aeb3a87551915737a136d64aec (diff) | |
| download | rust-c1e05528696ca523055b0f7ce94b8033dcbaa39e.tar.gz rust-c1e05528696ca523055b0f7ce94b8033dcbaa39e.zip | |
Auto merge of #71807 - Dylan-DPC:rollup-jvb8sd9, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #69274 (Implement RFC 2396: `#[target_feature]` 1.1) - #71767 (doc: make Stack and StackElement a little pretty) - #71772 (Mark query function as must_use.) - #71777 (cleanup: `config::CrateType` -> `CrateType`) - #71784 (Remove recommendation for unmaintained dirs crate) - #71785 (Update comment regarding SO_REUSEADDR on Windows) - #71787 (fix rustdoc warnings) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/net.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index a9b6079de75..1c03bc92344 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -368,12 +368,15 @@ impl TcpListener { let sock = Socket::new(addr, c::SOCK_STREAM)?; - // On platforms with Berkeley-derived sockets, this allows - // to quickly rebind a socket, without needing to wait for - // the OS to clean up the previous one. - if !cfg!(windows) { - setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, 1 as c_int)?; - } + // On platforms with Berkeley-derived sockets, this allows to quickly + // rebind a socket, without needing to wait for the OS to clean up the + // previous one. + // + // On Windows, this allows rebinding sockets which are actively in use, + // which allows “socket hijacking”, so we explicitly don't set it here. + // https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse + #[cfg(not(windows))] + setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, 1 as c_int)?; // Bind our new socket let (addrp, len) = addr.into_inner(); |
