[fpc-pascal] Unbuffering I/O

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Thu Aug 30 12:57:21 CEST 2018


On 30/08/18 10:15, Henry Vermaak wrote:
> On Thu, Aug 30, 2018 at 09:45:00AM +0000, Mark Morgan Lloyd wrote:> On 30/08/18 09:00, Henry Vermaak wrote:> >On Thu, Aug 30, 2018 at 07:52:54AM +0200, Martin Schreiber wrote:> > >In order to flush textfiles automatically I use> ">  ttextrec(<thefile>).flushfunc:= ttextrec(<thefile>).inoutfunc;> "> after it is opened.> > >Reading text.inc this morning lead me to believe this is the correctway.  This is what the RTL does when opening serial devices inFileOpenFunc(), for example.  There's a comment inside Flush() that saysthat InOutFunc() should be used to flush, since the FlushFunc() may notbe assigned.> > I've just checked this and unfortunately it doesn't do very much for the> standard device (?) used by WriteLn() etc., i.e. as would be used for a> quick-and-dirty program.
> It definitely works for me.  I made a program flush.pas that looks like this:
> begin	ttextrec(output).flushfunc := ttextrec(output).inoutfunc;	writeln('hi there');	sleep(1000);end.
> Running `./flush > out.txt` and `tail -F out.txt` shows the outputimmediately, while removing the flushfunc assignment causes a delay of asecond before the output appeared in the file.

Ah yes, that's it, thanks very much.

       WriteLn(StdErr, Format('# Socket %s, clock resolution %8.6f 
uSec', [socketName, ts.tv_nsec / 1000]));
     ttextrec(StdErr).flushfunc:= ttextrec(StdErr).inoutfunc;
     while true do begin
       ttextrec(Output).flushfunc:= ttextrec(Output).inoutfunc;
       i := fprecv(client, @buff, 1024, 0);

Basically, I was getting confused by the lack of "Error" etc., hence the 
different names.

I note this works the same for both  tail -f  and  tail -F  which have 
slightly different ways of looking to see if the input file has changed.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list