From e7a45fee600489abdfe171cde7d393ad1b308af4 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Fri, 2 Dec 2005 12:42:42 -0800 Subject: [PATCH] [project @ robey@lag.net-20051202204242-1fb4a6438ba50969] nail down select() on EOF: occasionally a channel would be closed remotely but select() wouldn't trigger. when a channel gets EOF or is closed, set the pipe FOREVER. --- paramiko/channel.py | 4 +++- paramiko/pipe.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/paramiko/channel.py b/paramiko/channel.py index 97c7df5..c4e8540 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -996,7 +996,7 @@ class Channel (object): self.in_buffer_cv.notifyAll() self.in_stderr_buffer_cv.notifyAll() if self.pipe is not None: - self.pipe.set() + self.pipe.set_forever() finally: self.lock.release() self._log(DEBUG, 'EOF received') @@ -1022,6 +1022,8 @@ class Channel (object): self.in_buffer_cv.notifyAll() self.in_stderr_buffer_cv.notifyAll() self.out_buffer_cv.notifyAll() + if self.pipe is not None: + self.pipe.set_forever() def _send_eof(self): # you are holding the lock. diff --git a/paramiko/pipe.py b/paramiko/pipe.py index 8c53987..cc28f43 100644 --- a/paramiko/pipe.py +++ b/paramiko/pipe.py @@ -36,6 +36,7 @@ class PosixPipe (object): def __init__ (self): self._rfd, self._wfd = os.pipe() self._set = False + self._forever = False def close (self): os.close(self._rfd) @@ -45,7 +46,7 @@ class PosixPipe (object): return self._rfd def clear (self): - if not self._set: + if not self._set or self._forever: return os.read(self._rfd, 1) self._set = False @@ -55,6 +56,10 @@ class PosixPipe (object): return self._set = True os.write(self._wfd, '*') + + def set_forever (self): + self._forever = True + self.set() class WindowsPipe (object): @@ -74,6 +79,7 @@ class WindowsPipe (object): self._wsock, addr = serv.accept() serv.close() self._set = False + self._forever = False def close (self): self._rsock.close() @@ -83,7 +89,7 @@ class WindowsPipe (object): return self._rsock.fileno() def clear (self): - if not self._set: + if not self._set or self._forever: return self._rsock.recv(1) self._set = False @@ -93,3 +99,7 @@ class WindowsPipe (object): return self._set = True self._wsock.send('*') + + def set_forever (self): + self._forever = True + self.set()