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

Port/Address re-use #2011

Closed
Frank-Friemel opened this issue Dec 24, 2024 · 2 comments
Closed

Port/Address re-use #2011

Frank-Friemel opened this issue Dec 24, 2024 · 2 comments
Labels

Comments

@Frank-Friemel
Copy link

Frank-Friemel commented Dec 24, 2024

setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,

Hi, I think there is a bug in the above line. This does not work. The return value is -1. I guess because you've previously enabled address re-use. Just applying SO_EXCLUSIVEADDRUSE (without SO_REUSEADDR) works.

I mean ... what is the purpose at all? In the Linux path you enable address/port re-usage. And in the Win32 path you try to disable it by acquiring the port exclusively? Currently it's enabled for both platforms, because SO_EXCLUSIVEADDRUSE fails. I stumbled over this because for my project this behaviour was kind of unexpected. My expectation was that a port can only be bound by one application/process/thread.

@yhirose yhirose added the bug label Dec 27, 2024
@yhirose
Copy link
Owner

yhirose commented Dec 27, 2024

@Frank-Friemel thank you for the report. I'll take a look at it when I have time.

@yhirose
Copy link
Owner

yhirose commented Jan 17, 2025

@Frank-Friemel sorry for the delay. As you mentioned, there is inconsistency between the Windows implementation and others (Linux and macOS). I actually prefer 'address/port re-usage' over 'exclusive address usage'. As for Windows, it seems I misunderstood the WinSock spec. (#506 (comment))

So in order to make all the platform behaviors consistent, I am actually removing SO_EXCLUSIVEADDRUSE from the Windows implementation.

If you would like to have 'exclusive address usage', you can set the socket option to SO_EXCLUSIVEADDRUSE with Server::set_socket_options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants