read-string!/partial on non-file ports
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): #). 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
Re: read-string!/partial on non-file ports
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): > #). > > 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 signature.asc Description: This is a digitally signed message part ___ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user
Re: read-string!/partial on non-file ports
On 9/10/07, Stephen Compall <[EMAIL PROTECTED]> 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): > > #). > > > > 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
Re: read-string!/partial on non-file ports
--- Luigi Semenzato <[EMAIL PROTECTED]> 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): > #). > 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
Re: read-string!/partial on non-file ports
Mike Gran <[EMAIL PROTECTED]> 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
Re: read-string!/partial on non-file ports
Hi, "Luigi Semenzato" <[EMAIL PROTECTED]> 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): > #). > > 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 bindings in GnuTLS 2.0
Hi, This is to announce that the newly released GnuTLS 2.0.0 contains bindings for Guile 1.8: http://article.gmane.org/gmane.comp.encryption.gpg.gnutls.devel/2302 Hopefully another (tiny) incentive to write Scheme code! ;-) Happy hacking, Ludovic. ___ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user
Re: read-string!/partial on non-file ports
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 <[EMAIL PROTECTED]> wrote: > Hi, > > "Luigi Semenzato" <[EMAIL PROTECTED]> 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): > > #). > > > > 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