bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] bug report on PROCINFO[,"READ_TIMEOUT"]


From: Andrew J. Schorr
Subject: Re: [bug-gawk] bug report on PROCINFO[,"READ_TIMEOUT"]
Date: Thu, 7 May 2015 15:47:30 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

Hi,

On Thu, May 07, 2015 at 02:26:08PM -0500, Alejandro Mendoza wrote:
> I just checked the ERRNO with this simple command:
> 
> awk 'BEGIN {infile="/dev/stdin"; PROCINFO[infile,"READ_TIMEOUT"]=2000;
> getline < infile; print "read: " $0; print "ERRNO: " ERRNO " \nnext..";
> $0=""; PROCINFO[infile,"READ_TIMEOUT"]="5000";getline <infile; print "ERRNO:
> " ERRNO; print "read2: " $0}'
> 
> I get the following:
> 
> read:
> ERRNO: Connection timed out
> next..
> ERRNO: Connection timed out
> read2:
> 
> So, I guessed the file (stdin) does not get closed, but is stuck in this
> state of timeout. Curiously, If I intentionally close it before the second
> read, I get the same ERRNO, but different return codes for getline. On the
> first, on the actual timeout, I get -1, on the second I get 0 (EOF) but
> ERRNO still as Connection timed out, so I guess ERRNO does not get updated:
> 
> awk 'BEGIN {infile="/dev/stdin";  PROCINFO[infile,"READ_TIMEOUT"]=2000;
> x=getline < infile; print "read: " $0; print "ERRNO: " ERRNO ", x= " x "
> \nnext.."; close(infile); $0="";
> PROCINFO[infile,"READ_TIMEOUT"]="5000";x=getline <infile; print "ERRNO: "
> ERRNO " x=" x; print "read2: " $0}'
> 
> I get:
> read:
> ERRNO: Connection timed out, x= -1
> next..
> ERRNO: Connection timed out x=0
> read2:

I haven't tested this lately, but I'm sure you're right.  In my opinion,
the READ_TIMEOUT capability is not terribly useful.  When the timeout
is encountered, I believe it returns an error and sets an internal
end-of-file flag.  So further reads cannot succeed.  And closing "/dev/stdin"
is not helpful.  Internally, that seems to map /dev/stdin to /dev/null,
so subsequent reads won't return anything.

As I said before, if you want to do this the right way, you'll need to
upgrade to the git master branch and then use the select extension
and/or the new retryable I/O features.

Why is READ_TIMEOUT actually useful?  I can't think of any usage cases
where it wouldn't be preferable to use select.  Maybe I'm missing something.

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]