How do I flush a pipe ?
- Matthias Gemuh
- Posts: 295
- Joined: Wed Jun 09, 2010 2:48 pm
- Contact:
How do I flush a pipe ?
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 GUI talks to child processes using pipes. I write into them using WriteFile(Handle, ...);
How can I flush such output pipes ?
Matthias.
Aided by engines, GMs can be very strong.
http://www.hylogic.de
http://www.hylogic.de
- kingliveson
- Posts: 1388
- Joined: Thu Jun 10, 2010 1:22 am
- Real Name: Franklin Titus
- Location: 28°32'1"N 81°22'33"W
- Matthias Gemuh
- Posts: 295
- Joined: Wed Jun 09, 2010 2:48 pm
- Contact:
Re: How do I flush a pipe ?
I casted a handle to a stream pointer to use with fflush(), but it did not work.kingliveson wrote:Have you explored fflush?
Anyway, HGM says a pipe cannot be flushed.
Matthias.
Aided by engines, GMs can be very strong.
http://www.hylogic.de
http://www.hylogic.de
-
- Posts: 1242
- Joined: Thu Jun 10, 2010 2:13 am
- Real Name: Bob Hyatt (Robert M. Hyatt)
- Location: University of Alabama at Birmingham
- Contact:
Re: How do I flush a pipe ?
The "pipe" part is irrelevant. The "buffer" is in the C library code. That's where you get into trouble. Easiest way to deal with this is to simply use read()/write() as I do in Crafty. They are, by standard, unbuffered. Which means that as soon as you do a write, the data is "on its way" to the final destination. It doesn't sit in a C library buffer until the buffer is filled, before it is sent. The engine-intf.html document explains that in detail.Matthias Gemuh wrote:I casted a handle to a stream pointer to use with fflush(), but it did not work.kingliveson wrote:Have you explored fflush?
Anyway, HGM says a pipe cannot be flushed.
Matthias.
- kingliveson
- Posts: 1388
- Joined: Thu Jun 10, 2010 1:22 am
- Real Name: Franklin Titus
- Location: 28°32'1"N 81°22'33"W
Re: How do I flush a pipe ?
Ok, I just read what HGM said and don't think he is saying a pipe cannot be flushed. I think as Prof. Hyatt pointed out, you are not targeting the key area, the buffer. Using read()/write() is probably best trying to redirect output in this case, as it is more efficient -- if I understand correctly what you're trying to do . See MSDN FlushFileBuffers note below:hyatt wrote:The "pipe" part is irrelevant. The "buffer" is in the C library code. That's where you get into trouble. Easiest way to deal with this is to simply use read()/write() as I do in Crafty. They are, by standard, unbuffered. Which means that as soon as you do a write, the data is "on its way" to the final destination. It doesn't sit in a C library buffer until the buffer is filled, before it is sent. The engine-intf.html document explains that in detail.Matthias Gemuh wrote:I casted a handle to a stream pointer to use with fflush(), but it did not work.kingliveson wrote:Have you explored fflush?
Anyway, HGM says a pipe cannot be flushed.
Matthias.
Typically the WriteFile and WriteFileEx functions write data to an internal buffer that the operating system writes to a disk or communication pipe on a regular basis. The FlushFileBuffers function writes all the buffered information for a specified file to the device or pipe.
Due to disk caching interactions within the system, the FlushFileBuffers function can be inefficient when used after every write to a disk drive device when many writes are being performed separately. If an application is performing multiple writes to disk and also needs to ensure critical data is written to persistent media, the application should use unbuffered I/O instead of frequently calling FlushFileBuffers. To open a file for unbuffered I/O, call the CreateFile function with the FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH flags. This prevents the file contents from being cached and flushes the metadata to disk with each write. For more information, see CreateFile.
PAWN : Knight >> Bishop >> Rook >>Queen
- Matthias Gemuh
- Posts: 295
- Joined: Wed Jun 09, 2010 2:48 pm
- Contact:
Re: How do I flush a pipe ?
I have been using WriteFile() without knowing that it buffers.kingliveson wrote: Typically the WriteFile and WriteFileEx functions write data to an internal buffer that the operating system writes to a disk or communication pipe on a regular basis. The FlushFileBuffers function writes all the buffered information for a specified file to the device or pipe.
Due to disk caching interactions within the system, the FlushFileBuffers function can be inefficient when used after every write to a disk drive device when many writes are being performed separately. If an application is performing multiple writes to disk and also needs to ensure critical data is written to persistent media, the application should use unbuffered I/O instead of frequently calling FlushFileBuffers. To open a file for unbuffered I/O, call the CreateFile function with the FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH flags. This prevents the file contents from being cached and flushes the metadata to disk with each write. For more information, see CreateFile.
That is why I was suspecting the buffer to be in the pipe.
Aided by engines, GMs can be very strong.
http://www.hylogic.de
http://www.hylogic.de
Re: How do I flush a pipe ?
1st and fore all: try the good old fashioned plunger! (this age-old remedy can often do wonders)
Drano (and/or Mr. Plumber) is quite good...but excercise caution and read the directions carefully if you have PVC.
otherwise: i highly recommend the help of an experienced professional...especially if the pipe is lead.
hope this helps...
Norm
Drano (and/or Mr. Plumber) is quite good...but excercise caution and read the directions carefully if you have PVC.
otherwise: i highly recommend the help of an experienced professional...especially if the pipe is lead.
hope this helps...
Norm
- Matthias Gemuh
- Posts: 295
- Joined: Wed Jun 09, 2010 2:48 pm
- Contact:
Re: How do I flush a pipe ?
What has a plumber got to do with what I smoke ?kranium wrote:1st and fore all: try the good old fashioned plunger! (this age-old remedy can often do wonders)
Drano (and/or Mr. Plumber) is quite good...but excercise caution and read the directions carefully if you have PVC.
otherwise: i highly recommend the help of an experienced professional...especially if the pipe is lead.
hope this helps...
Norm
Matthias.
Aided by engines, GMs can be very strong.
http://www.hylogic.de
http://www.hylogic.de
Re: How do I flush a pipe ?
http://www.pipesandcigars.com/pipecleaners.htmlMatthias Gemuh wrote: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.
- kingliveson
- Posts: 1388
- Joined: Thu Jun 10, 2010 1:22 am
- Real Name: Franklin Titus
- Location: 28°32'1"N 81°22'33"W
Re: How do I flush a pipe ?
From CCC:
You can accomplish read()/write() effect using FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH flags with WriteFile().Matthias Gemuh wrote:One last trial to explain it.
Windows offers only WriteFile() to write into a pipe.
(Obselete write functions do exist that work like WriteFile())
WriteFile() has an internal buffer that makes WriteFile() non-blocking.
Windows flushes that buffer depending on how full it is or how long data has been standing in it. This efficiency decision effectively steals time from any engine waiting at the other end of the pipe.
The internal WriteFile() buffer can be forcefully flushed with FlushFileBuffers() to eliminate delays, but that is blocking
PAWN : Knight >> Bishop >> Rook >>Queen