Skip to content

Commit 98d052d

Browse files
author
Dan Streetman
committed
allow Mux() flush/fill to work with python < 3.5
Fixes: #503
1 parent be4b081 commit 98d052d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

sshuttle/ssnet.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import errno
55
import select
66
import os
7+
import fcntl
78

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

@@ -436,7 +437,13 @@ def got_packet(self, channel, cmd, data):
436437
callback(cmd, data)
437438

438439
def flush(self):
439-
os.set_blocking(self.wfile.fileno(), False)
440+
try:
441+
os.set_blocking(self.wfile.fileno(), False)
442+
except AttributeError:
443+
# python < 3.5
444+
flags = fcntl.fcntl(self.wfile.fileno(), fcntl.F_GETFL)
445+
flags |= os.O_NONBLOCK
446+
flags = fcntl.fcntl(self.wfile.fileno(), fcntl.F_SETFL, flags)
440447
if self.outbuf and self.outbuf[0]:
441448
wrote = _nb_clean(os.write, self.wfile.fileno(), self.outbuf[0])
442449
debug2('mux wrote: %r/%d\n' % (wrote, len(self.outbuf[0])))
@@ -446,7 +453,13 @@ def flush(self):
446453
self.outbuf[0:1] = []
447454

448455
def fill(self):
449-
os.set_blocking(self.rfile.fileno(), False)
456+
try:
457+
os.set_blocking(self.rfile.fileno(), False)
458+
except AttributeError:
459+
# python < 3.5
460+
flags = fcntl.fcntl(self.rfile.fileno(), fcntl.F_GETFL)
461+
flags |= os.O_NONBLOCK
462+
flags = fcntl.fcntl(self.rfile.fileno(), fcntl.F_SETFL, flags)
450463
try:
451464
read = _nb_clean(os.read, self.rfile.fileno(), LATENCY_BUFFER_SIZE)
452465
except OSError:

0 commit comments

Comments
 (0)