From cc3609362eca771104bc46bb9eb3d0a0846f2675 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 24 Nov 2015 21:35:40 +0000 Subject: [PATCH] Make swig_bot server support Ctrl+C llvm-svn: 254024 --- lldb/scripts/swig_bot.py | 3 +++ lldb/scripts/swig_bot_lib/server.py | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lldb/scripts/swig_bot.py b/lldb/scripts/swig_bot.py index 38e65ca1e267..0f5238e1a81c 100644 --- a/lldb/scripts/swig_bot.py +++ b/lldb/scripts/swig_bot.py @@ -57,6 +57,9 @@ if __name__ == "__main__": else: logging.error("Unknown mode specified. Expected client or server.") sys.exit(-1) + except KeyboardInterrupt as e: + logging.info("Ctrl+C received. Shutting down...") + sys.exit(-1) except Exception as e: error = traceback.format_exc() logging.error("An error occurred running swig-bot.") diff --git a/lldb/scripts/swig_bot_lib/server.py b/lldb/scripts/swig_bot_lib/server.py index ab9baaf7cc04..0751ce8a29a4 100644 --- a/lldb/scripts/swig_bot_lib/server.py +++ b/lldb/scripts/swig_bot_lib/server.py @@ -13,6 +13,7 @@ from __future__ import print_function import argparse import logging import os +import select import socket import struct import sys @@ -53,16 +54,23 @@ def initialize_listening_socket(options): def accept_once(sock, options): logging.debug("Waiting for connection...") - client, addr = sock.accept() - logging.info("Received connection from {}".format(addr)) - data_size = struct.unpack("!I", sockutil.recvall(client, 4))[0] - logging.debug("Expecting {} bytes of data from client".format(data_size)) - data = sockutil.recvall(client, data_size) - logging.info("Received {} bytes of data from client".format(len(data))) + while True: + rlist, wlist, xlist = select.select([sock], [], [], 0.5) + if not rlist: + continue - logging.info("Sending {} byte response".format(len(data))) - client.sendall(struct.pack("!I", len(data))) - client.sendall(data) + client, addr = sock.accept() + logging.info("Received connection from {}".format(addr)) + data_size = struct.unpack("!I", sockutil.recvall(client, 4))[0] + logging.debug("Expecting {} bytes of data from client" + .format(data_size)) + data = sockutil.recvall(client, data_size) + logging.info("Received {} bytes of data from client" + .format(len(data))) + + logging.info("Sending {} byte response".format(len(data))) + client.sendall(struct.pack("!I", len(data))) + client.sendall(data) def accept_loop(sock, options): while True: