diff options
author | Dan Streetman <ddstreet@canonical.com> | 2020-08-15 15:12:51 -0400 |
---|---|---|
committer | Dan Streetman <ddstreet@canonical.com> | 2020-08-15 15:12:51 -0400 |
commit | 98d052d19eb9f077dba892ca237d19253003e033 (patch) | |
tree | 2fc45386dda9e5d2783002cee2786043756d009b | |
parent | be4b081a0d8dba6ffcb1e17b38a059915f87d61a (diff) |
allow Mux() flush/fill to work with python < 3.5
Fixes: #503
-rw-r--r-- | sshuttle/ssnet.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sshuttle/ssnet.py b/sshuttle/ssnet.py index c01f631..e7f9bf2 100644 --- a/sshuttle/ssnet.py +++ b/sshuttle/ssnet.py @@ -4,6 +4,7 @@ import socket import errno import select import os +import fcntl from sshuttle.helpers import b, log, debug1, debug2, debug3, Fatal @@ -436,7 +437,13 @@ class Mux(Handler): callback(cmd, data) def flush(self): - os.set_blocking(self.wfile.fileno(), False) + try: + os.set_blocking(self.wfile.fileno(), False) + except AttributeError: + # python < 3.5 + flags = fcntl.fcntl(self.wfile.fileno(), fcntl.F_GETFL) + flags |= os.O_NONBLOCK + flags = fcntl.fcntl(self.wfile.fileno(), fcntl.F_SETFL, flags) if self.outbuf and self.outbuf[0]: wrote = _nb_clean(os.write, self.wfile.fileno(), self.outbuf[0]) debug2('mux wrote: %r/%d\n' % (wrote, len(self.outbuf[0]))) @@ -446,7 +453,13 @@ class Mux(Handler): self.outbuf[0:1] = [] def fill(self): - os.set_blocking(self.rfile.fileno(), False) + try: + os.set_blocking(self.rfile.fileno(), False) + except AttributeError: + # python < 3.5 + flags = fcntl.fcntl(self.rfile.fileno(), fcntl.F_GETFL) + flags |= os.O_NONBLOCK + flags = fcntl.fcntl(self.rfile.fileno(), fcntl.F_SETFL, flags) try: read = _nb_clean(os.read, self.rfile.fileno(), LATENCY_BUFFER_SIZE) except OSError: |