I'm using Gawk 4.1.0, and it seems like it's working not as expected with TCP sockets.
BEGIN {
PROCINFO[server, "READ_TIMEOUT"] = 1000
for (i = 0; i < 10; i++) {
if ((server |& getline) > 0) {
print(">>", $0);
} else {
print(ERRNO);
}
}
}
It should be simple - I connect to localhost:12345, then read with timeout for 10 times.
What I expect to see is: 10 times a 1sec timeout if no data available, with corresponding ERRNO.
What I see is: once a 1sec timeout, then immediate loop iterations with no timeout.
I did some debugging, and seems like get_a_record() in io.c has the following check:
if (at_eof(iop) && no_data_left(iop))
return EOF;
Which is always true after the timeout, because IOP_AT_EOF flag is always set if select() returns -1 (which is select() error, e.g. timeout).
For my case I removed the line io.c:3351 (I'm talking about 4.1.0 sources form the tarball) and that helped.
I'm sure this will break other things in Awk, so could you please look for a proper solution?
Actually, maybe I just to it wrong? Are there any other ways to "poll" periodically for TCP sockets in a loop?
Regards,
Serge
--
"One must have a chaos inside oneself to give birth to a dancing star." - Thus Spoke Zarathustra