Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow Mux() flush/fill to work with python < 3.5 #507

Merged
merged 1 commit into from Aug 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions sshuttle/ssnet.py
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