def get_write_buffer_size(self):
return len(self._buffer)
+ def _add_reader(self, fd, callback, *args):
+ if self._closing:
+ return
+
+ self._loop._add_reader(fd, callback, *args)
+
class _SelectorSocketTransport(_SelectorTransport):
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,
+ self._loop.call_soon(self._add_reader,
self._sock_fd, self._read_ready)
if waiter is not None:
# only wake up the waiter when connection_made() has been called
if self._closing or not self._paused:
return
self._paused = False
- self._loop._add_reader(self._sock_fd, self._read_ready)
+ self._add_reader(self._sock_fd, self._read_ready)
if self._loop.get_debug():
logger.debug("%r resumes reading", self)
self._address = address
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,
+ self._loop.call_soon(self._add_reader,
self._sock_fd, self._read_ready)
if waiter is not None:
# only wake up the waiter when connection_made() has been called
self.assertIsNone(tr._protocol)
self.assertIsNone(tr._loop)
+ def test__add_reader(self):
+ tr = self.create_transport()
+ tr._buffer.extend(b'1')
+ tr._add_reader(7, mock.sentinel)
+ self.assertTrue(self.loop.readers)
+
+ tr._force_close(None)
+
+ self.assertTrue(tr.is_closing())
+ self.assertFalse(self.loop.readers)
+
+ # can not add readers after closing
+ tr._add_reader(7, mock.sentinel)
+ self.assertFalse(self.loop.readers)
+
class SelectorSocketTransportTests(test_utils.TestCase):