def proxy_to_coordinator(socket_path, header=None, stdin=None, stdout=None): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(socket_path) try: stdin_fd = get_fd(stdin, sys.stdin) stdout_fd = get_fd(stdout, sys.stdout) with no_echo(stdin_fd): while True: ready, _, _ = select.select([stdin_fd, sock], [], []) if stdin_fd in ready: c = os.read(stdin_fd, 1) if c: sock.send(c) if sock in ready: c = sock.recv(1024) if not c: break os.write(stdout_fd, c) finally: sock.close()
def proxy_to_coordinator(socket_path, header=None, stdin=None, stdout=None): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(socket_path) try: stdin_fd = get_fd(stdin, sys.stdin) stdout_fd = get_fd(stdout, sys.stdout) with no_echo(stdin_fd): while True: ready, _, _ = select.select([stdin_fd, sock], [], []) if stdin_fd in ready: c = os.read(stdin_fd, 1) if c: sock.send(c) if sock in ready: try: c = sock.recv(1024) except socket.error as e: break if not c: break os.write(stdout_fd, c) finally: sock.close()
def join_player(sock_path, **kwds): stdout_fd = get_fd(kwds.get("stdout"), sys.stdout) os.write(stdout_fd, "\x1b[2J\x1b[H") return proxy_to_coordinator(sock_path, **kwds)