How do I flush a pipe under Windows ?

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

How do I flush a pipe under Windows ?

Post by Matthias Gemuh »

How do I flush a pipe under Windows ?

My GUI talks to child processes using pipes. I write into them using WriteFile(Handle, ...);
How can I flush such output pipes ?

Matthias.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How do I flush a pipe under Windows ?

Post by hgm »

Not sure what exactly you mean. The pipe must drain because the process at the other end reads what is queued in there. There is no way you can hasten that.

If you want to 'recall' what you wrote into the pipe, because you somehow regret it, you can keep a read handle to the pipe open in the sender process, and let it read back its own output. If a pipe as more readers, they fight for the data, and what one gets, the other one won't.
User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

Re: How do I flush a pipe under Windows ?

Post by Matthias Gemuh »

hgm wrote:Not sure what exactly you mean. The pipe must drain because the process at the other end reads what is queued in there. There is no way you can hasten that.

If you want to 'recall' what you wrote into the pipe, because you somehow regret it, you can keep a read handle to the pipe open in the sender process, and let it read back its own output. If a pipe as more readers, they fight for the data, and what one gets, the other one won't.
The internet is full of statements that the output pipe can be flushed, so that its contents are available for reading a bit earlier.

As you say it's not possible, I'll take your word for it.

Thanks,
Matthias.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
Robert Pope
Posts: 567
Joined: Sat Mar 25, 2006 8:27 pm
Location: USA
Full name: Robert Pope

Re: How do I flush a pipe under Windows ?

Post by Robert Pope »

How about fflush() or _flushall()?
wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 5:03 pm
Location: British Columbia, Canada

Re: How do I flush a pipe under Windows ?

Post by wgarvin »

Matthias Gemuh wrote:The internet is full of statements that the output pipe can be flushed, so that its contents are available for reading a bit earlier.
That is probably of interest only for remote pipes (over a network connection). Flushing the output pipe causes it to send the data in the buffer, otherwise it might sit around for a short delay for efficiency reasons. For local pipes it probably has no effect.

Anyway, you coud try the FlushFileBuffers function, as mentioned near the bottom of this article.
User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How do I flush a pipe under Windows ?

Post by hgm »

Just to be clear: you can flush the _buffer_ that is holding data to go into the pipe, if you use buffered output. (And indeed, when you do not do that in GUI or engine, things come to a halt very quickly.) It transfers the data from the buffer to the pipe. I would not call that "flushing the pipe", and I don't think you meant that.
User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

Re: How do I flush a pipe under Windows ?

Post by Matthias Gemuh »

hgm wrote:Just to be clear: you can flush the _buffer_ that is holding data to go into the pipe, if you use buffered output. (And indeed, when you do not do that in GUI or engine, things come to a halt very quickly.) It transfers the data from the buffer to the pipe. I would not call that "flushing the pipe", and I don't think you meant that.
That is what I meant :lol: .
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How do I flush a pipe under Windows ?

Post by hgm »

If you did not do that already, how could ChessGUI possibly have worked?
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: How do I flush a pipe under Windows ?

Post by bob »

Robert Pope wrote:How about fflush() or _flushall()?
Or, as I do in Crafty, just use read()/write() which are, by standard, unbuffered. The engine-intf.html explanation in winboard/xboard covers this... Note that this is still a stream protocol, which means you may well not read everything that was sent from the remote end in one read() since large blocks get broken down into smaller packets, and a read() will read whatever is available, even if more is "on the way" from the remote end.
User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

Re: How do I flush a pipe under Windows ?

Post by Matthias Gemuh »

bob wrote:
Robert Pope wrote:How about fflush() or _flushall()?
Or, as I do in Crafty, just use read()/write() which are, by standard, unbuffered. The engine-intf.html explanation in winboard/xboard covers this... Note that this is still a stream protocol, which means you may well not read everything that was sent from the remote end in one read() since large blocks get broken down into smaller packets, and a read() will read whatever is available, even if more is "on the way" from the remote end.
I have been using ReadFile()/WriteFile() without bothering about buffering.
Now I will take a closer look.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de