Jump to page titleUNITED STATES
hp.com home products and services support and drivers solutions how to buy
» contact hp

:

more options
 

hp.com home
End of Jump to page title
Example-PLI Using Mailboxes To Communicate Between Processes
Jump to content



» 

business support center

Home & Home Office Support:
» HP branded products
» Presario branded products
» Services & Warranties
Small & Medium Business Support:
» Small & Medium Business products
» Small & Medium Business services
Support for IT Professionals:
» Enterprise products (IT Resource Center)
» NonStop enterprise products
» Business & IT Services
Content starts here
Copyright (c) Digital Equipment Corporation 1991. All rights reserved
LAYERED PRODUCT:  VAX PLI V3.4          OP/SYS: VMS V5.4-2

SOURCE:     Digital Customer Support Center


OVERVIEW:

This example demonstrates how to communicate between 2 process using
a temporary mailbox.


*** CAUTION ***

This sample program has been tested using VAX PLI V3.4 on VMS VT5.4-3.
However, we cannot guarantee its effectiveness because of the possibility
of error 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 first program, READ_MB, demonstrates how to create a mailbox and
read from it.  It has uses an AST routine (second program called
MY_AST) to notify it that something has been written to the mailbox.
The third program WRITE_MB, writes to the mailbox.  A temporary
mailbox is used in this example.  It is automatically deleted when all
channels has been deassigned that were using it.

If you want to use the mailbox as a communication device for processes
in the same group, the logical name must be in the group logical name
table.  See the $define command below.  It should be issued for both
processes.  Each process must be from the same group UIC for this
example to work correctly.  Each process needs GRPNAM and TMPMBX
privileges to run the respective programs.

The two programs below should be extracted to a file called
READ_MB.PLI.  It  should be compiled, linked, and executed as follows:

$pli read_mb.pli
$link read_mb.obj
$define/table=LNM$PROCESS_DIRECTORY LNM$TEMPORARY_MAILBOX LNM$GROUP
$run read_mb.exe


PROGRAM:

read_mb:    procedure options(main);

       %include sys$crembx;
       %include sys$qio;
       %include sys$hiber;
       %include $iodef;
       %include $rmsdef;
       %include $stsdef;
       %include $ssdef;

       dcl my_ast external entry;

       dcl chan fixed bin(15),
           iosb(4)      fixed bin(15);

       dcl mes_len     fixed bin(31) init(80);
       dcl  func       bit(32);

       dcl 01 mes_buff union,
              02 message        character(80),
              02 mes_byte       fixed bin(7);

/* Create a Temporary Mailbox with the logical name TSTMBX
   Note that the mailbox logical name will be placed in the
   group-wide logical name table, LNM$GROUP, and will only be
   accessible to processes in the same group as the creator. */

       sts$value = sys$crembx(,chan, , , , ,
                       'TSTMBX');
       if ^sts$success then signal vaxcondition(sts$value);

/* Queue up a WRITE ATTENTION AST to the mailbox */

       func = io$_setmode | io$m_wrtattn;
       sts$value = sys$qiow(, chan,
                     func,
                     iosb, , ,
                     value(my_ast), , , , , );
       if ^sts$success then signal vaxcondition(sts$value);
       if iosb(1) ^=ss$_normal
              then signal vaxcondition(iosb(1));

/* Go to sleep waiting for the other process to write to the mailbox */

       sts$value = sys$hiber();
       if ^sts$success then signal vaxcondition(sts$value);

/* Have been awakened, Read the mailbox, put message out */

       func = io$_readvblk;
       sts$value = sys$qiow(, chan,
                     func,
                     iosb, , ,
                     message, mes_len, , , , );

       if ^sts$success
           then signal vaxcondition(sts$value);
       if iosb(1) ^= ss$_normal
           then signal vaxcondition(iosb(1));
/* Put message out */

       put skip(2) list('mailbox message: ',message);

       put skip list('program complete - terminating');
       end read_mb;

my_ast: procedure;

       %include $stsdef;
       %include sys$wake;

/* Wake up the parent */

       sts$value = sys$wake( , );
       if ^sts$success then signal vaxcondition(sts$value);

       end my_ast;


This program will write to the mailbox.  To run it, issue the following
commands from another session.  (Note: WRITE_MB should be run after
read_mb has started execution.)

$pli write_mb.pli
$link write_mb.obj
$define/table=LNM$PROCESS_DIRECTORY LNM$TEMPORARY_MAILBOX LNM$GROUP
$run write_mb.exe

write_mb: procedure;

       %include sys$qio;
       %include sys$assign;
       %include sys$crembx;
       %include $iodef;
       %include $stsdef;
       %include $ssdef;

       dcl mes_len      fixed bin(31) init(80);

       dcl chan fixed bin(15),
           iosb(4)      fixed bin(15);

       dcl message        character(80);

       dcl func           bit(32);

/* Create the mailbox, if nonexistent, and assign a channel to the mailbox */

      sts$value = sys$crembx(,chan, , , , ,
                       'TSTMBX');
       if ^sts$success then signal vaxcondition(sts$value);

/* Write to the mailbox */

       message = 'this is a mailbox message from a second process';
       func = io$_writevblk | io$m_now;
       sts$value = sys$qiow(, chan,
                     func,
                     iosb, , ,
                     message, mes_len, , , , );

       if ^sts$success
           then signal vaxcondition(sts$value);
       if iosb(1) ^= ss$_normal
           then signal vaxcondition(sts$value);

       end write_mb;





buy online or call 1.800.AT.COMPAQ
privacy statementusing this site means you accept its terms