| Example-BASIC How To Communicate Between Processes With Mailboxes
COPYRIGHT (c) 1988, 1993 by Digital Equipment Corporation.
ALL RIGHTS RESERVED. No distribution except as provided under contract.
Copyright (c) Digital Equipment Corporation 1987, 1989. All rights reserved
LAYERED PRODUCT: VAX BASIC V3.3 OP/SYS: VMS V5.1
SOURCE: Digital Customer Support Center
OVERVIEW:
This example shows how to create a temporary mailbox, read from a mailbox,
and write to a mailbox.
PROGRAM ORIGIN:
This example is modeled after an example taken from the VAX/VMS Education
Series, UTILIZING VMS FEATURES FROM VAX BASIC, BASIC Language Workbook,
(Nov 84).
CAUTION: This sample program has been tested using:
PRODUCT: VAX BASIC V3.3 on OPERATING SYSTEM: VMS V5.1
However, we cannot guarantee its effectiveness because of the possibility of
errors in transmitting or implementing it. It is meant to be used as a
template for writing your own program, and it may require modification for use
on your system.
PROGRAM NOTES:
The programs MAILS and MAILR must be run from two processes in the same
group. To run the programs, log in at one terminal, execute the DEFINE
command as explained below, and run one program. Then log onto another
terminal, execute the DEFINE command for that process and run the other
terminal.
Because both MAILS and MAILR use $CREMBX to create a temporary mailbox
with the logical name FOZZIE_BEAR (if no such mailbox exists) and assign
a channel to it, the programs can be run in any order. If MAILS had used
$CREMBX and MAILR had used $ASSIGN, for example, it would be necessary to
run MAILS first.
When you specify a logical name for a temporary mailbox, the $CREMBX
service enters the name into the LNM$TEMPORARY_MAILBOX logical name table.
Normally, LNM$TEMPORARY_MAILBOX specifies LNM$JOB, the job-wide logical
name table; thus, only processes in the same job as the process that first
creates the mailbox can use the logical name to access the temporary
mailbox. If you want to use the temporary mailbox to enable communication
between processes in different jobs, you must redefine LNM$TEMPORARY_
MAILBOX in the process logical name directory table (LNM$PROCESS_
DIRECTORY), to specify a logical name table that those processes can
access.
For instance, if you want to use the mailbox as a communication device for
processes in the same group, you must redefine LNM$TEMPORARY_MAILBOX to
specify LNM$GROUP, the group logical name table. The following DCL command
assigns temporary mailbox logical names to the group logical name table:
$DEFINE/TABLE=LNM$PROCESS_DIRECTORY LNM$TEMPORARY_MAILBOX LNM$GROUP
GRPNAM privilege is required for a program to place a logical name for a
mailbox in the group logical name table.
Because $QIOW is used for input and output rather than $QIO, both MAILS
and MAILR wait for I/O to complete before advancing to the next program
statement.
The P1 argument of $QIOW is the address of a buffer of ASCII text, not the
address of an ASCII string descriptor. Therefore, MESSGE and INPUT_STR
are declared as CHARACTER data and passed by reference using BY REF.
PROGRAM EXAMPLE:
! MAILR.BAS
!
! This process will read the mailbox created by
! MAILS. As soon as it reads the mailbox, MAILS
! can continue.
!
OPTION TYPE = EXPLICIT
EXTERNAL LONG FUNCTION sys$crembx, sys$qiow
EXTERNAL LONG CONSTANT io$_readvblk
DECLARE WORD stat_block(3%)
DECLARE LONG stat, channel
DECLARE STRING mailbox_name
MAP (str_map) STRING input_str=30%
!
mailbox_name = "FOZZIE_BEAR"
!
! Create mailbox and/or assign a channel to the mailbox
stat = sys$crembx(,channel,,,,,mailbox_name)
CALL lib$stop(stat BY VALUE) IF (stat AND 1%)=0%
!
! Read the mailbox
stat = sys$qiow(,channel BY VALUE,io$_readvblk BY VALUE, &
stat_block(0%),,,input_str BY REF, &
LEN(input_str) BY VALUE,,,,)
CALL lib$stop(stat BY VALUE) IF (stat AND 1%)=0%
CALL lib$stop(stat_block(0%) BY VALUE) IF &
(stat_block(0%) AND 1%) = 0%
!
! Output mailbox message
PRINT SEG$(input_str, 1% , stat_block(1%))
END
! MAILS.BAS
!
! This program will write to a mail box with the
! logical name Fozzie_bear. Since this is a synchronous
! operation, the write will not complete until the
! process MAILR reads the mailbox.
!
OPTION TYPE = EXPLICIT
EXTERNAL LONG FUNCTION sys$crembx, sys$qiow
EXTERNAL LONG CONSTANT io$_writevblk
DECLARE LONG stat, channel, length
DECLARE WORD stat_block(3%)
DECLARE STRING messge, mailbox_name
!
messge = "This is a message."
mailbox_name = "FOZZIE_BEAR"
!
! Create mailbox and/or assign a channel to it
stat=sys$crembx(,channel,,,,,mailbox_name)
CALL lib$stop(stat BY VALUE) IF (stat AND 1%)=0%
!
! Write a message to the mailbox
stat=sys$qiow(,channel BY VALUE,io$_writevblk BY VALUE, &
stat_block(0%),,,messge BY REF, &
LEN(messge) BY VALUE,,,,)
CALL lib$stop(stat BY VALUE) IF (stat AND 1%)=0%
CALL lib$stop(stat_block(0%) BY VALUE) IF &
(stat_block(0%) AND 1%)=0%
!
! Notify user
PRINT "MAILS has completed mailbox write."
END
RUNNING THE PROGRAM:
$ ! RUN FROM ONE TERMINAL
$
$ DEFINE/TABLE=LNM$PROCESS_DIRECTORY LNM$TEMPORARY_MAILBOX LNM$GROUP
$
$ BASIC MAILS
$ LINK MAILS
$ RUN MAILS
MAILS has completed mailbox write.
$ ! RUN FROM ANOTHER TERMINAL
$
$ DEFINE/TABLE=LNM$PROCESS_DIRECTORY LNM$TEMPORARY_MAILBOX LNM$GROUP
$
$ BASIC MAILR
$ LINK MAILR
$ RUN MAILR
This is a message.
|