diff options
author | Victor Stinner <vstinner@redhat.com> | 2015-07-20 17:18:59 +0200 |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2015-07-20 17:36:41 +0200 |
commit | 13b71a16ee9d5af4939a7e214e92fa89cb96f6a3 (patch) | |
tree | cb9525ce018206804591e7e255c5745a044018c6 /asyncio/streams.py | |
parent | 9bb67431adc916d9d4b4e23ca257658c980d035d (diff) | |
download | trollius-git-closing.tar.gz |
Add closing read-only property to transportsclosing
* Disallow write() on closing transports
* Disallow aslo calling pause_writing() and resume_writing() on
StreamReaderProtocol if the transport is closing
Diffstat (limited to 'asyncio/streams.py')
-rw-r--r-- | asyncio/streams.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/asyncio/streams.py b/asyncio/streams.py index 6484c43..409b2f9 100644 --- a/asyncio/streams.py +++ b/asyncio/streams.py @@ -153,15 +153,25 @@ class FlowControlMixin(protocols.Protocol): self._paused = False self._drain_waiter = None self._connection_lost = False + self._transport = None + + def connection_made(self, transport): + self._transport = transport def pause_writing(self): assert not self._paused + if self._transport is not None and self._transport.closing: + raise RuntimeError('Cannot call pause_writing() ' + 'on closing or closed transport') self._paused = True if self._loop.get_debug(): logger.debug("%r pauses writing", self) def resume_writing(self): assert self._paused + if self._transport is not None and self._transport.closing: + raise RuntimeError('Cannot call resume_writing() ' + 'on closing or closed transport') self._paused = False if self._loop.get_debug(): logger.debug("%r resumes writing", self) @@ -217,6 +227,7 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol): self._client_connected_cb = client_connected_cb def connection_made(self, transport): + super().connection_made(transport) self._stream_reader.set_transport(transport) if self._client_connected_cb is not None: self._stream_writer = StreamWriter(transport, self, |