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.
Thanks very much Dave. I figured most of it. The bit that got me was the IOHandle that setNonBlocking wanted was a fileID. I am actually reading audio sampled data in binary mode and get a nil when the pipe is empty.
Bob
*** Confidentiality Notice *** Proprietary/Confidential Information belonging to CGI Group Inc. and its affiliates may be contained in this message. If you are not a recipient indicated or intended in this message (or responsible for delivery of this message to such person), or you think for any reason that this message may have been addressed to you in error, you may not use or copy or deliver this message to anyone else. In such case, you should destroy this message and are asked to notify the sender by reply email.
On Sun, Jan 01, 2006 at 10:00:56AM -0000, Cowdery, Bob [UK] wrote:
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.
Thanks very much Dave. I figured most of it. The bit that got me was the IOHandle that setNonBlocking wanted was a fileID. I am actually reading audio sampled data in binary mode and get a nil when the pipe is empty.
FYI, the "IOHandle" nomenclature comes from the IOHandle package (on Squeak Map). This factors out the low level IO from the file stream and socket classes. If you had IOHandle loaded, the #setNonBlocking: would take an instance of IOHandle as its parameter, rather than the fileID. But I have not kept IOHandle up to date with recent Squeak versions, so don't try to load it.
Dave
squeak-dev@lists.squeakfoundation.org