mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
Issue #7322: Trying to read from a socket's file-like object after a timeout
occurred now raises an error instead of silently losing data. Patch by Ross Lagerwall.
This commit is contained in:
parent
fc1cf41911
commit
68e5c044e8
3 changed files with 26 additions and 0 deletions
|
@ -257,6 +257,7 @@ class SocketIO(io.RawIOBase):
|
|||
self._mode = mode
|
||||
self._reading = "r" in mode
|
||||
self._writing = "w" in mode
|
||||
self._timeout_occurred = False
|
||||
|
||||
def readinto(self, b):
|
||||
"""Read up to len(b) bytes into the writable buffer *b* and return
|
||||
|
@ -268,9 +269,14 @@ class SocketIO(io.RawIOBase):
|
|||
"""
|
||||
self._checkClosed()
|
||||
self._checkReadable()
|
||||
if self._timeout_occurred:
|
||||
raise IOError("cannot read from timed out object")
|
||||
while True:
|
||||
try:
|
||||
return self._sock.recv_into(b)
|
||||
except timeout:
|
||||
self._timeout_occurred = True
|
||||
raise
|
||||
except error as e:
|
||||
n = e.args[0]
|
||||
if n == EINTR:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue