()
| 501 | |
| 502 | |
| 503 | def serve(): |
| 504 | logger.info("Xcode Build Server Startup") |
| 505 | while True: |
| 506 | line = sys.stdin.readline() |
| 507 | if len(line) == 0: |
| 508 | break |
| 509 | |
| 510 | assert line.startswith("Content-Length:") |
| 511 | length = int(line[len("Content-Length:") :]) |
| 512 | sys.stdin.readline() |
| 513 | raw = sys.stdin.read(length) |
| 514 | message = json.loads(raw) |
| 515 | logger.debug("Req --> " + raw) |
| 516 | |
| 517 | def default_response(): |
| 518 | if "id" in message: |
| 519 | return { |
| 520 | "jsonrpc": "2.0", |
| 521 | "id": message["id"], |
| 522 | "error": { |
| 523 | "code": 123, |
| 524 | "message": "unhandled method {}".format(message["method"]), |
| 525 | }, |
| 526 | } |
| 527 | |
| 528 | with mainlock: |
| 529 | response = None |
| 530 | handler = dispatch.get(message["method"].replace("/", "_")) |
| 531 | if handler: |
| 532 | try: |
| 533 | response = handler(message) |
| 534 | except Exception as e: |
| 535 | logger.exception(f"handle message error: {e}") |
| 536 | response = default_response() |
| 537 | else: |
| 538 | # ignore other notifications |
| 539 | response = default_response() |
| 540 | if response: |
| 541 | send(response) |
nothing calls this directly
no test coverage detected