<div dir="auto">Would it be possible to create a PyPI project to experiement the API and wait until we collected enough user feedback first?<div dir="auto"><br></div><div dir="auto">Currently socket is low level. Not sure if I like the idea of putting more high level features in it? Asyncio is a good place for high level features, but is limited to async programming.</div><div dir="auto"><br></div><div dir="auto">Victor</div></div><div class="gmail_extra"><br><div class="gmail_quote">Le 5 mars 2017 12:46, "Giampaolo Rodola'" <<a href="mailto:g.rodola@gmail.com">g.rodola@gmail.com</a>> a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Some years ago I started working on a patch for the socket module which added a couple of utility functions for being able to easily create a server socket, with the addition of being able to accept both IPv4 and IPv6 connections (as a single socket):<div><a href="https://bugs.python.org/issue17561" target="_blank">https://bugs.python.org/<wbr>issue17561</a></div><div><br></div><div>Given that not all OSes (Windows, many UNIXes) support this natively, I later submitted a recipe adding a "multiple socket listener" class.</div><div><a href="https://code.activestate.com/recipes/578504-server-supporting-ipv4-and-ipv6/" target="_blank">https://code.activestate.com/<wbr>recipes/578504-server-<wbr>supporting-ipv4-and-ipv6/</a><br></div><div><br></div><div>From the user perspective, the whole thing can be summarized as follows:</div><div><br></div><div><div>>>> sock = create_server_sock(("", 8000))</div><div>>>> if not has_dual_stack(sock):</div><div>... sock.close()</div><div>... sock = MultipleSocketsListener([("0.<wbr>0.0.0", 8000), ("::", 8000)])</div><div>>>></div></div><div><div><br></div><div>Part of this work ended up being included into Tulip internals:</div><div><a href="https://github.com/python/cpython/blob/70d28a184c42d107cc8c69a95aa52a4469e7929c/Lib/asyncio/base_events.py#L966-L1067" target="_blank">https://github.com/python/<wbr>cpython/blob/<wbr>70d28a184c42d107cc8c69a95aa52a<wbr>4469e7929c/Lib/asyncio/base_<wbr>events.py#L966-L1067</a></div><div>...and after that I basically forgot about the original patch. The other day I bumped into a case where I needed exactly this (on Windows), so here I am, trying to revamp the original proposal.</div><div><br></div><div>To be clear, the proposal is to add 3 new APIs in order to avoid the low-level cruft needed when creating a server socket (SO_REUSEADDR, getaddrinfo() etc.) </div><div>and being able to support IPv4/6 dual-stack socket servers in a cross-platform fashion:</div><div><br></div><div>- socket.has_dual_stack()</div><div>- socket.create_server_sock()<br></div><div>- socket.MultipleSocketsListener</div><div><br></div><div>Whereas the first two functions are relatively straightforward, MultipleSocketsListener is more debatable because, for instance, it's not clear what methods like getsockname() should return (because there are 2 sockets involved). One possible solution is to *not* expose such (all get*?) methods and simply expose the underlying socket objects as in:</div><div><br></div><div>>>> socket.<wbr>MultipleSocketsListener(...).<wbr>socks[0].getsockname() </div><div><br></div><div>On the other hand, all set* / write methods (setblocking(), setsockopt(), shutdown(), ...) can be exposed and internally they can simply operate against both sockets.</div><div><br></div><div>Thoughts?</div><div><br></div>-- <br><div class="m_8475259205230756984gmail_signature"><div dir="ltr"><div>Giampaolo - <a href="http://grodola.blogspot.com" target="_blank">http://grodola.blogspot.com</a></div><div><br></div></div></div>
</div></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br></blockquote></div></div>