Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Transport.resume_reading() and pause_reading() idempotent. Add is_reading(). #117

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,15 @@ async def test_client(addr):
t.set_protocol(p)

self.assertFalse(t._paused)
self.assertTrue(t.is_reading())
t.pause_reading()
t.pause_reading() # Check that it's OK to call it 2nd time.
self.assertTrue(t._paused)
self.assertFalse(t.is_reading())
t.resume_reading()
t.resume_reading() # Check that it's OK to call it 2nd time.
self.assertFalse(t._paused)
self.assertTrue(t.is_reading())

sock = t.get_extra_info('socket')
self.assertIs(sock, t.get_extra_info('socket'))
Expand Down Expand Up @@ -580,6 +585,12 @@ async def test_client(addr):
t.abort()
self.assertTrue(t._closing)

self.assertFalse(t.is_reading())
# Check that pause_reading and resume_reading don't raise
# errors if called after the transport is closed.
t.pause_reading()
t.resume_reading()

await fut

# Test that peername and sockname are available after
Expand Down
17 changes: 6 additions & 11 deletions uvloop/handles/stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -664,21 +664,16 @@ cdef class UVStream(UVBaseTransport):
def can_write_eof(self):
return True

def pause_reading(self):
self._ensure_alive()
def is_reading(self):
return self._is_reading()

if self._closing:
raise RuntimeError('Cannot pause_reading() when closing')
if not self._is_reading():
raise RuntimeError('Already paused')
def pause_reading(self):
if self._closing or not self._is_reading():
return
self._stop_reading()

def resume_reading(self):
self._ensure_alive()

if self._is_reading():
raise RuntimeError('Not paused')
if self._closing:
if self._is_reading() or self._closing:
return
self._start_reading()

Expand Down