artiq_devtool: don't drop data in unpredictable ways (sigh).

This commit is contained in:
whitequark 2017-07-18 02:38:22 +00:00
parent a201a9abd9
commit 9e38132c0a
1 changed files with 6 additions and 5 deletions

View File

@ -111,6 +111,7 @@ def main():
client.drain(flterm) client.drain(flterm)
elif action == "connect": elif action == "connect":
transport = client.get_transport()
def forwarder(port): def forwarder(port):
listener = socket.socket() listener = socket.socket()
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@ -125,24 +126,24 @@ def main():
continue continue
try: try:
remote_stream = client.get_transport() \ remote_stream = \
.open_channel('direct-tcpip', (args.device, port), peer_addr) transport.open_channel('direct-tcpip', (args.device, port), peer_addr)
except Exception as e: except Exception as e:
logger.exception("Cannot open channel on port %s", port) logger.exception("Cannot open channel on port %s", port)
continue continue
while True: while True:
try: try:
r, w, x = select.select([local_stream, remote_stream], [], []) r, _, _ = select.select([local_stream, remote_stream], [], [])
if local_stream in r: if local_stream in r:
data = local_stream.recv(65535) data = local_stream.recv(65535)
if data == b"": if data == b"":
break break
remote_stream.send(data) remote_stream.sendall(data)
if remote_stream in r: if remote_stream in r:
data = remote_stream.recv(65535) data = remote_stream.recv(65535)
if data == b"": if data == b"":
break break
local_stream.send(data) local_stream.sendall(data)
except Exception as e: except Exception as e:
logger.exception("Forward error on port %s", port) logger.exception("Forward error on port %s", port)
break break