Guardian Programmer's Guide

Table Of Contents
Using Nowait Input/Output
Guardian Programmer’s Guide 421922-014
4 - 12
Nowait I/O: An Example
Nowait I/O: An Example
The following example shows a complete working program that uses nowait I/O to time
out terminal response.
This example enhances the example given at the end of Section 2, Using the File
System. Whenever the program prompts the user to enter a value, a timer is started.
If the user does not respond to the prompt within five minutes, the user is logged off
and the program terminates.
Before prompting the user to select a function, the program checks whether the user is
logged on. If not, no prompt is issued and the program terminates. If the user is
logged on, then the program prompts the user to select a function.
The user is asked to log on when the program starts. The program uses a global
variable LOGGED^ON as a flag to indicate whether the user is logged on. After
successfully logging on, LOGGED^ON is set to 1. If the user fails to respond to any
prompt within the timeout period, then LOGGED^ON gets set to 0.
As with the example in Section 2, Using the File System, the data file to contain the log
must exist before the program is run. You can create this file using either the TACL
CREATE command or the FUP CREATE command. It is important that the file you
create is named in the appropriate call to the FILE_OPEN_ procedure in the program.
The code for this program appears on the following pages.
?INSPECT,SYMBOLS,NOMAP,NOCODE
?NOLIST, SOURCE $SYSTEM.ZSYSDEFS.ZSYSTAL
?LIST
LITERAL MAXFLEN = ZSYS^VAL^LEN^FILENAME; !maximum file-name
! length
LITERAL BUFSIZE = 512;
LITERAL WAIT^TIME = 30000D; !wait up to 5 minutes for
! input
STRING .SBUFFER[0:BUFSIZE]; !I/O buffer (one extra char)
STRING .S^PTR; !pointer to end of string
INT LOGNUM; !log file number
INT TERMNUM; !terminal file number
INT LOGGED^ON; !nonzero if someone is
! logged on
?NOLIST, SOURCE $SYSTEM.SYSTEM.EXTDECS0(INITIALIZER,
? PROCESS_GETINFO_,FILE_OPEN_,WRITEREADX,WRITEX,AWAITIOX,
? PROCESS_STOP_,READX,POSITION,DNUMOUT,FILE_GETINFO_,SETMODE)
?LIST