manuel-serrano / bigloo

a practical Scheme compiler
http://www-sop.inria.fr/indes/fp/Bigloo
Other
135 stars 19 forks source link

Functions for dealing with a named pipe (fifo) #31

Closed svenha closed 4 years ago

svenha commented 5 years ago

If I use append-output-file on an existing named pipe (fifo), the named pipe is just overwritten as a normal file. Can bigloo deal with named pipes?

manuel-serrano commented 4 years ago

I don't quite understand the problem. What about simply using open-output-file on your pipe? Is there a reason that prevent you from doing that?

svenha commented 4 years ago

open-output-file will delete the named pipe and open it as a regular file. But the named pipe is created outside the bigloo program and should be used by the bigloo program (and others). Maybe a solution could be as follows: append-output-file tests the file type and uses the appropriate C function if it is named pipe and not a regular file.

lassik commented 4 years ago

What system calls are open-output-file and append-output-file using?

manuel-serrano commented 4 years ago

It uses "open".

lassik commented 4 years ago

Interesting. Here's what POSIX says about open(): https://pubs.opengroup.org/onlinepubs/7908799/xsh/open.html

O_RDWR -- Open for reading and writing. The result is undefined if this flag is applied to a FIFO.

O_TRUNC -- If the file exists and is a regular file, and the file is successfully opened O_RDWR or O_WRONLY, its length is truncated to 0 and the mode and owner are unchanged. It will have no effect on FIFO special files or terminal device files. Its effect on other file types is implementation-dependent. The result of using O_TRUNC with O_RDONLY is undefined.

manuel-serrano commented 4 years ago

It seems to mean to open is okay to append on a fifo. Do you share this understanding?

lassik commented 4 years ago

I would assume that also. But @svenha's experience sounds like the OS does something different. Sven, which OS are you using?

svenha commented 4 years ago

@lassik , I am using Ubuntu Linux. I have a minimal example and found out that binary ports work with named pipes, but not normal ports. That is ok for me.

Terminal 1:

> mkfifo /tmp/npipe
> tail -f /tmp/npipe

Terminal 2:

> bigloo -eval '(define p (append-output-binary-file "/tmp/npipe")) (output-string p "def") (close-binary-port p)'
  ; shows def in Terminal 1
> bigloo -eval '(define p (append-output-file "/tmp/npipe")) (display "def" p) (close-output-port p) (quit)'
  ; fails
manuel-serrano commented 4 years ago

do you confirm that

bigloo -eval '(define p (openoutput-file "/tmp/npipe")) (display "def" p) (close-output-port p) (quit)'

works for you?

svenha commented 4 years ago

@manuel-serrano, yes. So, I should simply avoid append-output-file for fifos. I close this issue now.