diff options
author | Jeremy T. Bouse <jbouse@debian.org> | 2015-03-12 21:35:59 -0400 |
---|---|---|
committer | Jeremy T. Bouse <jbouse@debian.org> | 2015-03-12 21:35:59 -0400 |
commit | 01653e8710c38f3066078b2773ad47ccb3670c58 (patch) | |
tree | 8284e75857a06945167186d09dd9021fd24c2ee1 /paramiko/proxy.py | |
parent | 74794f84c2d9906aea5024dfccd90482fff9bab3 (diff) | |
parent | f784a533d6e1d09e89dc254f3493b491e19c94f0 (diff) | |
download | python-paramiko-01653e8710c38f3066078b2773ad47ccb3670c58.tar python-paramiko-01653e8710c38f3066078b2773ad47ccb3670c58.tar.gz |
Merge tag 'upstream/1.15.2'
Upstream version 1.15.2
Diffstat (limited to 'paramiko/proxy.py')
-rw-r--r-- | paramiko/proxy.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/paramiko/proxy.py b/paramiko/proxy.py index 0664ac6..ca602c4 100644 --- a/paramiko/proxy.py +++ b/paramiko/proxy.py @@ -24,6 +24,7 @@ import signal from subprocess import Popen, PIPE from select import select import socket +import time from paramiko.ssh_exception import ProxyCommandFailure from paramiko.util import ClosingContextManager @@ -79,20 +80,24 @@ class ProxyCommand(ClosingContextManager): :return: the length of the read content, as an `int` """ try: - start = datetime.now() + start = time.time() while len(self.buffer) < size: + select_timeout = None if self.timeout is not None: - elapsed = (datetime.now() - start).microseconds - timeout = self.timeout * 1000 * 1000 # to microseconds - if elapsed >= timeout: + elapsed = (time.time() - start) + if elapsed >= self.timeout: raise socket.timeout() - r, w, x = select([self.process.stdout], [], [], 0.0) + select_timeout = self.timeout - elapsed + + r, w, x = select( + [self.process.stdout], [], [], select_timeout) if r and r[0] == self.process.stdout: - b = os.read(self.process.stdout.fileno(), 1) + b = os.read( + self.process.stdout.fileno(), size - len(self.buffer)) # Store in class-level buffer for persistence across # timeouts; this makes us act more like a real socket # (where timeouts don't actually drop data.) - self.buffer.append(b) + self.buffer.extend(b) result = ''.join(self.buffer) self.buffer = [] return result |