[Top][All Lists]

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

Re: Reading data from a file descriptor

From: Andreas Rottmann
Subject: Re: Reading data from a file descriptor
Date: Sun, 08 Nov 2015 00:49:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

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))

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 -- <>

reply via email to

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