Skip to content

Commit

Permalink
Merge pull request #305 from Mispel/master
Browse files Browse the repository at this point in the history
return b'' when connection closes on rfc2217 connection
  • Loading branch information
zsquareplusc committed May 7, 2018
2 parents 2f57d7d + ee70f44 commit 4a32be2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion serial/rfc2217.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,10 @@ def read(self, size=1):
while len(data) < size:
if self._thread is None:
raise SerialException('connection failed (reader thread died)')
data += self._read_buffer.get(True, timeout.time_left())
buf = self._read_buffer.get(True, timeout.time_left())
if buf is None:
return bytes(data)
data += buf
if timeout.expired():
break
except Queue.Empty: # -> timeout
Expand Down Expand Up @@ -738,8 +741,10 @@ def _telnet_read_loop(self):
# connection fails -> terminate loop
if self.logger:
self.logger.debug("socket error in reader thread: {}".format(e))
self._read_buffer.put(None)
break
if not data:
self._read_buffer.put(None)
break # lost connection
for byte in iterbytes(data):
if mode == M_NORMAL:
Expand Down

0 comments on commit 4a32be2

Please sign in to comment.