cpython: 5e7e9b131904 (original) (raw)

Mercurial > cpython

changeset 98539:5e7e9b131904 3.4

Issue #23972: updates to asyncio datagram API. By Chris Laws. [#23972]

Guido van Rossum guido@python.org
date Mon, 05 Oct 2015 09:15:28 -0700
parents 233974dfda03
children ba956289fe66 54c77fdcdb2e
files Doc/library/asyncio-eventloop.rst Lib/asyncio/base_events.py Lib/asyncio/events.py Lib/test/test_asyncio/test_base_events.py Lib/test/test_asyncio/test_events.py Misc/ACKS Misc/NEWS
diffstat 7 files changed, 380 insertions(+), 69 deletions(-)[+] [-] Doc/library/asyncio-eventloop.rst 46 Lib/asyncio/base_events.py 164 Lib/asyncio/events.py 40 Lib/test/test_asyncio/test_base_events.py 140 Lib/test/test_asyncio/test_events.py 52 Misc/ACKS 1 Misc/NEWS 6

line wrap: on

line diff

--- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -283,17 +283,50 @@ Creating connections (:class:StreamReader, :class:StreamWriter) instead of a protocol. -.. coroutinemethod:: BaseEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, *, family=0, proto=0, flags=0) +.. coroutinemethod:: BaseEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, *, family=0, proto=0, flags=0, reuse_address=None, reuse_port=None, allow_broadcast=None, sock=None) Create datagram connection: socket family :py:data:~socket.AF_INET or :py:data:~socket.AF_INET6 depending on host (or family if specified),

+

+

+

+

+

+

On Windows with :class:ProactorEventLoop, this method is not supported. @@ -320,7 +353,7 @@ Creating connections Creating listening connections ------------------------------ -.. coroutinemethod:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, *, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None) +.. coroutinemethod:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, *, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None, reuse_port=None) Create a TCP server (socket type :data:~socket.SOCK_STREAM) bound to host and port. @@ -359,6 +392,11 @@ Creating listening connections expire. If not specified will automatically be set to True on UNIX.

+ This method is a :ref:coroutine <coroutine>. On Windows with :class:ProactorEventLoop, SSL/TLS is not supported.

--- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -700,75 +700,109 @@ class BaseEventLoop(events.AbstractEvent @coroutine def create_datagram_endpoint(self, protocol_factory, local_addr=None, remote_addr=None, *,

-

-

+

+

+

protocol = protocol_factory() waiter = futures.Future(loop=self)

@@ -804,7 +838,8 @@ class BaseEventLoop(events.AbstractEvent sock=None, backlog=100, ssl=None,

The host parameter can be a string, in that case the TCP server is bound @@ -857,8 +892,15 @@ class BaseEventLoop(events.AbstractEvent continue sockets.append(sock) if reuse_address:

--- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -297,7 +297,8 @@ class AbstractEventLoop: def create_server(self, protocol_factory, host=None, port=None, *, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE,

The return value is a Server object which can be used to stop @@ -327,6 +328,11 @@ class AbstractEventLoop: TIME_WAIT state, without waiting for its natural timeout to expire. If not specified will automatically be set to True on UNIX. +

@@ -358,7 +364,37 @@ class AbstractEventLoop: def create_datagram_endpoint(self, protocol_factory, local_addr=None, remote_addr=None, *,

+

+

+

+

+

+

+

# Pipes and subprocesses.

--- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -3,6 +3,7 @@ import errno import logging import math +import os import socket import sys import threading @@ -790,11 +791,11 @@ class MyProto(asyncio.Protocol): class MyDatagramProto(asyncio.DatagramProtocol): done = None

def connection_made(self, transport): self.transport = transport @@ -1100,6 +1101,19 @@ class BaseEventLoopWithSelectorTests(tes self.assertRaises(OSError, self.loop.run_until_complete, f) @mock.patch('asyncio.base_events.socket')

+

+

+

@@ -1199,6 +1213,128 @@ class BaseEventLoopWithSelectorTests(tes self.assertRaises(Err, self.loop.run_until_complete, fut) self.assertTrue(m_sock.close.called)

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+ def test_accept_connection_retry(self): sock = mock.Mock() sock.accept.side_effect = BlockingIOError()

--- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -814,6 +814,32 @@ class EventLoopTestsMixin: # close server server.close()

+

+

+ def _make_unix_server(self, factory, **kwargs): path = test_utils.gen_unix_socket_path() self.addCleanup(lambda: os.path.exists(path) and os.unlink(path)) @@ -1264,6 +1290,32 @@ class EventLoopTestsMixin: self.assertEqual('CLOSED', client.state) server.transport.close()

+

+ def test_internal_fds(self): loop = self.create_event_loop() if not isinstance(loop, selector_events.BaseSelectorEventLoop):

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -789,6 +789,7 @@ Ben Laurie Simon Law Julia Lawall Chris Lawrence +Chris Laws Brian Leair Mathieu Leduc-Hamel Amandine Lee

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -90,6 +90,12 @@ Core and Builtins Library ------- +- Issue #23972: Updates asyncio datagram create method allowing reuseport