@V7 54 2 -5
@L3 COUK1247
80
@V9 0
@YCHAPTER 15 - MUSS USER MANUAL
@G@RCHAPTER 15 - INTER-PROCESS COMMUNICATIONS@G
@V10 1 9 231
@T% 10
@BProcesses in MUSS normally communicate with one another by sending messages,
and the input/output devices connected to the system also generate
and receive messages.
Each process has eight input channels to which messages may be directed.
Thus, the complete identification of the destination for a message is
given by the system process number SPN and process identifier PID of
a process and a channel number for that process.
Specially encoded SPNs are used to address the peripheral devices.
The message system is
designed to be network wide, and so part of the SPN identifies
the machine containing the destination process or device.
@BTo enable a two-way communication to be set up easily, and to
prevent a rogue process from injecting unidentified messages into the
communication system, the system appends to each message the identification
of the sender. This is returned to the destination process when it
reads the message, and may subsequently be used as the address for reply
messages. There is an additional problem in ensuring that messages sent
as replies can be associated with a particular message from the original
process. Processes can therefore specify a sequence number, which
is presented to the destination process as part of the reply information.
@BA process also has control over which messages are accepted on a
channel. Each of the eight channels can be set into one of three states:
closed, open for all messages, and dedicated to one specific process.
Any messages directed to a closed channel is rejected, any
messages sent to an open channel is accepted and automatically queued.
With having eight channels under its control, therefore, a process can
selectively stream its input.
@BEach of the message channels acts as a first-in-first-out queue. There
are a number of ways in which a process can tell whether there are messages
waiting to be read. A process may poll its message channels by attempting
to read messages from them.  Secondly, it may elect to wait until a
message arrives on a specified channel, or one of a number of channels.
In this case, a time limit is also specified, and the process is
re-activated if no messages have arrived within that period.
A process may choose to be interrupted when the next
message arrives on a channel (Trap 3 reason 1).
Finally, a process may request the status and condition
of one of its message channels.
@BA message consists of two parts, a short header optionally
accompanied by a segment from the senders virtual store. The header
is copied from the sending to the receiving process' virtual store;
the segment is unlinked from the senders virtual store, and linked
into the receivers virtual store when the message is read. The format
of data in a message is not fixed by the system, and is usually by
arrangement between the sending and receiving processes. The system software
and input/output controllers have certain conventions for messages, and
these are described in Chapter 16.
@BAn alternative to the message system is provided for those
situations where buffered input/output is unsatisfactory, for example,
in a word processing package.  Direct single character communication
with a device is provided as described in 15.2.
@S215.1 MESSAGE COMMANDS
@
@
(1) @JSEND.MESSAGE ([C],[I],I,I,I,I)
@BThis procedure sends a message to a specified channel of the
specified process. P1 is the data to be sent in the short message. It should
not be greater than 80 characters long, and exist in store normally accessible
to the calling process. If longer messages are included, they are truncated
after 80 characters.
@BThe second parameter, P2, is a vector specifying the destination for
the message. It should be at least four elements long, holding respectively@
@Q 6
@
@Mthe SPN (and machine no) of the receiving process
@Nits PID
@Nthe destination mode
@Nthe destination sequence number
@
@
The destination mode and sequence number are parameters included to
help the setting up of "conversations" between two processes. They are
encoded in the same way and have reciprocal functions to the parameters
P3, the source mode and P4, the source sequence number.
@BThe mode may take on values as shown in Table 15-1.@
@A 15
@3
@U 15
@
@
                    Table 15-1. Mode Encoding
@
@X%`
@O                                                                     @O
@O| Value |      Source Mode          |     Destination Mode          |@O
|  %10  |Suspend the process until  |Free the destination process   |
|       |the message has been       |if this is a reply of the right|
@O|       |delivered.                 |sequence number.               |@O
| %8-%F |A reply may be sent on a   |The bottom 3 bits specify      |
|       |channel number equal to the|the channel number on          |
|       |bottom 3 bits (i.e.        |which to link the message.     |
@O|       |channels 0 to 7).          |                               |@O
|  %0   |No reply expected.         |Ignore the send message        |
@O|       |                           |request.                       |@O
@0
@Z
@X%%
@BThe sequence number, P4, provides a mechanism whereby a process can append
an identifier on to an outgoing message. This identifier may then be used
by the recipient process when making replies, so that the original process
can associate outgoing and reply messages. The sequence number may take
any user defined value. The only occasion when it is examined by the
system is when a reply is sent to free a suspended process. In this case,
the process must have suspended as a result of sending a message with
a corresponding sequence number.
@BThe parameters P5 and P6 represent a segment number and access permission
respectively, for a segment within the process' virtual store. The
segment must be present in the virtual store, and the same rules apply
to changes in access permission as would apply to a process calling the
change access command. If the segment parameter is
zero, then no segment is sent.
@
@
(2) @JREAD.MESSAGE ([C],[I],I,I)
@BThis procedure reads a message from the channel specified by the
bottom 3 bits of P3. P1 is a vector where the characters passed as the
short message may be returned. It should exist in store normally accessible
to the calling process. If the vector is not long enough to store the short mess
age, the
excess characters will be discarded and lost.
@BThe parameter P2 should be a vector of at least 4 entries. Information
about the source of the message is copied into this vector, in the form:@
@Q 6
@
@MSPN  of the source (including machine number)
@NPID  of the source
@NMode for replies
@NSequence number for replies.
@
@
This, of course corresponds exactly with the destination parameter of the
send message command. Thus, conversations may be set up by using this
information to send reply messages. The only other information about
the sender of the message, the identification of the user, is returned
in PW4.
@BThe fourth parameter specifies a segment number which may be used
for long messages. If this is negative, a free segment number is allocated.
PW1 always contains the segment number actually used (zero if a
short message), PW2 contains the size of the segment in bytes and PW3
holds the access permission accorded.
@
@
(3) @JSET.CH.STATUS (I,I,I,I)
@BThis procedure sets the status of the input channel specified in P1. The
status, given in P2, is interpreted in the following way:@
@3
@U 4
@
                @O                    @O
               |@O    | d | c | b | a @O|
@0
@
(a)@IAllow messages from any process.@
@
(b)@IDedicate the channel to allow messages from the process whose identifier
(PID) is given in P3.@
@
(c)@IClose the channel after 1 message corresponding to
the specified sequence number P4. Reject all other messages.@
@
(d)@IInterrupt the process when the next message arrives.
This option is reset when the interrupt is forced, and so a subsequent
call of SET.CH.STATUS is required to reassert this option.@
@BA status of zero implies that the channel is closed to all incoming messages.
@
@
(4) @JWAIT (I,I)
@BThis procedure halts the current process pending the arrival of a message.
The first parameter defines the channels on which messages are expected. Thus,
if the least significant bit is set,
messages on channel 0 will wake the process; if
the next bit, messages on channel 1 etc.
@BTo avoid a process waiting an indefinite period of time for a message,
a time limit in seconds, P2, may be specified. If a message on one of
the required channels has not been received within this time, then
the process is woken.
@BIf the time limit is negative or zero, or a message is already on one
of the required channels, then the procedure returns immediately without
halting the process. PW1 always contains a bit pattern indicating the
channels on which messages are present. Thus, the least significant
is set if messages
are on channel 0 etc.
@
@
(5) @JREAD.CH.STATUS (I)
@BThis procedure reads the status of the specified message channel. PW1
returns the status bits, as specified in SET.CH.STATUS, PW2
the PID if the channel is dedicated
and PW3 the sequence number if it is dedicated
for a specific message.
The number of messages on the
channel is returned in PW4.
@S215.2 DIRECT COMMUNICATION COMMANDS
@BThese commands provide an alternative more direct way of
communicating with peripherals which are logged into a message
channel.
@
@
@
1) @JCHANGE.CHANNEL (I,I,I)
@BThis procedure must be called with P2 = 0 before any attempt
is made to communicate directly with a peripheral.
P1 specifies the SPN of the required peripheral.  This SPN
will be included in the source information supplied when
reading a message from the peripheral.  It can also be obtained
by calling I.SOURCE for any message stream which has received
input from the peripheral.
The procedure informs the input/output
manager of a change in the mode of usage of the
device and returns in PW1 an identifier which
must be used as the P1 of the following two commands.
No further messages will be sent to the process whilst
the device remains in this state, but output messages
may still be sent from the process.  The procedure is
also used (with P2 = 1) to change a direct communication
channel back to a message channel.
@BP3 is a parameter giving the required device modes of the
input and output devices associated with the channel.  The
least significant eight bits contain the input
device mode and the next eight the output device mode.
The significance of the bits is described in Chapter 20.
The previous modes of the devices are returned in PW2.
@
@
@
2) @JREAD.CH (I)
@BThis procedure reads the next character of input
from the device specified by P1.
The character is returned in the least significant 8 bits of PW1
and the next more significant bit is set if no more input is waiting to be read.
If there is no input
waiting in the buffer the called process will be suspended
until the next input character arrives.
@
@
@
3) @JWRITE.CH (I,I)
@BThis procedure transmits the character specified by P2 to the
device specified by P1.  The process may be halted if, for example,
previously sent messages have not yet been transmitted or if too
many characters are buffered awaiting transmission.
@F
