summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2017-11-14 10:14:51 (GMT)
committerGitHub <noreply@github.com>2017-11-14 10:14:51 (GMT)
commitcc0961c517c31578f6a40a4dc7ea177d62c256b7 (patch)
treecd94f46d08231dabc271712e4cc35f6bebdc3dfc /Lib/asyncio
parent58cbae22930486814cc01cf9f981d9fe5e0c68f9 (diff)
downloadcpython-cc0961c517c31578f6a40a4dc7ea177d62c256b7.zip
cpython-cc0961c517c31578f6a40a4dc7ea177d62c256b7.tar.gz
cpython-cc0961c517c31578f6a40a4dc7ea177d62c256b7.tar.bz2
[3.6] bpo-32015: Asyncio looping during simultaneously socket read/write an… (GH-4386) (#4393)
* bpo-32015: Asyncio cycling during simultaneously socket read/write and reconnection * Tests fix * Tests fix * News add * Add new unit tests. (cherry picked from commit e1d62e0b7cc842d6b75b4d480391f4a94e503255)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/selector_events.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 9dbe550..942b627 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -363,25 +363,25 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
- self._sock_recv(fut, False, sock, n)
+ self._sock_recv(fut, None, sock, n)
return fut
- def _sock_recv(self, fut, registered, sock, n):
+ def _sock_recv(self, fut, registered_fd, sock, n):
# _sock_recv() can add itself as an I/O callback if the operation can't
# be done immediately. Don't use it directly, call sock_recv().
- fd = sock.fileno()
- if registered:
+ if registered_fd is not None:
# Remove the callback early. It should be rare that the
# selector says the fd is ready but the call still returns
# EAGAIN, and I am willing to take a hit in that case in
# order to simplify the common case.
- self.remove_reader(fd)
+ self.remove_reader(registered_fd)
if fut.cancelled():
return
try:
data = sock.recv(n)
except (BlockingIOError, InterruptedError):
- self.add_reader(fd, self._sock_recv, fut, True, sock, n)
+ fd = sock.fileno()
+ self.add_reader(fd, self._sock_recv, fut, fd, sock, n)
except Exception as exc:
fut.set_exception(exc)
else:
@@ -402,16 +402,14 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
if data:
- self._sock_sendall(fut, False, sock, data)
+ self._sock_sendall(fut, None, sock, data)
else:
fut.set_result(None)
return fut
- def _sock_sendall(self, fut, registered, sock, data):
- fd = sock.fileno()
-
- if registered:
- self.remove_writer(fd)
+ def _sock_sendall(self, fut, registered_fd, sock, data):
+ if registered_fd is not None:
+ self.remove_writer(registered_fd)
if fut.cancelled():
return
@@ -428,7 +426,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
else:
if n:
data = data[n:]
- self.add_writer(fd, self._sock_sendall, fut, True, sock, data)
+ fd = sock.fileno()
+ self.add_writer(fd, self._sock_sendall, fut, fd, sock, data)
@coroutine
def sock_connect(self, sock, address):