156 lines
6.0 KiB
HTML
156 lines
6.0 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
||
|
<title>Message Queue Functions</title>
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<!-- Begin Header Records ========================================= -->
|
||
|
<!-- 050119 JETAYLOR new for V5R4 -->
|
||
|
<!-- End Header Records -->
|
||
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<a name="Top_Of_Page"></a>
|
||
|
<!-- Java sync-link -->
|
||
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
||
|
</script>
|
||
|
|
||
|
<h2><a name="messagequeue">Message Queue Functions</a></h2>
|
||
|
|
||
|
<p><strong>Message queues</strong> provide a form of message passing in which
|
||
|
any process (given that it has the necessary permissions) can read a message
|
||
|
from or write a message to any IPC message queue on the system. There are no
|
||
|
requirements that a process be waiting to receive a message from a queue before
|
||
|
another process sends one, or that a message exist on the queue before a
|
||
|
process requests to receive one.</p>
|
||
|
|
||
|
<p>Every message on a queue has the following attributes:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Message type</li>
|
||
|
|
||
|
<li>Message length (length of data part of message)</li>
|
||
|
|
||
|
<li>Message data (if length is greater than 0)</li>
|
||
|
</ul>
|
||
|
|
||
|
<p>A thread gets a message queue identifier by calling the <strong>
|
||
|
msgget()</strong> function. Depending on the <em>key</em> and <em>msgflg</em>
|
||
|
parameters passed in, either a new message queue is created or an existing
|
||
|
message queue is accessed. When a new message queue is created, a data
|
||
|
structure is also created to contain information about the message queue. This
|
||
|
structure is defined in the <strong><sys/msg.h></strong> header file as
|
||
|
follows:</p>
|
||
|
|
||
|
<pre>
|
||
|
typedef struct msqid_ds {
|
||
|
struct ipc_perm msg_perm; /* Operation permission struct */
|
||
|
msgqnum_t msg_qnum; /* # msgs currently on queue */
|
||
|
msglen_t msg_qbytes; /* Max # bytes allowed on queue*/
|
||
|
pid_t msg_lspid; /* Process ID of last msgsnd() */
|
||
|
pid_t msg_lrpid; /* Process ID of last msgrcv() */
|
||
|
time_t msg_stime; /* Time of last msgsnd() */
|
||
|
time_t msg_rtime; /* Time of last msgrcv() */
|
||
|
time_t msg_ctime; /* Time of last change */
|
||
|
} msqid_ds_t;
|
||
|
</pre>
|
||
|
|
||
|
<p>A thread puts a message on a message queue by calling the <strong>
|
||
|
msgsnd()</strong> function. The following parameters are passed in:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Message queue ID</li>
|
||
|
|
||
|
<li>Pointer to a buffer containing the message type and message data</li>
|
||
|
|
||
|
<li>Length of the message</li>
|
||
|
|
||
|
<li>Flag that specifies whether or not the thread is willing to wait to send
|
||
|
the message.</li>
|
||
|
</ul>
|
||
|
|
||
|
<p>A thread gets a message from a message queue by calling the <strong>
|
||
|
msgrcv()</strong> function. The following parameters are passed in:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Message queue ID</li>
|
||
|
|
||
|
<li>Pointer to a buffer in which to receive the message</li>
|
||
|
|
||
|
<li>Length of the buffer</li>
|
||
|
|
||
|
<li>Type of message</li>
|
||
|
|
||
|
<li>Flag that specifies whether or not the thread is willing to wait and
|
||
|
whether or not the thread is willing to truncate a message to receive it</li>
|
||
|
</ul>
|
||
|
|
||
|
<p>A thread removes a message queue ID by calling the <strong>msgctl()</strong>
|
||
|
function. The thread also can use the <strong>msgctl()</strong> function to
|
||
|
change the data structure values associated with the message queue ID or to
|
||
|
retrieve the data structure values associated with the message queue ID. The
|
||
|
following parameters are passed in:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Message queue ID</li>
|
||
|
|
||
|
<li>Command the thread wants to perform (remove ID, set data structure values,
|
||
|
receive data structure values)</li>
|
||
|
|
||
|
<li>Pointer to a buffer from which to set data structure values or in which to
|
||
|
receive data structure values</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
<h4>Message Queue Differences and Restrictions</h4>
|
||
|
|
||
|
<p>i5/OS message queues differ from the message queue definition in the
|
||
|
Single UNIX Specification in the following ways:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>The maximum message size is 65535 bytes.</li>
|
||
|
|
||
|
<li>The maximum number of bytes on a message queue is
|
||
|
16 777 216.</li>
|
||
|
|
||
|
<li>The maximum number of message queues that can be created (system-wide) is
|
||
|
2 147 483 646.</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
<p>The message queue functions are:</p>
|
||
|
<!-- ***** NOTE ***** Do not manually update text or links in this section. -->
|
||
|
<!-- Updates made in this section *will* be overlaid by automated tools -->
|
||
|
<!-- Notify User Technologies of needed updates to be made in XML for API finder.-->
|
||
|
<!--***************API BEGIN PASTE***************-->
|
||
|
<ul>
|
||
|
<li><A HREF="ipcmsgct.htm">msgctl()</A> (Perform Message Control Operations) provides message control operations as specified by cmd on the message queue specified by msqid.</li>
|
||
|
<li><A HREF="ipcmsggt.htm">msgget()</A> (Get Message Queue) returns the message queue identifier associated with the parameter key.</li>
|
||
|
<li><A HREF="ipcmsgrc.htm">msgrcv()</A> (Receive Message Operation) reads a message from the queue associated with the message queue identifier specified by msqid and places it in the user-defined buffer pointed to by msgp.</li>
|
||
|
<li><A HREF="ipcmsgsn.htm">msgsnd()</A> (Send Message Operation) is used to send a message to the queue associated with the message queue identifier specified by msqid.</li>
|
||
|
</ul>
|
||
|
<!--***************API END PASTE***************-->
|
||
|
|
||
|
<p>See also <a href="unix3a4.htm">IPC Key Generation Functions</a> for additional message queue functions.</p>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
<hr>
|
||
|
<center>
|
||
|
<table cellpadding="2" cellspacing="2">
|
||
|
<tr align="center">
|
||
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
|
||
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</center>
|
||
|
</body>
|
||
|
</html>
|
||
|
|