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

Disable NetSocket reuse address on Windows. #36321

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions drivers/unix/net_socket_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,22 +673,29 @@ void NetSocketPosix::set_tcp_no_delay_enabled(bool p_enabled) {
void NetSocketPosix::set_reuse_address_enabled(bool p_enabled) {
ERR_FAIL_COND(!is_open());

// On Windows, enabling SO_REUSEADDR actually would also enable reuse port, very bad on TCP. Denying...
// Windows does not have this option, SO_REUSEADDR in this magical world means SO_REUSEPORT
#ifndef WINDOWS_ENABLED
if (_is_stream)
return;
int par = p_enabled ? 1 : 0;
if (setsockopt(_sock, SOL_SOCKET, SO_REUSEADDR, SOCK_CBUF(&par), sizeof(int)) < 0) {
WARN_PRINT("Unable to set socket REUSEADDR option!");
}
#endif
}

void NetSocketPosix::set_reuse_port_enabled(bool p_enabled) {
// Windows does not have this option, as it is always ON when setting REUSEADDR.
#ifndef WINDOWS_ENABLED
ERR_FAIL_COND(!is_open());

// See comment above...
#ifdef WINDOWS_ENABLED
#define SO_REUSEPORT SO_REUSEADDR
#endif
int par = p_enabled ? 1 : 0;
if (setsockopt(_sock, SOL_SOCKET, SO_REUSEPORT, SOCK_CBUF(&par), sizeof(int)) < 0) {
WARN_PRINT("Unable to set socket REUSEPORT option!");
}
#endif
}

bool NetSocketPosix::is_open() const {
Expand Down