Hi,
I was wondering about the ListenTCP method call with automatic port selection. If I set the port to 0, the OS will pick one at random, which we can query from the listener socket (i.e. sock.Addr.(*net.TCPAddr).Port).
Wouldn't a nicer design be to update the argument passed to listen with the port number (it it's a pointer anyway)?
I.e. doing this internally inside the listen method:
sock, err := ListenTCP(addr)
addr.Port = sock.Addr.(*net.TCPAddr).Port
The benefit would be that wrapping the listen in a higher level protocol wouldn't require bubbling up the port number with a different mechanism. Am I missing a reason why the original address shouldn't change? The only point in keeping the original 0 is to have multiple listen calls with the same struct, but I'd say that's the exception and not the general rule.
So, what are your takes on this? :)
Cheers,
Peter