📄 mq_open.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>mq_open</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="mq_open"></a> <a name="tag_03_385"></a><!-- mq_open --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_385_01"></a>NAME</h4><blockquote>mq_open - open a message queue (<b>REALTIME</b>)</blockquote><h4><a name="tag_03_385_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('MSG')">MSG</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/mqueue.h.html">mqueue.h</a>><br><br> mqd_t mq_open(const char *</tt><i>name</i><tt>, int</tt> <i>oflag</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_385_03"></a>DESCRIPTION</h4><blockquote><p>The <i>mq_open</i>() function shall establish the connection between a process and a message queue with a message queuedescriptor. It shall create an open message queue description that refers to the message queue, and a message queue descriptor thatrefers to that open message queue description. The message queue descriptor is used by other functions to refer to that messagequeue. The <i>name</i> argument points to a string naming a message queue. It is unspecified whether the name appears in the filesystem and is visible to other functions that take pathnames as arguments. The <i>name</i> argument shall conform to theconstruction rules for a pathname. If <i>name</i> begins with the slash character, then processes calling <i>mq_open</i>() with thesame value of <i>name</i> shall refer to the same message queue object, as long as that name has not been removed. If <i>name</i>does not begin with the slash character, the effect is implementation-defined. The interpretation of slash characters other thanthe leading slash character in <i>name</i> is implementation-defined. If the <i>name</i> argument is not the name of an existingmessage queue and creation is not requested, <i>mq_open</i>() shall fail and return an error.</p><p>A message queue descriptor may be implemented using a file descriptor, in which case applications can open up to at least{OPEN_MAX} file and message queues.</p><p>The <i>oflag</i> argument requests the desired receive and/or send access to the message queue. The requested access permissionto receive messages or send messages shall be granted if the calling process would be granted read or write access, respectively,to an equivalently protected file.</p><p>The value of <i>oflag</i> is the bitwise-inclusive OR of values from the following list. Applications shall specify exactly oneof the first three values (access modes) below in the value of <i>oflag</i>:</p><dl compact><dt>O_RDONLY</dt><dd>Open the message queue for receiving messages. The process can use the returned message queue descriptor with <a href="../functions/mq_receive.html"><i>mq_receive</i>()</a>, but not <a href="../functions/mq_send.html"><i>mq_send</i>()</a>. A messagequeue may be open multiple times in the same or different processes for receiving messages.</dd><dt>O_WRONLY</dt><dd>Open the queue for sending messages. The process can use the returned message queue descriptor with <a href="../functions/mq_send.html"><i>mq_send</i>()</a> but not <a href="../functions/mq_receive.html"><i>mq_receive</i>()</a>. A messagequeue may be open multiple times in the same or different processes for sending messages.</dd><dt>O_RDWR</dt><dd>Open the queue for both receiving and sending messages. The process can use any of the functions allowed for O_RDONLY andO_WRONLY. A message queue may be open multiple times in the same or different processes for sending messages.</dd></dl><p>Any combination of the remaining flags may be specified in the value of <i>oflag</i>:</p><dl compact><dt>O_CREAT</dt><dd>Create a message queue. It requires two additional arguments: <i>mode</i>, which shall be of type <b>mode_t</b>, and<i>attr</i>, which shall be a pointer to an <b>mq_attr</b> structure. If the pathname <i>name</i> has already been used to create amessage queue that still exists, then this flag shall have no effect, except as noted under O_EXCL. Otherwise, a message queueshall be created without any messages in it. The user ID of the message queue shall be set to the effective user ID of the process,and the group ID of the message queue shall be set to the effective group ID of the process. The file permission bits shall be setto the value of <i>mode</i>. When bits in <i>mode</i> other than file permission bits are set, the effect isimplementation-defined. If <i>attr</i> is NULL, the message queue shall be created with implementation-defined default messagequeue attributes. If <i>attr</i> is non-NULL and the calling process has the appropriate privilege on <i>name</i>, the messagequeue <i>mq_maxmsg</i> and <i>mq_msgsize</i> attributes shall be set to the values of the corresponding members in the<b>mq_attr</b> structure referred to by <i>attr</i>. If <i>attr</i> is non-NULL, but the calling process does not have theappropriate privilege on <i>name</i>, the <i>mq_open</i>() function shall fail and return an error without creating the messagequeue.</dd><dt>O_EXCL</dt><dd>If O_EXCL and O_CREAT are set, <i>mq_open</i>() shall fail if the message queue <i>name</i> exists. The check for the existenceof the message queue and the creation of the message queue if it does not exist shall be atomic with respect to other threadsexecuting <i>mq_open</i>() naming the same <i>name</i> with O_EXCL and O_CREAT set. If O_EXCL is set and O_CREAT is not set, theresult is undefined.</dd><dt>O_NONBLOCK</dt><dd>Determines whether an <a href="../functions/mq_send.html"><i>mq_send</i>()</a> or <a href="../functions/mq_receive.html"><i>mq_receive</i>()</a> waits for resources or messages that are not currently available, or failswith <i>errno</i> set to [EAGAIN]; see <a href="mq_send.html"><i>mq_send</i>()</a> and <a href="mq_receive.html"><i>mq_receive</i>()</a> for details.</dd></dl><p>The <i>mq_open</i>() function does not add or remove messages from the queue.</p></blockquote><h4><a name="tag_03_385_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, the function shall return a message queue descriptor; otherwise, the function shall return(<b>mqd_t</b>)-1 and set <i>errno</i> to indicate the error.</p></blockquote><h4><a name="tag_03_385_05"></a>ERRORS</h4><blockquote><p>The <i>mq_open</i>() function shall fail if:</p><dl compact><dt>[EACCES]</dt><dd>The message queue exists and the permissions specified by <i>oflag</i> are denied, or the message queue does not exist andpermission to create the message queue is denied.</dd><dt>[EEXIST]</dt><dd>O_CREAT and O_EXCL are set and the named message queue already exists.</dd><dt>[EINTR]</dt><dd>The <i>mq_open</i>() function was interrupted by a signal.</dd><dt>[EINVAL]</dt><dd>The <i>mq_open</i>() function is not supported for the given name.</dd><dt>[EINVAL]</dt><dd>O_CREAT was specified in <i>oflag</i>, the value of <i>attr</i> is not NULL, and either <i>mq_maxmsg</i> or <i>mq_msgsize</i>was less than or equal to zero.</dd><dt>[EMFILE]</dt><dd>Too many message queue descriptors or file descriptors are currently in use by this process.</dd><dt>[ENAMETOOLONG]</dt><dd>The length of the <i>name</i> argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd><dt>[ENFILE]</dt><dd>Too many message queues are currently open in the system.</dd><dt>[ENOENT]</dt><dd>O_CREAT is not set and the named message queue does not exist.</dd><dt>[ENOSPC]</dt><dd>There is insufficient space for the creation of the new message queue.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_385_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_385_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_385_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_385_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_385_10"></a>SEE ALSO</h4><blockquote><p><a href="mq_close.html"><i>mq_close</i>()</a> , <a href="mq_getattr.html"><i>mq_getattr</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_timedreceive.html"><i>mq_timedreceive</i>()</a> , <a href="mq_timedsend.html"><i>mq_timedsend</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> , <ahref="msgsnd.html"><i>msgsnd</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/mqueue.h.html"><i><mqueue.h></i></a></p></blockquote><h4><a name="tag_03_385_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 5. Included for alignment with the POSIX Realtime Extension.</p></blockquote><h4><a name="tag_03_385_12"></a>Issue 6</h4><blockquote><p>The <i>mq_open</i>() function is marked as part of the Message Passing option.</p><p>The [ENOSYS] error condition has been removed as stubs need not be provided if an implementation does not support the MessagePassing option.</p><p>The <a href="../functions/mq_timedreceive.html"><i>mq_timedreceive</i>()</a> and <a href="../functions/mq_timedsend.html"><i>mq_timedsend</i>()</a> functions are added to the SEE ALSO section for alignment withIEEE Std 1003.1d-1999.</p><p>The DESCRIPTION of O_EXCL is updated in response to IEEE PASC Interpretation 1003.1c #48.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® 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 + -