Skip to content

Commit

Permalink
socket: implement a functional a reset_input_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
zsquareplusc committed Dec 19, 2016
1 parent eb16326 commit 64d5992
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions serial/urlhandler/protocol_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,24 @@ def reset_input_buffer(self):
"""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):
"""\
Expand Down

0 comments on commit 64d5992

Please sign in to comment.