[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference clt::vax_basic

Title:Discussions on VAX BASIC
Notice:See Topic 1779 for latest kit info
Moderator:EPS::VANDENHEUVEL
Created:Sat Jan 25 1986
Last Modified:Tue May 13 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1798
Total number of notes:7362

444.0. "Puts to a Mailbox" by BMT::COMAROW (Resource wait state) Thu Dec 10 1987 14:33

T.RTitleUserPersonal
Name
DateLines
444.1Try thisDOULOS::HOBDAYKen Hobday -- CLTFri Dec 11 1987 15:0979
444.2Fixed a small bug in Read_mailboxSHARE::LEMONSAnd we thank you for your support.Thu Aug 25 1988 19:2580
444.3need example on use of mailboxHANDVC::STEVELIUTue Mar 04 1997 06:4014
    
    when I run the example in .2, I got run error.
    
    Maybe there is no readmefirst for me to show me how to use the program
    properly.
    
    what I need is a BASIC program which employ mailbox to demo its use
    and some instructions on how to use it. please advise.
    
    steve
    
    
    
    
444.4from STARSGIDDAY::GILLINGSa crucible of informative mistakesTue Mar 04 1997 21:07179
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.