Exemple #1
0
def remote_compile_client(conn, source_file_name, compile_args, source_data):
    conn.settimeout(None)
    schedaemon_util.send_buffer(conn, source_file_name)
    compile_args_str = '\0'.join(compile_args)
    schedaemon_util.send_buffer(conn, compile_args_str)
    schedaemon_util.send_buffer(conn, source_data)

    try:
        returncode = schedaemon_util.recv_struct(conn, '<i')
        outdata = schedaemon_util.recv_buffer(conn)
        errdata = schedaemon_util.recv_buffer(conn)

        sys.stderr.write(errdata)
        sys.stdout.write(outdata)

        num_files = schedaemon_util.recv_struct(conn, '<Q')
        output_files = []
        for i in range(num_files):
            file_name = str(schedaemon_util.recv_buffer(conn))
            file_data = schedaemon_util.recv_buffer(conn)
            output_files.append((file_name, file_data))
            continue

        ccerbd.write_files('', output_files)
        return returncode
    except schedaemon_util.ExSocketClosed:
        print('ERROR: `ccerb` socket closed early.', file=sys.stderr)
        return 1
Exemple #2
0
def sched_accept(conn, addr):
    if VERBOSE >= 2:
        print('new conn: ', addr)

    conn.settimeout(NET_TIMEOUT)
    try:
        priority = schedaemon_util.recv_struct(conn, PRIORITY_STRUCT)
        info = str(schedaemon_util.recv_buffer(conn))

    except (socket.timeout, socket.error, schedaemon_util.ExSocketClosed):
        return

    ####

    job = Job(priority, info)
    if VERBOSE >= 1:
        print('<new {}>'.format(job))
    g_pq.put_right(job)

    ####

    conn.setblocking(True)

    try:
        job.begin_event.wait()
        if VERBOSE >= 1:
            start = time.time()
            print('<+{}>'.format(job))

        conn.sendall( bytearray([1]) )
        conn.recv(1) # Blocks until recv or socket dies.
    except socket.error:
        pass

    if VERBOSE >= 1:
        time_diff = time.time() - start
        print('<-{}@{}ms>'.format(job, time_diff))

    job.end_event.set()
    g_pq.erase(job)
    return