Named pipes

David T. Lewis lewis at mail.msen.com
Sat Dec 31 23:41:24 UTC 2005


On Sat, Dec 31, 2005 at 04:47:47PM -0000, Bob.Cowdery at CGI-Europe.com wrote:
> I have posted a few messages concerning named pipes without any response so
> I guess people just don't use them. I have managed to figure out the issues
> so far and all turned out to be my mistake. Unfortunately I now have some
> issues reading (rather than writing which works fine now).
> 
> On the experiments I have done the following seems to be the case.
> 
> 1. As Squeak is single threaded reading an empty pipe locks up Squeak. This
> was not unexpected and I need to be able to do a fcntl(stream,
> fcntl.F_SETFL, os.O_NDELAY). But I don't know how to do this in Squeak. I
> would also want to run this in a separate thread and AsyncFile looks useful
> for this.

Load OSProcess from Squeak Map.
Make a named pipe called 'FIFO'.
In Squeak, open the named pipe as a file stream:

  namedPipe := FileStream fileNamed: 'FIFO'.

Set nonblocking:

  OSProcess accessor setNonBlocking: namedPipe fileID.

Read from the pipe without blocking (answers an empty string):

  namedPipe next: 10000

As you have noticed, a blocking read will hang your Squeak VM if no
data is available. But note that on Linux you can break things loose
by going to /proc/<squeakPID>/fd/ and writing to whatever file
descriptor is waiting for the data. This is handy if you have locked
up Squeak and don't want to lose your work.

If you set the file descriptor non-blocking with #setNonBlocking:, it
will not hang up the VM. A read will give you the available data
(possible an empty string if no data is ready).

See also AioPlugin on Squeak Map for buffered event-driven input from
a non-blocking file stream.

Dave




More information about the Squeak-dev mailing list