Port files enable communication between processes regardless of whether those processes reside on a single host or on separate hosts in a local area network or wide area network. There are several different environments, known as port providers, available on your system, which provide port file capabilities. Examples of port providers are BNA Version 2, Open Systems Interconnection (OSI), and Transmission Control Protocol/Internet Protocol (TCP/IP). However, even if none of these port providers are installed on a host, applications on the host can still use port files to communicate with applications on the same host.
Port files have been implemented to provide the applications programmer with a single interface that can be used to communicate within a single host or across all the types of multihost networks supported by MCP systems. However, the programmer can choose among any of several different port services with varying functionality. Each type of port provider supports one or more of these port services. A port service that is available from most port providers is BASICSERVICE. Port file applications using BASICSERVICE can run with little or no modification on BNA Version 2, OSI networks, or a single host that is not part of any network.
The following languages support port file functionality: ALGOL, COBOL74, COBOL85 FORTRAN77, and Pascal. Other languages that support files also access port files; however, for these languages, full support of port file statements might not be available.
A port file consists of one or more distinct communication paths, or subfiles, that are grouped under a common name. Individual subfiles are identified by way of the port file name and a number called the subfile index. You can specify the number of subfiles associated with a port file by using the MAXSUBFILES file attribute. On systems running BNA Version 2 or TCP/IP, you can establish differing priorities for the subfiles using the DIALOGPRIORITY file attribute.
Before opening a subfile, the application can assign several file attributes that help the system to identify the matching port subfile. These file attributes include FILENAME, which specifies the name of the port file; MYNAME, which must match the YOURNAME file attribute of the matching port subfile; and YOURHOST, which specifies the host where the matching process is running. Other attributes can be used to restrict access to processes having specified usercodes.
An application can use any of several OPEN statement options to specify whether the process waits for a matching process to appear or continues execution immediately. If the process continues execution, it can either abandon the open operation or leave the subfile in an offered state, ready for the matching process to link to it.
Each subfile consists of an input queue, from which the process reads, and an output queue, to which the process writes. Messages are processed through each queue on a first-in, first-out basis, so they always reflect the chronological order in which they were transmitted. The system provides the event-valued file attributes INPUTEVENT and OUTPUTEVENT to inform the process of activity in the input and output queues.
The process can write messages to individual subfiles, or can use a broadcast write statement, which sends the same message to all the subfiles in a port file. Similarly, a process can read messages from a specific subfile, or use a nonselective read statement, which reads a message from any one of the subfiles with waiting input.
For a complete explanation of how to use port files, refer to the I/O Subsystem Programming Guide.
The following subsections provide simple examples of port file programs written in COBOL74 and ALGOL.
COBOL74 Port File Example
The following COBOL74 program declares a port file called MSSR with three subfiles. This program runs on host SFA15CD and opens the port file with MYNAME = MASTER and YOURHOST = SF59D. The program opens the port and broadcasts a message to all subfiles. The program then performs a nonselective operation read to determine which of the remote processes responded first. It sends a message to the remote process that responded first and a different message to the other remote processes. A “USE AFTER ERROR” procedure causes the program to display a message after any I/O error. Note that this program should be initiated after the three matching processes have been initiated and have attempted to open their subfiles.
*COBOL74 READ/WRITE PROGRAM USING BNA OPTIONS.
*THIS PROGRAM RUNS ON HOST SFA15CD.
IDENTIFICATION DIVISION.
PROGRAM-ID. COBOL74-PORTFILE-DEMO2.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MSSR ASSIGN TO PORT
ACTUAL KEY IS MSSR-KEY
FILE STATUS IS MSSR-STATUS.
DATA DIVISION.
FILE SECTION.
FD MSSR.
01 MSSR-REC PIC X(17).
WORKING-STORAGE SECTION.
01 MSSR-WS.
05 MSSR-STATUS PIC XX.
05 MSSR-KEY PIC 9 COMPUTATIONAL.
PROCEDURE DIVISION.
DECLARATIVES.
IO-ERROR SECTION.
USE AFTER ERROR PROCEDURE ON I-O.
IO-ERROR-HANDLER.
DISPLAY “I/O ERROR ENCOUNTERED”.
DISPLAY “STATUS IS “, MSSR-STATUS.
END DECLARATIVES.
THE-PROGRAM SECTION.
INITIALIZATION.
CHANGE ATTRIBUTE MAXSUBFILES OF MSSR TO 3.
CHANGE ATTRIBUTE MYNAME OF MSSR TO “MASTER.”.
*COBOL74 APPLIES THE FOLLOWING ASSIGNMENTS TO ALL SUBFILES.
CHANGE ATTRIBUTE YOURNAME OF MSSR(0) TO “SERVANT.”.
CHANGE ATTRIBUTE YOURHOST OF MSSR(0) TO “SF59D.”.
OPEN-THE-PORT.
MOVE 0 TO MSSR-KEY.
OPEN I-O MSSR.
BROADCAST-THE-MESSAGE.
MOVE 0 TO MSSR-KEY.
MOVE “SEND ME A MESSAGE” TO MSSR-REC.
WRITE MSSR-REC.
GET-A-MESSAGE.
MOVE 0 TO MSSR-KEY.
READ MSSR.
DISPLAY “MESSAGE RECEIVED FROM SUBFILE “, MSSR-KEY.
DISPLAY MSSR-REC.
SEND-A-MESSAGE.
* THE ACTUAL KEY AT THIS POINT CONTAINS THE SUBFILE
* FROM WHICH THE MESSAGE WAS REMOVED IN THE LAST
* READ STATEMENT.
MOVE “YOU WIN” TO MSSR-REC.
WRITE MSSR-REC.
CLOSE-THE-WINNING-SUBFILE.
CLOSE MSSR.
* READ THE MESSAGES FROM THE LOSING SUBFILES.
PERFORM GET-A-MESSAGE.
PERFORM GET-A-MESSAGE.
BROADCAST-A-MESSAGE-TO-LOSERS.
MOVE “YOU LOSE” TO MSSR-REC.
MOVE 0 TO MSSR-KEY.
WRITE MSSR-REC.
CLOSE-THE-LOSERS.
CLOSE MSSR.
STOP RUN.ALGOL Port File Example
The following ALGOL program is designed to communicate with the preceding COBOL74 program. If three instances of this program are initiated, they will each communicate with one of the subfiles declared in the COBOL74 program. This ALGOL program runs on host SF59D and opens a port file called MSSR with a single subfile, and with MYNAME = MASTER and YOURHOST = SFA15CD. The program reads the message broadcast from the COBOL74 program, sends a reply, and then reads another message from the COBOL74 program. The read and write statements are handled by the procedures READIT and WRITEIT, which use complex wait statements to monitor the status of the subfiles used.
% COMPLEMENTARY ALGOL PROGRAM FOR READ/WRITE TO A PORT FILE.
% THIS PROGRAM IS TO BE EXECUTED ON HOST “SF59D”.
BEGIN
FILE MSSR (KIND = PORT, MAXSUBFILES = 1, MAXRECSIZE = 17,
MYUSE = IO, UNITS = CHARACTERS, MYNAME = “SERVANT.”,
YOURNAME=“MASTER.”, YOURHOST = “SFA15CD.”);
EBCDIC ARRAY INMSS[1:17],OUTMSS[1:14];
BOOLEAN RSLT;
INTEGER INT;
PROCEDURE ABORT(REASON);
STRING REASON;
BEGIN
DISPLAY (REASON);
MYSELF.STATUS:= VALUE(TERMINATED);
END;
PROCEDURE READIT;
BEGIN
INTEGER EVNT;
EVNT:= WAIT ((120),MSSR.CHANGEEVENT,MSSR.INPUTEVENT);
CASE EVNT OF
BEGIN
1: ABORT (“TIME LIMIT ELAPSED - NO MESSAGE RECEIVED”);
2: CASE MSSR.FILESTATE OF
BEGIN
VALUE(BLOCKED):VALUE(DEACTIVATIONPENDING):
VALUE(OPENED): VALUE(SHUTTINGDOWN):
IF HAPPENED (MSSR.INPUTEVENT) THEN
RSLT:= READ (MSSR,17,INMSS)
ELSE ABORT (“NO MESSAGE RECEIVED”);
ELSE: ABORT (“BAD FILESTATE”);
END;
3: RSLT:= READ (MSSR,17,INMSS);
END;
IF RSLT THEN ABORT (“MESSAGE MISCARRIED”)
ELSE DISPLAY (INMSS);
END READIT;
PROCEDURE WRITEIT;
BEGIN
INTEGER EVNT;
EVNT:= WAIT ((120),MSSR.CHANGEEVENT,MSSR.OUTPUTEVENT);
CASE EVNT OF
BEGIN
1: ABORT (“TIME LIMIT ELAPSED - NO ROOM TO WRITE”);
2: CASE MSSR.FILESTATE OF
BEGIN
VALUE(BLOCKED): VALUE(OFFERED): WRITEIT;
VALUE(OPENED): IF HAPPENED (MSSR.OUTPUTEVENT) THEN
RSLT:= WRITE(MSSR,14,OUTMSS);
ELSE: ABORT (“BAD FILESTATE”);
END;
3: RSLT:= WRITE (MSSR,14,OUTMSS);
END;
IF RSLT THEN ABORT (“WRITE MISCARRIED”);
END WRITEIT;
IF (INT:= OPEN (MSSR)) NEQ 1 THEN
ABORT(“UNABLE TO OPEN SUBFILE”);
READIT;
REPLACE OUTMSS BY “REMOTE MESSAGE”;
WRITEIT;
READIT;
CLOSE (MSSR);
END.
