diff options
| author | Markus Reiter <me@reitermark.us> | 2020-05-02 07:05:22 +0200 |
|---|---|---|
| committer | Markus Reiter <me@reitermark.us> | 2020-05-02 17:06:16 +0200 |
| commit | 39a97900bee062b020c93e995c3b48b48d335bf2 (patch) | |
| tree | 055e2adc1fc05191fdc56d6bdcf9903c54b0018a /src/libstd/sys_common | |
| parent | 7184d137f65bb8d143ce8b5b664e50d33c4b5fbd (diff) | |
| download | rust-39a97900bee062b020c93e995c3b48b48d335bf2.tar.gz rust-39a97900bee062b020c93e995c3b48b48d335bf2.zip | |
Replace `cfg` macro with attribute.
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(); |
