diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2011-04-25 02:25:54 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2011-04-25 02:25:54 +0000 |
commit | dbf00133f517e3f90d70403822f563f924dd5f06 (patch) | |
tree | fadb9d1d24d79f114daa8b03aa93f0fcde748efb | |
parent | 5d04005468f7eafed0b1c78dfb8495225e96f4ad (diff) | |
download | pyserial-dbf00133f517e3f90d70403822f563f924dd5f06.tar.gz |
fix for SF 3245627 (read loop hangs on lost connection), fix some doc typos, add debug logs
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@399 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r-- | CHANGES.txt | 1 | ||||
-rw-r--r-- | serial/rfc2217.py | 21 |
2 files changed, 13 insertions, 9 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index bb06f90..c4b2cca 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -412,3 +412,4 @@ New Features: Bugfixes: - [SF 3093882] calling open() on an already open port now raises an exception +- [SF 3245627] connection-lost let rfc2217 hangs in closed loop diff --git a/serial/rfc2217.py b/serial/rfc2217.py index 28cbc6a..3d05a85 100644 --- a/serial/rfc2217.py +++ b/serial/rfc2217.py @@ -402,7 +402,7 @@ class RFC2217Serial(SerialBase): 'parity': TelnetSubnegotiation(self, 'parity', SET_PARITY, SERVER_SET_PARITY), 'stopsize': TelnetSubnegotiation(self, 'stopsize', SET_STOPSIZE, SERVER_SET_STOPSIZE), } - # There are more subnegotiation object, combine all in one dictionary + # There are more subnegotiation objects, combine all in one dictionary # for easy access self._rfc2217_options = { 'purge': TelnetSubnegotiation(self, 'purge', PURGE_DATA, SERVER_PURGE_DATA), @@ -577,7 +577,7 @@ class RFC2217Serial(SerialBase): try: self._socket.sendall(data.replace(IAC, IAC_DOUBLED)) except socket.error, e: - raise SerialException("socket connection failed: %s" % e) # XXX what exception if socket connection fails + raise SerialException("connection failed (socket error): %s" % e) # XXX what exception if socket connection fails finally: self._write_lock.release() return len(data) @@ -672,9 +672,12 @@ class RFC2217Serial(SerialBase): # just need to get out of recv form time to time to check if # still alive continue - except socket.error: + except socket.error, e: # connection fails -> terminate loop + if self.logger: + self.logger.debug("socket error in reader thread: %s" % (e,)) break + if not data: break # lost connection for byte in data: if mode == M_NORMAL: # interpret as command or as data @@ -805,10 +808,10 @@ class RFC2217Serial(SerialBase): def rfc2217SetControl(self, value): item = self._rfc2217_options['control'] - item.set(value) # transmit desired purge type + item.set(value) # transmit desired control type if self._ignore_set_control_answer: # answers are ignored when option is set. compatibility mode for - # servers that answers, but not the expected ones... (or no answer + # servers that answer, but not the expected one... (or no answer # at all) i.e. sredird time.sleep(0.1) # this helps getting the unit tests passed else: @@ -873,7 +876,7 @@ else: class PortManager(object): """This class manages the state of Telnet and RFC 2217. It needs a serial - instance and a connection to work with. connection is expected to implement + instance and a connection to work with. Connection is expected to implement a (thread safe) write function, that writes the string to the network.""" def __init__(self, serial_port, connection, logger=None): @@ -976,9 +979,9 @@ class PortManager(object): # - outgoing data escaping def escape(self, data): - """this function is for the user. all outgoing data has to be properly - escaped, so that no IAC character in the data stream messes up the - Telnet state machine in the server. + """this generator function is for the user. all outgoing data has to be + properly escaped, so that no IAC character in the data stream messes up + the Telnet state machine in the server. socket.sendall(escape(data)) """ |