| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | OS/2 Event utility? |
Hi David,
DC> I would like to echo the other response, can we see
DC> some examples please?
Ok, now I am back at the machine, here are 2 methods that could be used to
communicate between 2 different tasks using REXX under OS/2, instead of
using FLAG files. Using PIPES and QUEUES has one large advantage, OS/2 will
store any data that is "in transit" in a QUEUE or PIPE until the
recipient is able to read it. This is all stored "in memory" such
that a system re-boot does not leave any FLAG FILES lying around to tidy
up.
The first example uses QUEUES and will work with out-of-the-box OS/2
probably from V2.0 onwards, although I have only used it under Warp 3 and
4. This code was copied from existing code and simplified for a demo. I
have added plenty of comments to explain what happens... Watch out for line
wrapping in Fidonet messages!
======== QSERV.CMD ===========================================
/* REXX script to demonstrate handling of QUEUES. */
Say Date('S') Time() 'Queue Server Start...' /* Let us begin. */
Qname = "QDEMO" /* The name for this Queue. */
CurName = RxQueue("Get") /* Save original Queue name. */
ret = RxQueue("Delete", Qname) /* Ensure new one doesn't exist. */
ret = RxQueue("Create", Qname) /* Create the new one. */
If ret = CurName Then Do /* If Create failed. */
Say ' ERROR: Unable to create new Queue ['ret'].'
Say ' Failed to set up ['Qname'] Queue - Aborted.'
Exit 99
End
OldName = RxQueue("Set",Qname) /* Exchange Queues. */
Say Date('S') Time() 'Waiting for work...'
Do Forever /* The Main loop. */
If Queued() > 0 Then Do /* If there is something there. */
Pull cmd /* Remove entry from Queue. */
Say Date('S') Time() ' Received ['cmd'].' /* Report work. */
If cmd = 'X' | cmd = 'x' Then Leave /* Force an exit now? */
End
ret = SysSleep(1) /* Wait 1 second. */
End
NewName = RxQueue("Set",OldName) /* Restore default Queue. */
ret = RxQueue("Delete", Qname) /* Remove the one we used. */
Say Date('S') Time() 'Queue Server complete.'
==============================================================
======== QSEND.CMD ===========================================
/* REXX script to demonstrate sending messages to a QUEUE. */
Parm = 'Hello World' /* Just in case no ARG supplied. */
Qname = "QDemo" /* Define the Queue name. */
Parse Arg Parm /* Grab any ARG. */
OldName = RxQueue("Set",Qname) /* Save OLD name, set NEW name. */
Queue Parm /* Enque the new message. */
NewName = RxQueue("Set",OldName) /* Restore the default Queue. */
==============================================================
Because REXX as supplied with OS/2 does not provide a BLOCKING READ of a
QUEUE, SysSleep(1) is useful to prevent heavy resource usage, however REXX
QUEUES are very light on the resource anyway, so the effect is minimal. To
implement a BLOCKING read of a QUEUE, you would need to use one of the
DLL's suggested for PIPES below. Using such a DLL you can also add the
capability to look through everything that has arrived in a QUEUE, and pick
individual messages out, you dont have to read the records in any
particular sequence, QUEUES can be read FIFO or LIFO, or even change
direction in midstream as required.
I actually use the standard OS/2 REXX supplied method for handling QUEUES
for inter process communication on the BBS. When the Client SENDS the
message, in most cases the particular BBS function that SENT the message
has yet to actually end, so a SysSleep(5) can be very useful, it allows the
SENDING task to end and resources to be released before the new task starts
and qants some resources. With multiple lines running on a 16Mb 486/33 this
just helps to keep things running smooth and swapping to a minimum.
Using PIPES is a bit more complicated, but they do have some useful
features such as being able to be used over a LAN between machines. To use
PIPES, you need to add an external REXX feature DLL that provides decent
PIPE handling. I am aware of 2 comonly available DLLS for PIPES and QUEUES
-
1. YDBAUTIL. This package is available from HOBBES as RXUnn.ZIP, the last
version I saw there was RXU19.ZIP, although I have used RXU13.ZIP. This is
my preferenced tool, its from the IBM EWS (Employee Written S/W) suite and
can be very useful.
2. REXXLIB from Quersus Systems. This is a shareware product that is
possibly a bit easier to use, so I have used this one for the following
demo code. I normally use YDBAUTIL though.
======== PSERV.CMD ===========================================
/* REXX script to demonstrate handling of PIPES using REXXLIB.DLL. */
/* Load the REXXLIB library. */
Call rxfuncadd 'rexxlibregister', 'rexxlib', 'rexxlibregister'
Call rexxlibregister
Say Date('S') Time() 'Pipe Server Start...' /* Let us begin. */
Pname = "\PIPE\PipeDemo" /* The name for this Pipe. */
Ptype = 'M' /* Message type, not Byte type. */
Pmode = 'M' /* Read by Message, not by Char. */
Pwait = 'W' /* Wait (block) for messages */
result = NMPIPE_CLOSE(Pname) /* Destroy any pre-existing Pipe. */
Say Date('S') Time() ' Cleanup returned ['result'].'
Phandle = NMPIPE_CREATE(Pname, Ptype, Pmode, Pwait) /* Build new Pipe. */
If Phandle < 0 Then Do /* If Create failed. */
Say ' ERROR: Create PIPE returned ['Phandle'].'
Say ' Failed to set up ['Pname'] - Aborted.'
Exit 99
End
Say Date('S') Time() ' PIPE created using handle ['Phandle'].'
result = NMPIPE_CONNECT(Pname) /* Now connect to Pipe this end. */
if result 0 Then Do
Say ' ERROR: Unable to connect to PIPE!'
Exit 98
End
Do Forever /* The Main loop. */
/* This is a blocking read of the PIPE. The code waits
here until a message arrives. 0 CPU cycles consumed. */
cmd = NMPIPE_READ(Pname) /* Read a message. */
If cmd = 'X' | cmd = 'x' Then Leave /* Force an exit now? */
Say Date('S') Time() ' Received ['cmd'].' /* Report message. */
End
Say Date('S') Time() ' Exit requested.' /* Report message. */
result = SysSleep(2) /* Wait for client to finish. */
result = NMPIPE_DISCONNECT(Phandle) /* Disconnect from the PIPE. */
Say Date('S') Time() ' Disconnect returned ' result
result = NMPIPE_CLOSE(Phandle) /* Now close the PIPE. */
Say Date('S') Time() ' Close returned ' result
Say Date('S') Time() 'Pipe Server complete.'
==============================================================
======== PSEND.CMD ===========================================
/* REXX script to demonstrate sending messages to a PIPE.
Requires REXXLIB.DLL. */
/* Load the REXXLIB library. */
Call rxfuncadd 'rexxlibregister', 'rexxlib', 'rexxlibregister'
Call rexxlibregister
Say Date('S') Time() 'Pipe Client Start.'
Pmode = 'M' /* Pipe Mode = Messages. */
Pname = "\PIPE\PipeDemo" /* Define the PIPE name. */
result = NMPIPE_OPEN(Pname,Pmode) /* Open the PIPE. */
if result 0 Then Do
Say Date('S') Time() ' ERROR: Unable to connect to ['Pname'], error ['res
ult'].'
Say Date('S') Time() ' NB: Server must be started and running first!'
Exit 99
End
Do Forever
Say ' Enter message or X to exit -'
Parse Pull Msg
Say Date('S') Time() ' Sending ['Msg'].' /* Tell em whats happening. */
result = NMPIPE_WRITE(Pname,Msg) /* Write the message. */
If Msg = 'x' | Msg = 'X' Then Leave
result = stream(Pname, 'C', 'Close') /* Close the Pipe. */
End
Say Date('S') Time() 'Exit requested.'
result = stream(Pname, 'C', 'Close') /* Close the Pipe. */
==============================================================
As you can see, there is a bit more work required to get PIPES runing. Both
the PIPE and QUEUE code above was tested here before I posted, so it should
work elsewhere. If you run PULSE or some other system utilization tool you
will notice that none of the above code consumes much in the way of
resources at any time. One tool I use shows <1% CPU for any message
handing.
NOTE: In BOTH cases, the SERVER code must be started before the CLIENT code
is run, or unexpected results may appear.
If anyone wishes to take these further, I recommend the OS/2 REXX Echo,
there are plenty of people there who can provide a lot of the finer points
about using QUEUES and PIPES and how they relate to REXX than I can.
Regards...............pk.
--- Maximus/2 3.01
* Origin: Another Good Point About OS/2 (3:772/1.10)SEEN-BY: 396/1 632/0 371 633/260 262 267 270 284 371 634/397 635/444 506 728 SEEN-BY: 639/252 670/218 @PATH: 772/1 270/101 396/1 633/260 635/506 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.