Jan Synáček <jan.syna...@gmail.com> writes: > On Sun, Nov 8, 2015 at 12:49 AM, Andreas Rottmann <a.rottm...@gmx.at> > wrote: > > Also note that if there's no requirement to actually implement > this in > C, there's `fdes->inport' and `fdes->outport' on the Scheme level, > so > something like the following would be analogous to the C example > code > posted: > > (import (ice-9 binary-ports)) > > (define (process-fd fd) > (let ((port (fdes->inport fd))) > (display "read: ") > (display (get-bytevector-n port 100)) > (display "\n"))) > > (process-fd (acquire-valid-fd)) > > > This is something very similar that I ended up with. Just instead of > get-byte-vector, I used read-string!/partial.
I would advise against using 'read-string!/partial' or any of the procedures in (ice-9 rw). This is a vestigial module from Guile 1.8 when strings were arrays of bytes, which they no longer are. We should probably mark them as deprecated. For one thing, when we switch to using UTF-8 as the internal string encoding, it will not be possible to keep 'read-string!/partial' efficient. It will necessarily have to do an encoding conversion. In Guile 2+, I would advise using byte vectors when working with binary data. Portions of these can be converted to strings with a given encoding if desired. I might be able to give better advice if I knew more about what you are doing here. Regards, Mark