[Top][All Lists]

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

Re: Reading data from a file descriptor

From: Jan Synáček
Subject: Re: Reading data from a file descriptor
Date: Mon, 9 Nov 2015 08:25:05 +0100

On Sun, Nov 8, 2015 at 12:49 AM, Andreas Rottmann <address@hidden> wrote:
Artyom Poptsov <address@hidden> writes:

> Oh sorry, there was a mistake in my previous mail.  'scm_i_fdes_to_port'
> is an internal procedure, but 'scm_fdes_to_port' is defined as Guile API
> and should be available to Guile programs.  Here's its definition:
> scm_fdes_to_port (int fdes, char *mode, SCM name)
> And the commentary that I quoted really applies to 'scm_fdes_to_port',
> not to 'scm_i_fdes_to_port'.
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

    (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.
You could now just implement `acquire-valid-fd' in C and expose it to
Scheme, if that is even necessary. If you have the FD available via
e.g. an environment variable, `acquire-valid-fd' can be implemented in
Scheme as well.

Regards, Rotty
Andreas Rottmann -- <>

Thank you for all the responses!
Jan Synáček

reply via email to

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