; program i/o ; this works, but not using a proper protocol can make it lock up ; pretty easily. ; next plan: how to do something like this: ; [HOST] uds <-> program <-> ssh channel <-> program <-> uds [HOST] ; i.o. to connect two program that ordinarily communicate with ; uds using a secure channel, so authentication is offloaded to unix ; file permissions/login for uds, and ssh identication/encryption for ; the internet channel. ; maybe the first problem to solve is really an object channel over ; ssh between two guile instances. (define (make-program pid read write) (cons pid (cons read write))) (define (program-read-port program) (cadr program)) (define (program-write-port program) (cddr program)) (define (program-pid program) (car program)) (define (program-wait program) (waitpid (program-pid program))) (define (open-program . program-lst) (define (read-port pair) (car pair)) (define (write-port pair) (cdr pair)) ;; create pipes (let ((request (pipe)) ;; us -> program (reply (pipe))) ;; program -> us ;; fork (let ((child-pid (primitive-fork))) (if (zero? child-pid) (begin ;; child (dup->fdes (read-port request) 0) ;; connect stdin (dup->fdes (write-port reply) 1) ;; connect stdout (apply execlp program-lst)) (begin ;; parent (setvbuf (write-port request) _IONBF) ;; turn off buffering (make-program child-pid (read-port reply) (write-port request))))))) ; TEST ; (define bash (program-connect "bash" "bash")) ; (define (bash-write command) ; (let ((port (program-write-port bash))) ; (with-output-to-port port ; (lambda () ; (display command) ; (newline))))) ; (define (bash-read) ; (read-line (program-read-port bash))) ;; scheme channel, client-server model ;; SERVER = unix domain server