diff --git a/telnetsrv/green.py b/telnetsrv/green.py index ae461c8..c5d79a8 100644 --- a/telnetsrv/green.py +++ b/telnetsrv/green.py @@ -34,10 +34,13 @@ def finish(self): def getc(self, block=True): """Return one character from the input queue""" - try: - return self.cookedq.get(block) - except gevent.queue.Empty: - return '' + while True: + try: + return self.cookedq.get(block, timeout = 10) + except gevent.queue.Empty: + if block and not self.eof: + continue + return '' def inputcooker_socket_ready(self): """Indicate that the socket is ready to be read""" diff --git a/telnetsrv/telnetsrvlib.py b/telnetsrv/telnetsrvlib.py index 2ed6a3f..148d727 100755 --- a/telnetsrv/telnetsrvlib.py +++ b/telnetsrv/telnetsrvlib.py @@ -524,7 +524,17 @@ def setup(self): def finish(self): "End this session" log.debug("Session disconnected.") - self.sock.shutdown(socket.SHUT_RDWR) + try: + self.sock.shutdown(socket.SHUT_RDWR) + except socket.error as e: + # on some systems shutdown fails with EINVAL. + # http://www.freebsd.org/cgi/query-pr.cgi?pr=31647 + import errno + if e.errno == errno.EINVAL: + pass + else: + raise + self.sock.close() self.session_end() def session_start(self): @@ -665,7 +675,8 @@ def readline(self, echo=None, prompt='', use_history=True): c = self.ansi_to_curses(c) if c == theNULL: continue - + elif c == '': + return 'QUIT' elif c == curses.KEY_LEFT: if insptr > 0: insptr = insptr - 1