⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msgsnd.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>msgsnd</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="msgsnd"></a> <a name="tag_03_396"></a><!-- msgsnd --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_396_01"></a>NAME</h4><blockquote>msgsnd - XSI message send operation</blockquote><h4><a name="tag_03_396_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include &lt;<a href="../basedefs/sys/msg.h.html">sys/msg.h</a>&gt;<br><br> int msgsnd(int</tt> <i>msqid</i><tt>, const void *</tt><i>msgp</i><tt>, size_t</tt> <i>msgsz</i><tt>, int</tt> <i>msgflg</i><tt>);<img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_396_03"></a>DESCRIPTION</h4><blockquote><p>The <i>msgsnd</i>() function operates on XSI message queues (see the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001,<a href="../basedefs/xbd_chap03.html#tag_03_224">Section 3.224, Message Queue</a>). It is unspecified whether this functioninteroperates with the realtime interprocess communication facilities defined in <a href="xsh_chap02_08.html#tag_02_08"><i>Realtime</i></a> .</p><p>The <i>msgsnd</i>() function shall send a message to the queue associated with the message queue identifier specified by<i>msqid</i>.</p><p>The application shall ensure that the argument <i>msgp</i> points to a user-defined buffer that contains first a field of type<b>long</b> specifying the type of the message, and then a data portion that holds the data bytes of the message. The structurebelow is an example of what this user-defined buffer might look like:</p><pre><tt>struct mymsg {    long   mtype;       /* Message type. */    char   mtext[1];    /* Message text. */}</tt></pre><p>The structure member <i>mtype</i> is a non-zero positive type <b>long</b> that can be used by the receiving process for messageselection.</p><p>The structure member <i>mtext</i> is any text of length <i>msgsz</i> bytes. The argument <i>msgsz</i> can range from 0 to asystem-imposed maximum.</p><p>The argument <i>msgflg</i> specifies the action to be taken if one or more of the following is true:</p><ul><li><p>The number of bytes already on the queue is equal to <b>msg_qbytes</b>; see <a href="../basedefs/sys/msg.h.html"><i>&lt;sys/msg.h&gt;</i></a>.</p></li><li><p>The total number of messages on all queues system-wide is equal to the system-imposed limit.</p></li></ul><p>These actions are as follows:</p><ul><li><p>If (<i>msgflg</i> &amp; IPC_NOWAIT) is non-zero, the message shall not be sent and the calling thread shall returnimmediately.</p></li><li><p>If (<i>msgflg</i> &amp; IPC_NOWAIT) is 0, the calling thread shall suspend execution until one of the following occurs:</p><ul><li><p>The condition responsible for the suspension no longer exists, in which case the message is sent.</p></li><li><p>The message queue identifier <i>msqid</i> is removed from the system; when this occurs, <i>errno</i> shall be set equal to[EIDRM] and -1 shall be returned.</p></li><li><p>The calling thread receives a signal that is to be caught; in this case the message is not sent and the calling thread resumesexecution in the manner prescribed in <a href="sigaction.html"><i>sigaction</i>()</a> .</p></li></ul></li></ul><p>Upon successful completion, the following actions are taken with respect to the data structure associated with <i>msqid</i>; see<a href="../basedefs/sys/msg.h.html"><i>&lt;sys/msg.h&gt;</i></a>:</p><ul><li><p><b>msg_qnum</b> shall be incremented by 1.</p></li><li><p><b>msg_lspid</b> shall be set equal to the process ID of the calling process.</p></li><li><p><b>msg_stime</b> shall be set equal to the current time.</p></li></ul></blockquote><h4><a name="tag_03_396_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>msgsnd</i>() shall return 0; otherwise, no message shall be sent, <i>msgsnd</i>() shall return-1, and <i>errno</i> shall be set to indicate the error.</p></blockquote><h4><a name="tag_03_396_05"></a>ERRORS</h4><blockquote><p>The <i>msgsnd</i>() function shall fail if:</p><dl compact><dt>[EACCES]</dt><dd>Operation permission is denied to the calling process; see <a href="xsh_chap02_07.html#tag_02_07"><i>XSI InterprocessCommunication</i></a> .</dd><dt>[EAGAIN]</dt><dd>The message cannot be sent for one of the reasons cited above and (<i>msgflg</i> &amp; IPC_NOWAIT) is non-zero.</dd><dt>[EIDRM]</dt><dd>The message queue identifier <i>msqid</i> is removed from the system.</dd><dt>[EINTR]</dt><dd>The <i>msgsnd</i>() function was interrupted by a signal.</dd><dt>[EINVAL]</dt><dd>The value of <i>msqid</i> is not a valid message queue identifier, or the value of <i>mtype</i> is less than 1; or the value of<i>msgsz</i> is less than 0 or greater than the system-imposed limit.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_396_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_396_06_01"></a>Sending a Message</h5><p>The following example sends a message to the queue identified by the <i>msqid</i> argument (assuming that value has previouslybeen set). This call specifies that an error should be reported if no message is available. The message size is calculated directlyusing the <i>sizeof</i> operator.</p><pre><tt>#include &lt;sys/msg.h&gt;...int result;int msqid;struct message {    long type;    char text[20];} msg;<br>msg.type = 1;strcpy(msg.text, "This is message 1");...result = msgsnd(msqid, (void *) &amp;msg, sizeof(msg.text), IPC_NOWAIT);</tt></pre></blockquote><h4><a name="tag_03_396_07"></a>APPLICATION USAGE</h4><blockquote><p>The POSIX Realtime Extension defines alternative interfaces for interprocess communication (IPC). Application developers whoneed to use IPC should design their applications so that modules using the IPC routines described in <a href="xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess Communication</i></a> can be easily modified to use the alternativeinterfaces.</p></blockquote><h4><a name="tag_03_396_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_396_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_396_10"></a>SEE ALSO</h4><blockquote><p><a href="xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess Communication</i></a> , <a href="xsh_chap02_08.html#tag_02_08"><i>Realtime</i></a> , <a href="mq_close.html"><i>mq_close</i>()</a> , <a href="mq_getattr.html"><i>mq_getattr</i>()</a> , <a href="mq_notify.html"><i>mq_notify</i>()</a> , <a href="mq_open.html"><i>mq_open</i>()</a> , <a href="mq_receive.html"><i>mq_receive</i>()</a> , <a href="mq_send.html"><i>mq_send</i>()</a> , <a href="mq_setattr.html"><i>mq_setattr</i>()</a> , <a href="mq_unlink.html"><i>mq_unlink</i>()</a> , <a href="msgctl.html"><i>msgctl</i>()</a> , <a href="msgget.html"><i>msgget</i>()</a> ,<a href="msgrcv.html"><i>msgrcv</i>()</a> , <a href="sigaction.html"><i>sigaction</i>()</a> , the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/sys/msg.h.html"><i>&lt;sys/msg.h&gt;</i></a></p></blockquote><h4><a name="tag_03_396_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2. Derived from Issue 2 of the SVID.</p></blockquote><h4><a name="tag_03_396_12"></a>Issue 5</h4><blockquote><p>The note about use of POSIX Realtime Extension IPC routines has been moved from FUTURE DIRECTIONS to a new APPLICATION USAGEsection.</p></blockquote><h4><a name="tag_03_396_13"></a>Issue 6</h4><blockquote><p>The DESCRIPTION is updated to avoid use of the term &quot;must&quot; for application requirements.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -