From: Alexander Vorobiev

Subject: communication with pipes

Date: 1999-3-24 14:05

Hello, everybody!

I am trying to write a program (using acl5/linux Trial Edition) which
is supposed to run as a subprocess and communicate with its parent
(big C program) through 2 unidirectional pipes. File descriptors of
the pipes are given to my program in command line. Information is
transmitted as 32-bit packets (unsigned long in C terminology).

The first thing i tried was to use /dev/fd/* files (as I know
appropriate file descriptors):

(defvar *sender-pathname* 
    (make-pathname :directory '(:absolute "dev" "fd") 
		   :name (sys:command-line-argument 2)))

(defconstant +header-size+ 4) ; I want to read a header of some big packet

(defvar *header* (make-array +header-size+ 
                             :element-type '(unsigned-byte 32)
			     :initial-element 0))
(defun read-header ()
  (with-open-file (sender *sender-pathname* 
		   :direction :input 
		   :element-type '(unsigned-byte 32))
    (read-sequence *header* sender)))

Unfortunately, this didn't work:

Warning: An error occurred
         (`CLOS::..SLOT-UNBOUND..' is not of the expected type `REAL') 
         during the reading or evaluation of -e "(read-header)" 


Further reading of documentation revealed that opening such "special" files 
produces streams that are instances of terminal-stream class so
changing (unsigned-byte 32) to character should theoretically solve
the problem. Now I have several questions:

What would be the best way of dealing with 32-bit unsigned long data
with such a character-based stream?  

Or would it be better to create some customized stream class? How to
do this in my case? I couldn't find any relevant examples in the
documentation. 

Is it possible to avoid using /dev/fd/* files and to connect streams
directly to open file descriptors? I know there are :fn-in and :fn-out 
parameters to open but how to use them properly without specifying
any file name? Create new stream class?

And the last question about C to lisp communication: should I use some 
tools from ffi package to convert data for transmitting to/from parent 
process written in C?

Thanks in advance,
Alexander

-- 
People who like this sort of thing will find this is the sort of thing
they like.
		Abraham Lincoln