guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read-string!/partial on non-file ports


From: Kevin Ryde
Subject: Re: read-string!/partial on non-file ports
Date: Tue, 11 Sep 2007 09:49:41 +1000
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux)

Mike Gran <address@hidden> writes:
>
> I wrote a peer-to-peer ap where I used "(display data socket)" to send
> and "(read-string!/partial block socket-port)" to receive.  

That'd be the ticket, I use a `socketpair' and read-string to talk back
and forward to a child process.  You have to have an ugly
fork/exec/whatever yourself of course (fragment below).  In any case the
soft ports thingie certainly ought to have a read-string operation, you
can't do input a character at a time.


  (let* ((pair          (socketpair PF_UNIX SOCK_STREAM 0))
         (parent-sock   (car pair))
         (child-sock    (cdr pair))
         (errport       (mkstemp-ext ""))
         (pid           (primitive-fork)))

    (if (eqv? 0 pid)  ;; child
        (catch #t
          (lambda ()
            (dup2 (fileno child-sock) 0)
            (dup2 (fileno child-sock) 1)
            (dup2 (fileno errport)    2)

            (port-for-each
             (lambda (port)
               (false-if-exception ;; for non-fd ports and/or close errors
                (let ((fd (fileno port)))
                  (or (<= fd 2)
                      (close-fdes fd))))))

            (apply execlp (first args) args))

          (lambda errargs
            (primitive-_exit 127))))

    ;; parent
    (close-port child-sock)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]