From 5df9a1d2c5f572d3258fd3b13c638ceaa27b46c3 Mon Sep 17 00:00:00 2001 From: ghostplant Date: Wed, 19 Apr 2023 00:00:27 +0800 Subject: [PATCH] avoid reconnecting socket due to multi-init --- backends/c-hlsl_xbox/evaluator/client.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backends/c-hlsl_xbox/evaluator/client.py b/backends/c-hlsl_xbox/evaluator/client.py index f822c58..33fae24 100755 --- a/backends/c-hlsl_xbox/evaluator/client.py +++ b/backends/c-hlsl_xbox/evaluator/client.py @@ -14,14 +14,15 @@ EVAL_PROPERTIES = {'compiler': 'x86_64-w64-mingw32-g++', 'compile_flags': '-std= def init(**kwargs): if rev_port: - import socket - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - print(f"\n>> Waiting for peer to connect to port: {rev_port} ..") - s.bind(('0.0.0.0', rev_port)) - s.listen() - conn, addr = s.accept() - rev_state["s"], rev_state["conn"] = s, conn + if "conn" not in rev_state: + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + print(f"\n>> Waiting for peer to connect to port: {rev_port} ..") + s.bind(('0.0.0.0', rev_port)) + s.listen() + conn, addr = s.accept() + rev_state["s"], rev_state["conn"] = s, conn print(f"Received connection from peer.") elif not os.environ.get('AGENT_URL', ''): print("Skipping evaluation: environment variable `AGENT_URL` not specified (required: e.g. export AGENT_URL=)")