[Python-checkins] bpo-39148: enable ipv6 for datagrams in Proactor (GH-19121)

Kjell Braden webhook-mailer at python.org
Mon May 18 02:21:42 EDT 2020


https://github.com/python/cpython/commit/442634c42fcaf31c636f693951a97734042c3e7b
commit: 442634c42fcaf31c636f693951a97734042c3e7b
branch: master
author: Kjell Braden <afflux at pentabarf.de>
committer: GitHub <noreply at github.com>
date: 2020-05-17T23:21:30-07:00
summary:

bpo-39148: enable ipv6 for datagrams in Proactor (GH-19121)



Ifdef is not necessary, as AF_INET6 is supported from Windows Vista, and other code in overlapped.c uses AF_INET6 and is not ifdef'd.
Change the raised exception so users are not fooled to think it comes from Windows API.

Automerge-Triggered-By: @njsmith

files:
A Misc/NEWS.d/next/Windows/2020-03-23-19-07-55.bpo-39148.W1YJEb.rst
M Lib/test/test_asyncio/test_events.py
M Modules/overlapped.c

diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index aa4daca0e4e03..573df2d765887 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -1208,7 +1208,7 @@ def test_server_close(self):
             ConnectionRefusedError, client.connect, ('127.0.0.1', port))
         client.close()
 
-    def test_create_datagram_endpoint(self):
+    def _test_create_datagram_endpoint(self, local_addr, family):
         class TestMyDatagramProto(MyDatagramProto):
             def __init__(inner_self):
                 super().__init__(loop=self.loop)
@@ -1218,9 +1218,11 @@ def datagram_received(self, data, addr):
                 self.transport.sendto(b'resp:'+data, addr)
 
         coro = self.loop.create_datagram_endpoint(
-            TestMyDatagramProto, local_addr=('127.0.0.1', 0))
+            TestMyDatagramProto, local_addr=local_addr, family=family)
         s_transport, server = self.loop.run_until_complete(coro)
-        host, port = s_transport.get_extra_info('sockname')
+        sockname = s_transport.get_extra_info('sockname')
+        host, port = socket.getnameinfo(
+            sockname, socket.NI_NUMERICHOST|socket.NI_NUMERICSERV)
 
         self.assertIsInstance(s_transport, asyncio.Transport)
         self.assertIsInstance(server, TestMyDatagramProto)
@@ -1254,6 +1256,13 @@ def datagram_received(self, data, addr):
         self.assertEqual('CLOSED', client.state)
         server.transport.close()
 
+    def test_create_datagram_endpoint(self):
+        self._test_create_datagram_endpoint(('127.0.0.1', 0), socket.AF_INET)
+
+    @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 not supported or enabled')
+    def test_create_datagram_endpoint_ipv6(self):
+        self._test_create_datagram_endpoint(('::1', 0), socket.AF_INET6)
+
     def test_create_datagram_endpoint_sock(self):
         sock = None
         local_address = ('127.0.0.1', 0)
diff --git a/Misc/NEWS.d/next/Windows/2020-03-23-19-07-55.bpo-39148.W1YJEb.rst b/Misc/NEWS.d/next/Windows/2020-03-23-19-07-55.bpo-39148.W1YJEb.rst
new file mode 100644
index 0000000000000..7c70dce1e7333
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2020-03-23-19-07-55.bpo-39148.W1YJEb.rst
@@ -0,0 +1,3 @@
+Add IPv6 support to :mod:`asyncio` datagram endpoints in ProactorEventLoop.
+Change the raised exception for unknown address families to ValueError
+as it's not coming from Windows API.
diff --git a/Modules/overlapped.c b/Modules/overlapped.c
index a16797c47b5d6..df6282cba819b 100644
--- a/Modules/overlapped.c
+++ b/Modules/overlapped.c
@@ -670,7 +670,6 @@ make_ipv4_addr(const struct sockaddr_in *addr)
         return PyUnicode_FromString(buf);
 }
 
-#ifdef ENABLE_IPV6
 /* Convert IPv6 sockaddr to a Python str. */
 
 static PyObject *
@@ -683,7 +682,6 @@ make_ipv6_addr(const struct sockaddr_in6 *addr)
         }
         return PyUnicode_FromString(buf);
 }
-#endif
 
 static PyObject*
 unparse_address(LPSOCKADDR Address, DWORD Length)
@@ -701,7 +699,6 @@ unparse_address(LPSOCKADDR Address, DWORD Length)
             }
             return ret;
         }
-#ifdef ENABLE_IPV6
         case AF_INET6: {
             const struct sockaddr_in6 *a = (const struct sockaddr_in6 *)Address;
             PyObject *addrobj = make_ipv6_addr(a);
@@ -716,9 +713,9 @@ unparse_address(LPSOCKADDR Address, DWORD Length)
             }
             return ret;
         }
-#endif /* ENABLE_IPV6 */
         default: {
-            return SetFromWindowsErr(ERROR_INVALID_PARAMETER);
+            PyErr_SetString(PyExc_ValueError, "recvfrom returned unsupported address family");
+            return NULL;
         }
     }
 }



More information about the Python-checkins mailing list