unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
To: guile-user@gnu.org
Subject: Re: read-string!/partial on non-file ports
Date: Tue, 11 Sep 2007 09:49:41 +1000	[thread overview]
Message-ID: <87r6l6jd2i.fsf@zip.com.au> (raw)
In-Reply-To: 235712.72749.qm@web37908.mail.mud.yahoo.com

Mike Gran <spk121@yahoo.com> 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)


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2007-09-10 23:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-10 19:25 read-string!/partial on non-file ports Luigi Semenzato
2007-09-10 19:51 ` Stephen Compall
2007-09-10 20:35   ` Luigi Semenzato
2007-09-11  7:18     ` Thien-Thi Nguyen
2007-09-10 20:42 ` Mike Gran
2007-09-10 23:49   ` Kevin Ryde [this message]
2007-09-10 23:19 ` Ludovic Courtès
2007-09-11  5:00   ` Luigi Semenzato

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r6l6jd2i.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).