Next: , Previous: , Up: Reading Files   [Contents][Index]


4.12 Retrying Reads After Certain Input Errors

This section describes a feature that is specific to gawk.

When gawk encounters an error while reading input, by default getline returns -1, and subsequent attempts to read from that file result in an end-of-file indication. However, you may optionally instruct gawk to allow I/O to be retried when certain errors are encountered by setting a special element in the PROCINFO array (see section Built-in Variables That Convey Information):

PROCINFO["input_name", "RETRY"] = 1

When this element exists, gawk checks the value of the system (C language) errno variable when an I/O error occurs. If errno indicates a subsequent I/O attempt may succeed, getline instead returns -2 and further calls to getline may succeed. This applies to the errno values EAGAIN, EWOULDBLOCK, EINTR, or ETIMEDOUT.

This feature is useful in conjunction with PROCINFO["input_name", "READ_TIMEOUT"] or situations where a file descriptor has been configured to behave in a non-blocking fashion.