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
Named PIPEs
Re: Named PIPEs
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
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
-
- Aurora
- Posts: 970
- Joined: Tue Dec 17, 2013 1:17 pm
Re: Named PIPEs
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.
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 Master
- Posts: 2893
- Joined: Sun Nov 28, 2010 4:51 pm
- Location: Stone, United Kingdom
- Contact:
Re: Named PIPEs
I just used to pass a string to signify the end of data - eg *!PIPE_END!*
Rich Mellor
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module - add a USB printer to your QL
Also Involved in:
Icephorm
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module - add a USB printer to your QL
Also Involved in:
Icephorm