diff options
author | Guido van Rossum <guido@python.org> | 2016-08-31 16:42:38 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2016-08-31 16:42:38 (GMT) |
commit | 4786787c07ba660c62a233ebfd16a8fcebc1c13e (patch) | |
tree | 9a98f99c5a3c4d288da8672f518a071866f5f1d1 | |
parent | 8b7918a7e29b9043d6ed57e2ea799febaf2b9cc8 (diff) | |
download | cpython-4786787c07ba660c62a233ebfd16a8fcebc1c13e.zip cpython-4786787c07ba660c62a233ebfd16a8fcebc1c13e.tar.gz cpython-4786787c07ba660c62a233ebfd16a8fcebc1c13e.tar.bz2 |
Fix ordering issues in UNIX read/write pipe transport constructors.
Upstream https://github.com/python/asyncio/pull/408 by Ron Frederick.
-rw-r--r-- | Lib/asyncio/unix_events.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index f04d514..18519fc 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -305,14 +305,20 @@ class _UnixReadPipeTransport(transports.ReadTransport): self._loop = loop self._pipe = pipe self._fileno = pipe.fileno() + self._protocol = protocol + self._closing = False + mode = os.fstat(self._fileno).st_mode if not (stat.S_ISFIFO(mode) or stat.S_ISSOCK(mode) or stat.S_ISCHR(mode)): + self._pipe = None + self._fileno = None + self._protocol = None raise ValueError("Pipe transport is for pipes/sockets only.") + _set_nonblocking(self._fileno) - self._protocol = protocol - self._closing = False + self._loop.call_soon(self._protocol.connection_made, self) # only start reading when connection_made() has been called self._loop.call_soon(self._loop.add_reader, @@ -421,18 +427,23 @@ class _UnixWritePipeTransport(transports._FlowControlMixin, self._extra['pipe'] = pipe self._pipe = pipe self._fileno = pipe.fileno() + self._protocol = protocol + self._buffer = [] + self._conn_lost = 0 + self._closing = False # Set when close() or write_eof() called. + mode = os.fstat(self._fileno).st_mode is_char = stat.S_ISCHR(mode) is_fifo = stat.S_ISFIFO(mode) is_socket = stat.S_ISSOCK(mode) if not (is_char or is_fifo or is_socket): + self._pipe = None + self._fileno = None + self._protocol = None raise ValueError("Pipe transport is only for " "pipes, sockets and character devices") + _set_nonblocking(self._fileno) - self._protocol = protocol - self._buffer = [] - self._conn_lost = 0 - self._closing = False # Set when close() or write_eof() called. self._loop.call_soon(self._protocol.connection_made, self) |