diff options
author | Chris Liechti <cliechti@gmx.net> | 2016-12-19 03:12:05 +0100 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2016-12-19 03:12:05 +0100 |
commit | 64d599251461da5cd1327407f1c6fbe8f4a6ff9c (patch) | |
tree | 0b76f1c53026da10f1b46e8eb546260065884eed | |
parent | eb1632634d34ae3ed24e8ce227b25751eb44a8e4 (diff) | |
download | pyserial-git-64d599251461da5cd1327407f1c6fbe8f4a6ff9c.tar.gz |
socket: implement a functional a reset_input_buffer
-rw-r--r-- | serial/urlhandler/protocol_socket.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/serial/urlhandler/protocol_socket.py b/serial/urlhandler/protocol_socket.py index 80c4ea9..a35cf75 100644 --- a/serial/urlhandler/protocol_socket.py +++ b/serial/urlhandler/protocol_socket.py @@ -232,8 +232,24 @@ class Serial(SerialBase): """Clear input buffer, discarding all that is in the buffer.""" if not self.is_open: raise portNotOpenError - if self.logger: - self.logger.info('ignored reset_input_buffer') + + # just use recv to remove input, while there is some + ready = True + while ready: + ready, _, _ = select.select([self._socket], [], [], 0) + try: + self._socket.recv(4096) + except OSError as e: + # this is for Python 3.x where select.error is a subclass of + # OSError ignore EAGAIN errors. all other errors are shown + if e.errno != errno.EAGAIN: + raise SerialException('reset_input_buffer failed: {}'.format(e)) + except (select.error, socket.error) as e: + # this is for Python 2.x + # ignore EAGAIN errors. all other errors are shown + # see also http://www.python.org/dev/peps/pep-3151/#select + if e[0] != errno.EAGAIN: + raise SerialException('reset_input_buffer failed: {}'.format(e)) def reset_output_buffer(self): """\ |