Exemple #1
0
def acquire_remote(cc_key):
    addr_list = [REMOTE_ADDR]

    gai_list = []
    for (host, port) in addr_list:
        gai_list += socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)

    for gai in gai_list:
        print('gai:', gai)
        (family, socktype, proto, _, sockaddr) = gai
        remote_conn = None
        try:
            remote_conn = socket.socket(family, socktype, proto)
            remote_conn.settimeout(REMOTE_NET_TIMEOUT)
            remote_conn.connect(sockaddr)
        except (socket.error, socket.timeout) as e:
            if remote_conn:
                schedaemon_util.kill_socket(remote_conn)
            print('gai failed:', e)
            continue
        break
    else:
        print('out of gai')
        return (None, None)

    try:
        schedaemon_util.send_buffer(remote_conn, '') # no token
        schedaemon_util.send_buffer(remote_conn, cc_key)

        remote_conn.settimeout(None)
        reconn_token = str(schedaemon_util.recv_buffer(remote_conn))
        return (gai, reconn_token)
    except schedaemon_util.ExSocketClosed:
        print('no token')
        return (None, None)
    finally:
        schedaemon_util.kill_socket(remote_conn)
Exemple #2
0
def main(args):
    assert len(args) >= 1

    cc_bin = args[0]
    cc_args = args[1:]

    (preproc_args, compile_args, source_file_name) = process_args(cc_args)
    #print('\npreproc_args:', preproc_args)
    #print('\ncompile_args:', compile_args)

    ####

    try:
        info = 'ccerb-preproc: {}'.format(source_file_name)
        with schedaemon.ScheduledJob(PREPROC_PRIORITY, info):
            cc_key = ccerbd.get_cc_key(cc_bin)
            preproc_args = [cc_bin] + preproc_args + [source_file_name]
            p = subprocess.Popen(preproc_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

            (outdata, errdata) = p.communicate()
            if p.returncode != 0:
                sys.stderr.write(errdata)
                sys.stdout.write(outdata)
                exit(p.returncode)

            preproc_data = outdata
    except schedaemon.ExTimeout:
        print('ERROR: Missing `schedaemon`.', file=sys.stderr)
        return 1 # Will oversubscribe heavily without schedaemon.

    #print(preproc_data)
    #exit(0)

    ####

    while True:
        try:
            local_conn = socket.create_connection(ccerbd.LOCAL_ADDR, LOCAL_TIMEOUT)
        except socket.timeout:
            print('ERROR: Missing `ccerbd`.', file=sys.stderr)
            return 1 # Exit, since even shimming out is strictly slower than normal.

        try:
            schedaemon_util.send_buffer(local_conn, cc_key)

            local_conn.settimeout(None)
            remote_gai_str = str(schedaemon_util.recv_buffer(local_conn))
            reconn_token = schedaemon_util.recv_buffer(local_conn)
        except  (socket.error, schedaemon_util.ExSocketClosed) as e:
            if VERBOSE >= 1:
                print('Warning: Failed to request remote compile addr. ({})'.format(e),
                      file=sys.stderr)
            raise ExShimOut('no remote compile addr')
        finally:
            schedaemon_util.kill_socket(local_conn)

        ####

        remote_gai = marshal.loads(remote_gai_str)
        (family, socktype, proto, _, sockaddr) = remote_gai

        ####

        try:
            remote_conn = socket.socket(family, socktype, proto)
            remote_conn.connect(sockaddr)
        except (socket.error, socket.timeout) as e:
            print('Failed to connect to remote addr ({}): {}'.format(remote_gai, e))
            continue

        try:
            schedaemon_util.send_buffer(remote_conn, reconn_token)
            returncode = remote_compile_client(remote_conn, source_file_name,
                                               compile_args, preproc_data)
        except (socket.error, socket.timeout, schedaemon_util.ExSocketClosed) as e:
            print('Remote compile failed ({}): {}'.format(remote_gai, e))
            continue
        finally:
            schedaemon_util.kill_socket(remote_conn)

        break

    ####

    return returncode
Exemple #3
0
 def cancel(self):
     if self.conn:
         schedaemon_util.kill_socket(self.conn)
     self.conn = None
     return