mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-20 17:06:30 +08:00
artiq_devtool: more robust port forwarding.
This commit is contained in:
parent
fbc2420443
commit
8b6418c604
@ -105,6 +105,7 @@ def main():
|
|||||||
elif action == "connect":
|
elif action == "connect":
|
||||||
def forwarder(port):
|
def forwarder(port):
|
||||||
listener = socket.socket()
|
listener = socket.socket()
|
||||||
|
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
listener.bind(('localhost', port))
|
listener.bind(('localhost', port))
|
||||||
listener.listen(1)
|
listener.listen(1)
|
||||||
while True:
|
while True:
|
||||||
@ -114,6 +115,7 @@ def main():
|
|||||||
remote_stream = get_ssh().get_transport() \
|
remote_stream = get_ssh().get_transport() \
|
||||||
.open_channel('direct-tcpip', (args.ip, port), peer_addr)
|
.open_channel('direct-tcpip', (args.ip, port), peer_addr)
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
r, w, x = select.select([local_stream, remote_stream], [], [])
|
r, w, x = select.select([local_stream, remote_stream], [], [])
|
||||||
if local_stream in r:
|
if local_stream in r:
|
||||||
data = local_stream.recv(1024)
|
data = local_stream.recv(1024)
|
||||||
@ -125,6 +127,10 @@ def main():
|
|||||||
if data == b"":
|
if data == b"":
|
||||||
break
|
break
|
||||||
local_stream.send(data)
|
local_stream.send(data)
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception("Forward error on port %s", port)
|
||||||
|
local_stream.close()
|
||||||
|
remote_stream.close()
|
||||||
|
|
||||||
for port in (1381, 1382):
|
for port in (1381, 1382):
|
||||||
thread = threading.Thread(target=forwarder, args=(port,),
|
thread = threading.Thread(target=forwarder, args=(port,),
|
||||||
|
Loading…
Reference in New Issue
Block a user