Send a debug command and wait for response (blocks).
(sock, cmd, session_id=None, timeout=180)
| 19 | SOCKET_PATH = os.path.join(RUNTIME_DIR, "jcode-debug.sock") |
| 20 | |
| 21 | def send_cmd_blocking(sock, cmd, session_id=None, timeout=180): |
| 22 | """Send a debug command and wait for response (blocks).""" |
| 23 | req = {"type": "debug_command", "id": int(time.time() * 1000000), "command": cmd} |
| 24 | if session_id: |
| 25 | req["session_id"] = session_id |
| 26 | sock.send((json.dumps(req) + '\n').encode()) |
| 27 | sock.settimeout(timeout) |
| 28 | |
| 29 | data = b"" |
| 30 | while True: |
| 31 | try: |
| 32 | chunk = sock.recv(65536) |
| 33 | if not chunk: |
| 34 | break |
| 35 | data += chunk |
| 36 | try: |
| 37 | resp = json.loads(data.decode()) |
| 38 | return resp.get('ok', False), resp.get('output', '') |
| 39 | except json.JSONDecodeError: |
| 40 | continue |
| 41 | except socket.timeout: |
| 42 | break |
| 43 | |
| 44 | try: |
| 45 | resp = json.loads(data.decode()) |
| 46 | return resp.get('ok', False), resp.get('output', '') |
| 47 | except: |
| 48 | return False, f"Failed to parse: {data.decode()[:500]}" |
| 49 | |
| 50 | def send_cmd_quick(cmd, session_id=None, timeout=10): |
| 51 | """Quick command on fresh connection.""" |
no test coverage detected