diff options
author | Guido van Rossum <guido@dropbox.com> | 2016-08-31 16:47:08 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@dropbox.com> | 2016-08-31 16:47:08 (GMT) |
commit | 898ac56fc2667af051b739cdbc2f8aba97ebf09c (patch) | |
tree | 356a225b18a40ccc2124461a4fd75c8d187b1993 /Lib/asyncio | |
parent | 7309421502a7c5e98a228c2e4a43d242c0eb91ea (diff) | |
parent | 4786787c07ba660c62a233ebfd16a8fcebc1c13e (diff) | |
download | cpython-898ac56fc2667af051b739cdbc2f8aba97ebf09c.zip cpython-898ac56fc2667af051b739cdbc2f8aba97ebf09c.tar.gz cpython-898ac56fc2667af051b739cdbc2f8aba97ebf09c.tar.bz2 |
Merge asyncio from 3.5
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/unix_events.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index ce49c4f..d183f60 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, @@ -422,25 +428,30 @@ 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_socket or - stat.S_ISFIFO(mode) or - stat.S_ISCHR(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) # On AIX, the reader trick (to be notified when the read end of the # socket is closed) only works for sockets. On other platforms it # works for pipes and sockets. (Exception: OS X 10.4? Issue #19294.) - if is_socket or not sys.platform.startswith("aix"): + if is_socket or (is_fifo and not sys.platform.startswith("aix")): # only start reading when connection_made() has been called self._loop.call_soon(self._loop.add_reader, self._fileno, self._read_ready) |