SO_REUSEADDR
Alan Bateman
Alan.Bateman at oracle.com
Wed Nov 11 11:20:50 UTC 2020
On 11/11/2020 10:14, Simone Bordet wrote:
> Hi,
>
> the javadocs for SocketOptions.SO_REUSEADDR states that: "This is used
> only for MulticastSockets in java".
>
> However, the javadocs for ServerSocket.setReuseAddress(boolean) goes a
> great length explaining a behavior that applies to TCP sockets
> (referencing SocketOptions.SO_REUSEADDR).
>
> Similarly, the javadocs for SocketOptions.SO_REUSEPORT states: "This
> option enables and disables the ability to have multiple sockets
> listen to the same address and port."
> This seems to apply to listening sockets only, but then it says that
> it is valid for SocketImpl (not ServerSocketImpl).
>
> Can this be clarified?
>
java.net.StandardSocketOptions is the "user facing API" that has clear
descriptions of the standard socket options. That's the place to read
about SO_REUSEADDR and SO_REUSEPORT.
java.net.SocketOptions is a legacy JDK 1.1 interface for the underlying
socket implementations (SocketImpl, DatagramSocketImpl). It's really SPI
rather than API and you shouldn't find any usages in any of the APIs.
So yes, there is technical debt here and ideally there would be pass
done over Socket and ServerSocket to change the links. It might also be
useful to put text in the SocketOptions class description to redirect
people to StandardSocketOptions.
-Alan
More information about the net-dev
mailing list