[fpc-pascal] Unbuffering I/O
Marc Santhoff
M.Santhoff at t-online.de
Wed Aug 29 21:27:51 CEST 2018
On Wed, 2018-08-29 at 15:01 +0000, Mark Morgan Lloyd wrote:
> I've got two programs intended to be functionally identical, one in Perl
> and the other in FPC. They read a unix-domain datagram, decode the
> message, and emit output; if this goes to a file then it's reasonable to
> monitor it using tail -f
>
> Perl has a variable that you can set to force output to be unbuffered,
> with the result that as soon as a message is output it's in the file in
> its entirety.
>
> Is there an equivalent for Pascal, or should I be using something like
> fpSync(stdout) at opportune times?
I don't know if it really helps, but since I fiddled with a similar topic:
FreeBSD has stdio channel non blocking by default. I had some problems with
that and did this:
procedure SwitchFdBlocking(var channel: Text);
var
res: cint;
begin
res := fpfcntl(TextRec(channel).Handle, F_GETFL);
if ((O_NONBLOCK AND res)>0) then
begin
res := res AND (NOT O_NONBLOCK);
res := fpfcntl(TextRec(channel).Handle, F_SETFL, res);
if (res=-1) then writeln(stderr, 'ERROR on SETFL');
end;
end;
According to the man page of fcntl using the flag "O_DIRECT" instead of
"O_NONBLOCK" for switching of caching as far as possible. At least on FreeBSD
it is like this, check on Linux yourself...
--
Marc Santhoff <M.Santhoff at t-online.de>
More information about the fpc-pascal
mailing list