Closed VioletEternity closed 1 year ago
The combination of SO_REUSEADDR
and SO_EXCLUSIVEADDRUSE
on Windows has WSABind return a WSAEINVAL
error. Ideally, Reticulum would probe for a running shared instance by attempting to connect to it rather than attempting to bind, but this PR is a much simpler change that fixes the immediate issue of not being able to use most of the functionality of RNS with RNodes (which relies on being able to use a shared instance).
Thank you very much for this contribution!
On Linux, SO_REUSEADDR is used so that a socket in TIME-WAIT state can be rebound after a listening process is restarted. It does not allow two processes to listen on the exact same (addr, port) combination. However, on Windows, it does, and SO_EXCLUSIVEADDRUSE is required to reproduce the Linux behavior.
Reticulum relies on an error being returned by bind() that reuses the same (addr, port) combination as another process to detect whether there is a shared instance already running. Setting SO_EXCLUSIVEADDRUSE makes this detection process work on Windows as well.