Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
bpo-17561: add socket.create_server_sock() and socket.has_dual_stack() #11215
I'm not sure if this is a good idea. For users who don't understand all the intricacies of BSD sockets and IPv4/IPv6, dual-protocol sockets are kind of confusing. People expect them to handle IPv4 connections like IPv4 connections, but in fact they convert IPv4 connections into "virtual" IPv6 connections. This can be especially problematic when porting legacy IPv4-only code. For example, right now,
It does this by using
This is surprising and confusing (and in the case of
I think this is why tornado/asyncio/trio all make a special effort to disable the dual-protocol mode, and instead handle dual-stack servers by opening multiple single-protocol sockets.
OTOH, for people who do understand the intricacies of BSD sockets and IPv4/IPv6, a helper is not really needed... and if you want to use the socket API directly you kind of have to know a lot of obscure intricacies.
I'm not like, massively opposed. If it's merged I'll just ignore it and it won't hurt me :-).
If you do go ahead, the docs definitely need to highlight this issue, because otherwise you're going to get complaints from confused users.
That's a good point which I didn't consider. I guess that invalidates my original idea of indiscriminately using this function in other parts of the stdlib, like the
def create_server_sock(address, family=AF_UNSPEC, type=SOCK_STREAM, *, reuse_addr=os.name == 'posix' and sys.platform != 'cygwin', reuse_port=False, backlog=100, hybrid_v46=False):
Note: if family is AF_UNSPEC or None it will be determined from
It probably also makes sense to rename
I wouldn't expose any option for controlling this.
The right way to do it is: