From 0a2899ca82318b775dfba5bdbb42102393dc6f6e Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 24 Nov 2015 21:35:32 +0000 Subject: swig_bot remote path connection / preliminary implementation. With this patch, the client will package up all the required inputs into a compressed zip file, establish a connection to the server, send the input to the server, and wait for the server to send a response (in this case the response is just echoed back to the client). This gets the network communication in place, and in a subsequent patch I will follow up with the code that actually runs swig on the server and sends back the output instead of echoing back the input. llvm-svn: 254023 --- lldb/scripts/swig_bot_lib/server.py | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'lldb/scripts/swig_bot_lib/server.py') diff --git a/lldb/scripts/swig_bot_lib/server.py b/lldb/scripts/swig_bot_lib/server.py index b7f62e00e1b..ab9baaf7cc0 100644 --- a/lldb/scripts/swig_bot_lib/server.py +++ b/lldb/scripts/swig_bot_lib/server.py @@ -1,6 +1,80 @@ #!/usr/bin/env python +""" +SWIG generation server. Listens for connections from swig generation clients +and runs swig in the requested fashion, sending back the results. +""" + # Future imports from __future__ import absolute_import from __future__ import print_function +# Python modules +import argparse +import logging +import os +import socket +import struct +import sys +import traceback + +# LLDB modules +import use_lldb_suite +from lldbsuite.support import sockutil + +# package imports +from . import local + +default_port = 8537 + +def process_args(args): + # Setup the parser arguments that are accepted. + parser = argparse.ArgumentParser(description='SWIG generation server.') + + parser.add_argument( + "--port", + action="store", + default=default_port, + help=("The local port to bind to")) + + # Process args. + return parser.parse_args(args) + +def initialize_listening_socket(options): + logging.debug("Creating socket...") + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + logging.info("Binding to ip address '', port {}".format(options.port)) + s.bind(('', options.port)) + + logging.debug("Putting socket in listen mode...") + s.listen() + return s + +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))) + + 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: + try: + accept_once(sock, options) + except Exception as e: + error = traceback.format_exc() + logging.error("An error occurred while processing the connection.") + logging.error(error) + +def run(args): + options = process_args(args) + sock = initialize_listening_socket(options) + accept_loop(sock, options) + return options -- cgit v1.2.3