Guardian Programmer's Guide

Table Of Contents
Using Nowait Input/Output
Guardian Programmer’s Guide 421922-014
4 - 4
Applying a Nowait Operation on a Single File
In this example, if the WRITEX call initiates just one I/O operation (as, for example,
when writing to an unstructured file), it returns immediately to the program. If the
WRITEX call initiates several I/O operations (as, for example, when writing to a key-
sequenced file that has alternate keys), then the program waits until the last I/O
operation starts. In either case, once control is returned to your program, the program
continues to execute until it reaches a call to the AWAITIOX procedure. Additional
attempts to initiate I/O operations on this file before the current I/O finishes will return
an error because only one I/O is permitted to run at a time.
You must complete the I/O operation at some point later in the program. The
AWAITIO[X] procedure gives you three ways you can do this, depending on the value
you assign to the timeout parameter:
Wait indefinitely until the I/O finishes. You do this by assigning -1D to the timeout
parameter or by omitting the timeout parameter. In this case, AWAITIO[X] waits
as long as it takes for the I/O to finish:
CALL AWAITIOX(FILENUM);
IF <> THEN ...
Specify a time limit for the I/O to finish. Set the timeout parameter to the number
of one hundredths of a second that your program will wait for the operation to
finish. Error 40 (operation timed out) is returned if the operation does not finish
within the time limit, and the operation is canceled.
LIMIT := 100D;
CALL AWAITIOX(F1,
!buffer^address!,
!count^transferred!,
!tag!,
LIMIT);
IF <> THEN ...
Return immediately to the program whether the I/O operation finishes or not. You
do this by setting the time limit to zero:
LIMIT := 0D;
CALL AWAITIOX(F2,
!buffer^address!,
!count^transferred!,
!tag!,
LIMIT);
This method effectively checks whether the I/O is finished and then returns. The
procedure call returns error 40 (operation timed out) if the I/O is not finished, but it
does not cancel the operation.
This example should be part of a loop that regularly checks for I/O completion.
Caution. When the file system cancels an operation due to timeout, it does not undo those
parts of the operation that have already finished. For example, in an operation that requires
multiple physical I/O operations, some of those operations may have finished and others may
not have finished.