Skip to content

Conversation

@not-my-username
Copy link
Contributor

Allows setting the SO_REUSEADDR and SO_REUSEPORT option on the underlying socket when using PacketPeerUDP.

See godotengine/godot-proposals#13519 for details.

See it in action: https://github.com/not-my-username/UdpMulticastDiscoveryDemo

<param index="0" name="reuse_port" type="bool" />
<description>
Enable or disable [code]SO_REUSEPORT[/code] on the underlying socket. This option is disabled by default.
[b]Note:[/b] Not supported on Windows, use [method set_reuse_address_enabled] instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it supported on every other platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on MacOS and Linux. In theory IOS and Android should work, however they may need some permission set. Then again due to the nature of mobile oprating system, it would be unlikely you would be able / need to run 2 instances of the same godot project at the same time

Comment on lines +552 to +556
int par = p_enabled ? 1 : 0;
if (setsockopt(_sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&par, sizeof(int)) < 0) {
WARN_PRINT("Unable to set socket REUSEADDR option.");
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Since it was deliberately disabled and SO_REUSEADDR act like SO_REUSEPORT on Windows, it might be better to keep set_reuse_address_enabled as NOP and move this to set_reuse_port_enabled. To keep existing behavior intact.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. From doing a global search in the code base. The only times NetSocketWinSock::set_reuse_address_enabled is called is in /core/io/udp_server.cpp and /core/io/tcp_server.cpp on lines 109 and 56 respectively.

From my research I don't believe it would cause any issues with existing behavior. Then again i try to stay away from Windows as a whole, so im no expert.

Ill push a new commit that moves the logic into set_reuse_port_enabled and keep set_reuse_address_enabled as a NOP like it originally was

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants