2 import subprocess, socket, fcntl, select
4 class sshsocket(object):
5 def __init__(self, host, path, user = None, port = None):
8 args += ["-u", str(user)]
10 args += ["-p", str(int(port))]
12 args += ["python", "-m", "pdm.sshsock", path]
13 self.proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
14 fcntl.fcntl(self.proc.stdout, fcntl.F_SETFL, fcntl.fcntl(self.proc.stdout, fcntl.F_GETFL) | os.O_NONBLOCK)
17 if self.proc is not None:
18 self.proc.stdin.close()
19 self.proc.stdout.close()
23 def send(self, data, flags = 0):
24 self.proc.stdin.write(data)
27 def recv(self, buflen, flags = 0):
28 if (flags & socket.MSG_DONTWAIT) == 0:
29 select.select([self.proc.stdout], [], [])
30 return self.proc.stdout.read(buflen)
33 return self.proc.stdout.fileno()
39 fcntl.fcntl(sys.stdin, fcntl.F_SETFL, fcntl.fcntl(sys.stdin, fcntl.F_GETFL) | os.O_NONBLOCK)
40 sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
42 sk.connect(sys.argv[1])
47 if buf1: wfd.append(sk)
48 if buf2: wfd.append(sys.stdout)
49 rfd, wfd, efd = select.select([sk, sys.stdin], wfd, [])
57 ret = sys.stdin.read()
66 sys.stdout.write(buf2)
72 if __name__ == "__main__":