* read-string!/partial on non-file ports
@ 2007-09-10 19:25 Luigi Semenzato
2007-09-10 19:51 ` Stephen Compall
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Luigi Semenzato @ 2007-09-10 19:25 UTC (permalink / raw)
To: guile-user
Greetings,
I would like to move binary data between two guile
applications across a pipe (opened with open-input-output-pipe).
Read-char and write-char in a loop are going to be too slow.
Read-string!/partial and write-string/partial are exactly what
I need but they only work on file ports. (I get this error:
Wrong type argument in position 2 (expecting open file port):
#<input-output: soft 56f1d0>).
Two questions.
1. Do I have other choices? I cannot find any.
2. If I have no other choices, should I write my own extension
to do block read/writes on pipes, or should I coordinate with
you folks to add this feature to guile?
Thanks!
Luigi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: read-string!/partial on non-file ports
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-10 20:42 ` Mike Gran
2007-09-10 23:19 ` Ludovic Courtès
2 siblings, 1 reply; 8+ messages in thread
From: Stephen Compall @ 2007-09-10 19:51 UTC (permalink / raw)
To: Luigi Semenzato; +Cc: guile-user
[-- Attachment #1.1: Type: text/plain, Size: 1223 bytes --]
On Mon, 2007-09-10 at 12:25 -0700, Luigi Semenzato wrote:
> I would like to move binary data between two guile
> applications across a pipe (opened with open-input-output-pipe).
> Read-char and write-char in a loop are going to be too slow.
> Read-string!/partial and write-string/partial are exactly what
> I need but they only work on file ports. (I get this error:
> Wrong type argument in position 2 (expecting open file port):
> #<input-output: soft 56f1d0>).
>
> 1. Do I have other choices? I cannot find any.
How about display?
-- Scheme Procedure: display obj [port]
Send a representation of OBJ to PORT or to the current output port
if not given.
The output is designed for human readability, it differs from
`write' in that strings are printed without doublequotes and
escapes, and characters are printed as per `write-char', not in
`#\' form.
--
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
"Peta" is Greek for fifth; a petabyte is 10 to the fifth power, as
well as fifth in line after kilo, mega, giga, and tera.
-- Lee Gomes, performing every Wednesday in his tech column
"Portals" on page B1 of The Wall Street Journal
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
[-- Attachment #2: Type: text/plain, Size: 140 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: read-string!/partial on non-file ports
2007-09-10 19:51 ` Stephen Compall
@ 2007-09-10 20:35 ` Luigi Semenzato
2007-09-11 7:18 ` Thien-Thi Nguyen
0 siblings, 1 reply; 8+ messages in thread
From: Luigi Semenzato @ 2007-09-10 20:35 UTC (permalink / raw)
To: Stephen Compall; +Cc: guile-user
On 9/10/07, Stephen Compall <s11@member.fsf.org> wrote:
> On Mon, 2007-09-10 at 12:25 -0700, Luigi Semenzato wrote:
> > I would like to move binary data between two guile
> > applications across a pipe (opened with open-input-output-pipe).
> > Read-char and write-char in a loop are going to be too slow.
> > Read-string!/partial and write-string/partial are exactly what
> > I need but they only work on file ports. (I get this error:
> > Wrong type argument in position 2 (expecting open file port):
> > #<input-output: soft 56f1d0>).
> >
> > 1. Do I have other choices? I cannot find any.
>
> How about display?
>
> -- Scheme Procedure: display obj [port]
> Send a representation of OBJ to PORT or to the current output port
> if not given.
>
> The output is designed for human readability, it differs from
> `write' in that strings are printed without doublequotes and
> escapes, and characters are printed as per `write-char', not in
> `#\' form.
That's cool for writing, thanks. But what about reading?
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: read-string!/partial on non-file ports
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:42 ` Mike Gran
2007-09-10 23:49 ` Kevin Ryde
2007-09-10 23:19 ` Ludovic Courtès
2 siblings, 1 reply; 8+ messages in thread
From: Mike Gran @ 2007-09-10 20:42 UTC (permalink / raw)
To: Luigi Semenzato, guile-user
--- Luigi Semenzato <luigi@semenzato.com> wrote:
> Greetings,
>
> I would like to move binary data between two guile
> applications across a pipe (opened with open-input-output-pipe).
> Read-char and write-char in a loop are going to be too slow.
> Read-string!/partial and write-string/partial are exactly what
> I need but they only work on file ports. (I get this error:
> Wrong type argument in position 2 (expecting open file port):
> #<input-output: soft 56f1d0>).
> Luigi-
In the past, I know that I have used read-string!/partial to read from
a socket.
I wrote a peer-to-peer ap where I used "(display data socket)" to send
and "(read-string!/partial block socket-port)" to receive.
I haven't tried it with a pipe, however.
(I used it in a rather confusing program found at
http://lonelycactus.com/code/schmolester , but, that code is pretty
ugly to use as an example.)
Hope this helps,
Mike Gran
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: read-string!/partial on non-file ports
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:42 ` Mike Gran
@ 2007-09-10 23:19 ` Ludovic Courtès
2007-09-11 5:00 ` Luigi Semenzato
2 siblings, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2007-09-10 23:19 UTC (permalink / raw)
To: guile-user
Hi,
"Luigi Semenzato" <luigi@semenzato.com> writes:
> I would like to move binary data between two guile
> applications across a pipe (opened with open-input-output-pipe).
> Read-char and write-char in a loop are going to be too slow.
> Read-string!/partial and write-string/partial are exactly what
> I need but they only work on file ports. (I get this error:
> Wrong type argument in position 2 (expecting open file port):
> #<input-output: soft 56f1d0>).
>
> Two questions.
>
> 1. Do I have other choices? I cannot find any.
Using strings for binary I/O is Bad because it assumes a specific
bit-representation of strings (namely, ASCII).
SRFI-4 vectors and `uniform-vector-read!'/`uniform-vector-write' may be
a better match.
If you're not afraid of using experimental code, you might also want to
try Guile-R6RS-Libs, which includes part of R6RS' binary I/O API
(actually based on R5.92RS):
http://www.laas.fr/~lcourtes/software/guile/guile-r6rs-libs-0.0.tar.gz
http://www.r6rs.org/document/lib-html-5.92/r6rs-lib-Z-H-4.html#node_chap_2
http://www.r6rs.org/document/lib-html-5.92/r6rs-lib-Z-H-9.html#node_sec_7.2
Thanks,
Ludovic.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: read-string!/partial on non-file ports
2007-09-10 20:42 ` Mike Gran
@ 2007-09-10 23:49 ` Kevin Ryde
0 siblings, 0 replies; 8+ messages in thread
From: Kevin Ryde @ 2007-09-10 23:49 UTC (permalink / raw)
To: guile-user
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: read-string!/partial on non-file ports
2007-09-10 23:19 ` Ludovic Courtès
@ 2007-09-11 5:00 ` Luigi Semenzato
0 siblings, 0 replies; 8+ messages in thread
From: Luigi Semenzato @ 2007-09-11 5:00 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-user
Wow, thanks for all the help.
Mike and Kevin pointed out that it's probably
best to use socketpair rather than pipe. Of course. I am
such a troglodyte. Kevin's example looks robust and I
used it almost verbatim (I assume it's OK). It works
fine.
Ludovic suggests that uniform vectors are better than
strings for raw data. Yes. The distinction is not vital for
me at this point, but if I get beyond a prototype, that's
the right direction.
For the moment I'll pass on the suggestion of using
Guile-R6RS-Libs. The language is large enough as it is
and I am learning it as I go along.
Thanks again!
Luigi
On 9/10/07, Ludovic Courtès <ludo@gnu.org> wrote:
> Hi,
>
> "Luigi Semenzato" <luigi@semenzato.com> writes:
>
> > I would like to move binary data between two guile
> > applications across a pipe (opened with open-input-output-pipe).
> > Read-char and write-char in a loop are going to be too slow.
> > Read-string!/partial and write-string/partial are exactly what
> > I need but they only work on file ports. (I get this error:
> > Wrong type argument in position 2 (expecting open file port):
> > #<input-output: soft 56f1d0>).
> >
> > Two questions.
> >
> > 1. Do I have other choices? I cannot find any.
>
> Using strings for binary I/O is Bad because it assumes a specific
> bit-representation of strings (namely, ASCII).
>
> SRFI-4 vectors and `uniform-vector-read!'/`uniform-vector-write' may be
> a better match.
>
> If you're not afraid of using experimental code, you might also want to
> try Guile-R6RS-Libs, which includes part of R6RS' binary I/O API
> (actually based on R5.92RS):
>
> http://www.laas.fr/~lcourtes/software/guile/guile-r6rs-libs-0.0.tar.gz
>
> http://www.r6rs.org/document/lib-html-5.92/r6rs-lib-Z-H-4.html#node_chap_2
> http://www.r6rs.org/document/lib-html-5.92/r6rs-lib-Z-H-9.html#node_sec_7.2
>
> Thanks,
> Ludovic.
>
>
>
> _______________________________________________
> Guile-user mailing list
> Guile-user@gnu.org
> http://lists.gnu.org/mailman/listinfo/guile-user
>
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: read-string!/partial on non-file ports
2007-09-10 20:35 ` Luigi Semenzato
@ 2007-09-11 7:18 ` Thien-Thi Nguyen
0 siblings, 0 replies; 8+ messages in thread
From: Thien-Thi Nguyen @ 2007-09-11 7:18 UTC (permalink / raw)
To: Luigi Semenzato; +Cc: guile-user
() "Luigi Semenzato" <luigi@semenzato.com>
() Mon, 10 Sep 2007 13:35:29 -0700
That's cool for writing, thanks. But what about reading?
have you tried passing the socket's file descriptor to read-string!/partial?
thi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-09-11 7:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2007-09-10 23:19 ` Ludovic Courtès
2007-09-11 5:00 ` Luigi Semenzato
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).