Accessing Files Programmer's Guide (32650-90885)

18 Chapter2
Creating A File
The HPFOPEN Intrinsic
The HPFOPEN Intrinsic
The HPFOPEN intrinsic establishes access to a disk or device file and enables you to create a
file on a shareable device. HPFOPEN is used to define a file's physical characteristics,
including file and record structure. Its syntax is
HPFOPEN (
filenum
,
status
, [,
itemnum
,
item
]...);
The HPFOPEN optional parameters are a superset of the options provided in the FOPEN
intrinsic and provide more efficient access to files.
NOWAIT I/O
Sometimes a programmer wants an application to read or write a record, but does not
want it to wait for I/O to complete. For such an application, waiting is wasting time when it
could be doing other processing. Timeouts do not adequately address this problem. The
programmer wants this application to start an I/O, continue processing immediately, and
check periodically to see if the I/O has finished
MPE/iX provides a way to solve this problem with NOWAIT I/O. This feature is requested
by enabling the NOWAIT I/O option (item #16) in HPFOPEN.
When using NOWAIT I/O, the process must make at least two intrinsic calls to perform the
I/O, one to start it and one to finish it. MPE/iX still handles the file in the same way; but
instead of waiting for the I/O to complete, MPE/iX returns control to the application so that
the application can do some useful processing.
NOWAIT I/O has been available to users of standard files for a long time, but to use it on
standard files requires privileged mode. On standard files the mechanics of NOWAIT I/O
prevent MPE/iX from protecting a process from corrupting its own stack; however, because
message files work differently, NOWAIT I/O on message files does not require privileged
mode.
NOWAIT I/O intrinsics
To perform a NOWAIT I/O, the FREAD or FWRITE intrinsic must be called to initiate the
transfer. These intrinsics return immediately, and no data is transferred yet. The return
value for FREAD is set to zero and is not needed. To complete the transfer, either
IODONTWAIT or IOWAIT must be called. IODONTWAIT tests whether the I/O has finished. If it
has, the intrinsic returns a condition code of CCE and the file number as the return value.
If the I/O has not completed, CCE and a zero return value are passed back. If IOWAIT is
called, it waits until the I/O has finished, like a normal WAIT I/O FREAD or FWRITE.
Only one NOWAIT I/O can be outstanding against a file by a particular accessor at a time;
however, an accessor can have NOWAIT I/Os outstanding against several files at the same
time. These I/Os can be completed by a "generalized" IODONTWAIT or IOWAIT: the file
number parameter is zero or is omitted. In this case, these intrinsics report on the first I/O
to complete, returning the file number for that file. If the call to one of these intrinsics is in
a loop, then that one call can be used to complete all the NOWAIT I/Os.