Named PIPEs

Anything QL Software or Programming Related.
Post Reply
Martin_Head
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Named PIPEs

Post by Martin_Head »

Is there a way to test if a named PIPE in SMSQ/E is empty? EOF does not seem to work.

Also how do you empty a PIPE, or ensure it is empty, If there is nothing in it you want. Closing and re opening does not seem to empty it. The only idea I have had is to run a loop reading it.

If #4 is the open pipe

REP loop
a$=INKEY$(#4)
IF a$="" THEN EXIT loop
END REP loop


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Named PIPEs

Post by tofro »

Martin,

EOF or EOFW on a pipe actually indicate EOF only when the other end of the pipe has been closed.

In unexpanded S*Basic, using INKEY$ in a loop (albeit with a small timeout) seems to be the only way to do what you want. (I'm assuming you want a non-blocking read).

Tiny toolkit has a function PEND that exactly does what you want - returning 1 if there's nothing to read or 0 if there is something (without blocking).

DIY toolkit issue "P" has a function Q_COUNT% that returns the number of bytes available in a pipe

Pipes are one of the device types that could actually benefit a lot from a "read from channel in a buffer as much as is there until buffer full and return #of bytes read" - Function like fread() in C, which is unfortunately not implemented in S*BASIC. This would be a direct call to IO.FBYTES

With regards to emptying a pipe I see no other way than to do INKEY$ in a loop.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Martin_Head
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Re: Named PIPEs

Post by Martin_Head »

Thanks for that.

I am running a loop, where I need the pipe to be empty at the start of each loop. So I think I will just do the small INKEY$ loop at the start of each main loop.


RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: Named PIPEs

Post by RWAP »

I just used to pass a string to signify the end of data - eg *!PIPE_END!*


Post Reply