From: Frank Goenninger DG1SBG
Subject: Re: Lisp stream to file descriptor conversion ?
Date:
Message-ID: <m2r732jbbi.fsf@pcsde001.local>
····@rpw3.org (Rob Warnock) writes:
> Frank Goenninger DG1SBG <·······@nomail.com> wrote:
> +---------------
> | When accessing a serial device I need to set the device into raw mode.
> ...
> | Now, using AllegroCL, I am trying to figure out how to get a file
> | descriptor of a Lisp stream.
> +---------------
>
> This will be *very* implementation-dependent, so you will probably want
> to isolate this off into your local "misc. implementation-dependent stuff"
> library.
Yep.
>
> +---------------
> | When inspecting the stream I get back from calling (open "somefile") I
> | see there's some slots named
> | INPUT-HANDLE and
> | OUTPUT-HANDLE
> | Are these valid file descriptors ???
> +---------------
>
> Dunno 'bout Allegro, but for any stream which is connected directly
> to a Unix file or device, CMUCL provides a subclass of STREAM called
> FD-STREAM, which contains a Unix FD slot, e.g.:
>
> cmu> (open "/dev/random")
>
> #<Stream for file "/dev/random">
> cmu> (lisp::fd-stream-fd *)
>
> 6
> cmu>
Likewise in AllegroCL:
CL-USER> (open "/dev/random")
#<TERMINAL-SIMPLE-STREAM /dev/random for input fd 35 @ #x10b1f9da>
CL-USER> (excl:stream-input-fn *)
35
CL-USER>
>
> But be careful! In CMUCL, *STANDARD-INPUT* is *not* an FD-STREAM! ;-}
> So if you wanted to play with the TTY modes of your terminal,
> getting to its Unix file descriptor is a bit more complex:
>
> cmu> (type-of *standard-input*)
>
> TWO-WAY-STREAM
> cmu> (type-of (two-way-stream-input-stream *standard-input*))
>
> SYNONYM-STREAM
> cmu> (synonym-stream-symbol (two-way-stream-input-stream *standard-input*))
>
> SYSTEM:*STDIN*
> cmu> (type-of system:*stdin*)
>
> SYSTEM:FD-STREAM
> cmu> (lisp::fd-stream-fd system:*stdin*)
>
> 0
> cmu>
>
> And likewise:
>
> cmu> (lisp::fd-stream-fd
> (symbol-value
> (synonym-stream-symbol
> (two-way-stream-output-stream *standard-input*))))
>
> 1
> cmu>
>
> Allegro will be different, certainly, but be prepared for some sort
> of similar complexities...
AllegroCL is different ...
CL-USER> (type-of *standard-input*)
TERMINAL-SIMPLE-STREAM
CL-USER> (type-of *standard-output*)
TERMINAL-SIMPLE-STREAM
CL-USER>
... but does handle standard-input and standard-output without
additional complexity.
Nice!
Thanks for the heads up on this, Rob!
Frank
--
Frank Goenninger
Bempflingen, Germany