Skip to content

Commit

Permalink
allow Mux() flush/fill to work with python < 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Streetman committed Aug 15, 2020
1 parent be4b081 commit 98d052d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions sshuttle/ssnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import errno
import select
import os
import fcntl

from sshuttle.helpers import b, log, debug1, debug2, debug3, Fatal

Expand Down Expand Up @@ -436,7 +437,13 @@ def got_packet(self, channel, cmd, data):
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])))
Expand All @@ -446,7 +453,13 @@ def flush(self):
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:
Expand Down

0 comments on commit 98d052d

Please sign in to comment.