Subject: communication via unix pipes

From: Alexander Vorobiev <[email-masked]>
Date: 25 Mar 1999 20:15:02 +0300

Hello, everybody!

I am trying to write a program (using clisp on linux) 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):

#!/usr/local/bin/clisp -q -C
(defvar *receiver-pathname* 
    (make-pathname :directory '(:absolute "dev" "fd") 
		   :name (car lisp:*args*)))

(defvar *sender-pathname* 
    (make-pathname :directory '(:absolute "dev" "fd") 
		   :name (cadr lisp:*args*)))

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

(read-header)  

Unfortunately, this didn't work:

*** - file #P"/proc/5395/fd/pipe:[1339598]" does not exist

Is it possible to make clisp deal with such "special" files properly?

Or maybe it is possible to avoid using /dev/fd/* files and to connect streams
directly to open file descriptors? 

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

Thanks in advance,
Alexander

---

From: Sam Steingold <[email-masked]>
Date: 25 Mar 1999 14:19:29 -0500

Privet!

First of all, I don't think I can help you with the particular problem
you are having.  I have no idea what can go wrong.  Nevertheless, I'd
think that the method you are using is not optimal.  Generally speaking,
file descriptors are so low-level things that I would be reluctant to
use them for communication between programs.

Also, by using /dev/fd/, you are limiting portability of your program to
modern unixes (basically, to Linux and Solaris :-).

 >> I am trying to write a program (using clisp on linux) which is
 >> supposed to run as a subprocess and communicate with its parent (big
 >> C program) through 2 unidirectional pipes. File descriptors of the

why use 2 pipes when you can use one socket?
you can even make the two program communicate via TCP/IP (and have them
running on different computers).

-- 
Sam Steingold (http://www.goems.com/~sds) running RedHat5.2 GNU/Linux
Micros**t is not the answer.  Micros**t is a question, and the answer is Linux,
(http://www.linux.org) the choice of the GNU (http://www.gnu.org) generation.
Never trust a man who can count to 1024 on his fingers.

---

From: Alexander Vorobiev <[email-masked]>
Date: 26 Mar 1999 16:55:41 +0300

Hi!

> you are having.  I have no idea what can go wrong.  Nevertheless, I'd

btw acl5/linux trial edition has no problems with opening /dev/fd/*
files - the resulting stream is an instance of a subclass of
terminal-stream. Does clisp have something like that?

> use them for communication between programs.

Unfortunately I cannot change parent program - I just have the
communication protocol specs I have to obey
 
> modern unixes (basically, to Linux and Solaris :-).

It's ok ;) Wouldn't it be a good idea to have some low-level tools to
facilitate systems programming?  I think that unlike some scheme
implementations (guile), this tools should be integrated into
high-level lisp concepts (class/conditions hierarchies etc). 

For example in acl it is possible to specify unix file descriptors as
arguments to 'open'

> running on different computers).

If I could choose means of communication I would definitely use corba (ilu)
- it's amazing! pity that clisp does not have corba bindings yet.

Alexander

-- 
It's not just a language, it's an adventure.  Common Lisp.

---

From: Sam Steingold <[email-masked]>
Date: 26 Mar 1999 14:54:27 -0500

>>>> In message <[email-masked]>
>>>> On the subject of "Re: communication via unix pipes"
>>>> Sent on Fri, 26 Mar 1999 05:56:54 -0800 (PST)
>>>> Honorable Alexander Vorobiev <[email-masked]> writes:
 >> 

I can do that - but I am afraid that Bruno will (rightfully!) kill me
for that when he comes back from his vacation.

 >> - it's amazing! pity that clisp does not have corba bindings yet.

you are welcome to write it.

-- 
Sam Steingold (http://www.goems.com/~sds) running RedHat5.2 GNU/Linux
Micros**t is not the answer.  Micros**t is a question, and the answer is Linux,
(http://www.linux.org) the choice of the GNU (http://www.gnu.org) generation.
Don't hit a man when he's down -- kick him; it's easier.

---

From: Bruno Haible <[email-masked]>
Date: Tue, 30 Mar 1999 19:59:08 +0200 (MET DST)

> *** - file #P"/proc/5395/fd/pipe:[1339598]" does not exist

That's because these symlinks in /proc/self/fd/ are really faked. They
point into void. And unfortunately clisp tries to follow the link,
in order to get the absolute pathname of the "file", for the benefit
of the function `truename'.

> Is it possible to make clisp deal with such "special" files properly?

Instead of special casing them, clisp should be changed to treat symlinks
pointing into void like regular files, and let the OS give an error if
needed.

> directly to open file descriptors? 

Trying to open /dev/fd/* files is perfectly ok; file descriptors as numbers
are a Unix specific hack.

> ffi tools to convert data for transmitting to/from parent process

`read-integer' and `write-integer' will be your friends (present in recent
clisp snapshots). If you want to write portable programs, open the
stream with   :element-type '(unsigned-byte 8)   and use `read-byte' and
`write-byte'.

> - it's amazing! pity that clisp does not have corba bindings yet.

Yes, really. The spec for CORBA bindings is already there, thanks to
Franz and Harlequin. See
   ftp://ftp.omg.org/pub/docs/orbos/98-10-16.ps
   ftp://ftp.omg.org/pub/docs/orbos/98-10-16.pdf

You have the choice between ILU and MICO.

                 Bruno

! To unsubscribe from the clisp-list mailing list, send mail to     !
!                    [email-masked]                        !
! including the two words "unsubscribe clisp-list" as message body. !