2008-01-30 15:01:22 +01:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* fs/mqueue/mq_open.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-30 15:01:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-30 15:01:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-30 15:01:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2021-07-11 11:44:25 +02:00
|
|
|
#include <sys/stat.h>
|
2017-02-04 18:46:54 +01:00
|
|
|
#include <stdbool.h>
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <stdarg.h>
|
2014-09-29 22:59:31 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sched.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <mqueue.h>
|
2007-03-20 17:51:12 +01:00
|
|
|
#include <fcntl.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2007-02-21 22:55:16 +01:00
|
|
|
#include <errno.h>
|
2014-09-29 22:59:31 +02:00
|
|
|
|
|
|
|
#include <nuttx/mqueue.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
|
|
|
|
#include "inode/inode.h"
|
|
|
|
#include "mqueue/mqueue.h"
|
2023-08-18 14:14:38 +02:00
|
|
|
#include "notify/notify.h"
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2020-12-22 15:02:48 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nxmq_file_close(FAR struct file *filep);
|
2021-01-08 06:43:33 +01:00
|
|
|
static int nxmq_file_poll(FAR struct file *filep,
|
2023-09-15 21:07:32 +02:00
|
|
|
FAR struct pollfd *fds, bool setup);
|
2020-12-22 15:02:48 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const struct file_operations g_nxmq_fileops =
|
|
|
|
{
|
|
|
|
NULL, /* open */
|
|
|
|
nxmq_file_close, /* close */
|
|
|
|
NULL, /* read */
|
|
|
|
NULL, /* write */
|
|
|
|
NULL, /* seek */
|
|
|
|
NULL, /* ioctl */
|
2023-01-02 14:02:51 +01:00
|
|
|
NULL, /* mmap */
|
2023-01-02 18:06:12 +01:00
|
|
|
NULL, /* truncate */
|
2022-01-10 15:51:17 +01:00
|
|
|
nxmq_file_poll /* poll */
|
2020-12-22 15:02:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nxmq_file_close(FAR struct file *filep)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
|
2024-07-03 05:44:27 +02:00
|
|
|
if (inode->i_crefs <= 0)
|
2020-12-22 15:02:48 +01:00
|
|
|
{
|
|
|
|
FAR struct mqueue_inode_s *msgq = inode->i_private;
|
|
|
|
|
|
|
|
if (msgq)
|
|
|
|
{
|
|
|
|
nxmq_free_msgq(msgq);
|
|
|
|
inode->i_private = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-08 06:43:33 +01:00
|
|
|
static int nxmq_file_poll(FAR struct file *filep,
|
2023-09-15 21:07:32 +02:00
|
|
|
FAR struct pollfd *fds, bool setup)
|
2021-01-08 06:43:33 +01:00
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct mqueue_inode_s *msgq = inode->i_private;
|
|
|
|
pollevent_t eventset = 0;
|
|
|
|
irqstate_t flags;
|
|
|
|
int ret = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
if (setup)
|
|
|
|
{
|
|
|
|
for (i = 0; i < CONFIG_FS_MQUEUE_NPOLLWAITERS; i++)
|
|
|
|
{
|
|
|
|
/* Find an available slot */
|
|
|
|
|
2023-09-15 21:07:32 +02:00
|
|
|
if (msgq->fds[i] == NULL)
|
2021-01-08 06:43:33 +01:00
|
|
|
{
|
|
|
|
/* Bind the poll structure and this slot */
|
|
|
|
|
|
|
|
msgq->fds[i] = fds;
|
|
|
|
fds->priv = &msgq->fds[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= CONFIG_FS_MQUEUE_NPOLLWAITERS)
|
|
|
|
{
|
|
|
|
fds->priv = NULL;
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Immediately notify on any of the requested events */
|
|
|
|
|
|
|
|
if (msgq->nmsgs < msgq->maxmsgs)
|
|
|
|
{
|
2022-09-19 05:08:57 +02:00
|
|
|
eventset |= POLLOUT;
|
2021-01-08 06:43:33 +01:00
|
|
|
}
|
|
|
|
|
2023-09-15 21:07:32 +02:00
|
|
|
if (msgq->nmsgs > 0)
|
2021-01-08 06:43:33 +01:00
|
|
|
{
|
2022-09-19 05:08:57 +02:00
|
|
|
eventset |= POLLIN;
|
2021-01-08 06:43:33 +01:00
|
|
|
}
|
|
|
|
|
2023-11-19 12:19:53 +01:00
|
|
|
poll_notify(&fds, 1, eventset);
|
2021-01-08 06:43:33 +01:00
|
|
|
}
|
|
|
|
else if (fds->priv != NULL)
|
|
|
|
{
|
|
|
|
for (i = 0; i < CONFIG_FS_MQUEUE_NPOLLWAITERS; i++)
|
|
|
|
{
|
|
|
|
if (fds == msgq->fds[i])
|
|
|
|
{
|
|
|
|
msgq->fds[i] = NULL;
|
|
|
|
fds->priv = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
errout:
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-24 13:53:17 +01:00
|
|
|
static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
|
2023-09-15 21:07:32 +02:00
|
|
|
int oflags, mode_t umask, va_list ap,
|
|
|
|
FAR int *created)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-09-29 22:59:31 +02:00
|
|
|
FAR struct inode *inode;
|
2014-09-29 21:19:11 +02:00
|
|
|
FAR struct mqueue_inode_s *msgq;
|
2020-12-24 13:53:17 +01:00
|
|
|
FAR struct mq_attr *attr = NULL;
|
2017-02-05 16:51:42 +01:00
|
|
|
struct inode_search_s desc;
|
2014-09-29 22:59:31 +02:00
|
|
|
char fullpath[MAX_MQUEUE_PATH];
|
2023-01-31 10:27:13 +01:00
|
|
|
irqstate_t flags;
|
2020-12-24 13:53:17 +01:00
|
|
|
mode_t mode = 0;
|
2014-09-29 22:59:31 +02:00
|
|
|
int ret;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Make sure that a non-NULL name is supplied */
|
|
|
|
|
2020-12-24 13:53:17 +01:00
|
|
|
if (!mq || !mq_name || *mq_name == '\0')
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2020-05-03 22:31:05 +02:00
|
|
|
ret = -EINVAL;
|
2014-09-30 00:46:01 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2022-02-05 17:30:34 +01:00
|
|
|
if (sizeof(CONFIG_FS_MQUEUE_VFS_PATH) + 1 + strlen(mq_name)
|
2021-10-25 08:28:31 +02:00
|
|
|
>= MAX_MQUEUE_PATH)
|
2021-07-12 16:15:25 +02:00
|
|
|
{
|
|
|
|
ret = -ENAMETOOLONG;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2020-12-24 13:53:17 +01:00
|
|
|
/* Were we asked to create it? */
|
|
|
|
|
|
|
|
if ((oflags & O_CREAT) != 0)
|
|
|
|
{
|
|
|
|
/* We have to extract the additional
|
|
|
|
* parameters from the variable argument list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mode = va_arg(ap, mode_t);
|
|
|
|
attr = va_arg(ap, FAR struct mq_attr *);
|
2023-06-13 16:02:47 +02:00
|
|
|
if (attr != NULL)
|
2023-06-08 09:01:50 +02:00
|
|
|
{
|
2023-06-13 16:02:47 +02:00
|
|
|
if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto errout;
|
|
|
|
}
|
2023-06-08 09:01:50 +02:00
|
|
|
}
|
2020-12-24 13:53:17 +01:00
|
|
|
}
|
|
|
|
|
2021-07-16 14:37:19 +02:00
|
|
|
mode &= ~umask;
|
2021-07-11 11:44:25 +02:00
|
|
|
|
2017-01-08 16:14:11 +01:00
|
|
|
/* Skip over any leading '/'. All message queue paths are relative to
|
2022-02-05 17:30:34 +01:00
|
|
|
* CONFIG_FS_MQUEUE_VFS_PATH.
|
2017-01-08 16:14:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
while (*mq_name == '/')
|
|
|
|
{
|
|
|
|
mq_name++;
|
|
|
|
}
|
|
|
|
|
2014-09-30 00:46:01 +02:00
|
|
|
/* Get the full path to the message queue */
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2022-02-05 17:30:34 +01:00
|
|
|
snprintf(fullpath, MAX_MQUEUE_PATH,
|
|
|
|
CONFIG_FS_MQUEUE_VFS_PATH "/%s", mq_name);
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2014-09-30 00:46:01 +02:00
|
|
|
/* Make sure that the check for the existence of the message queue
|
|
|
|
* and the creation of the message queue are atomic with respect to
|
2023-01-31 10:27:13 +01:00
|
|
|
* other processes executing mq_open(). A simple sched_lock() would
|
|
|
|
* be sufficient for non-SMP case but critical section is needed for
|
|
|
|
* SMP case.
|
2014-09-30 00:46:01 +02:00
|
|
|
*/
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2023-01-31 10:27:13 +01:00
|
|
|
flags = enter_critical_section();
|
2014-09-30 00:46:01 +02:00
|
|
|
|
|
|
|
/* Get the inode for this mqueue. This should succeed if the message
|
2017-02-04 18:46:54 +01:00
|
|
|
* queue has already been created. In this case, inode_find() will
|
2015-09-23 18:34:08 +02:00
|
|
|
* have incremented the reference count on the inode.
|
2014-09-30 00:46:01 +02:00
|
|
|
*/
|
|
|
|
|
2017-02-05 21:25:45 +01:00
|
|
|
SETUP_SEARCH(&desc, fullpath, false);
|
2017-02-05 16:51:42 +01:00
|
|
|
|
|
|
|
ret = inode_find(&desc);
|
|
|
|
if (ret >= 0)
|
2014-09-30 00:46:01 +02:00
|
|
|
{
|
2017-02-05 16:51:42 +01:00
|
|
|
/* Something exists at this path. Get the search results */
|
|
|
|
|
|
|
|
inode = desc.node;
|
|
|
|
|
|
|
|
/* Verify that the inode is a message queue */
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2014-09-30 00:46:01 +02:00
|
|
|
if (!INODE_IS_MQUEUE(inode))
|
|
|
|
{
|
2020-05-03 22:31:05 +02:00
|
|
|
ret = -ENXIO;
|
2014-09-30 00:46:01 +02:00
|
|
|
goto errout_with_inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It exists and is a message queue. Check if the caller wanted to
|
|
|
|
* create a new mqueue with this name.
|
2014-09-29 22:59:31 +02:00
|
|
|
*/
|
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2020-05-03 22:31:05 +02:00
|
|
|
ret = -EEXIST;
|
2014-09-30 00:46:01 +02:00
|
|
|
goto errout_with_inode;
|
2014-09-29 22:59:31 +02:00
|
|
|
}
|
2014-09-30 00:46:01 +02:00
|
|
|
|
2020-12-22 15:02:48 +01:00
|
|
|
/* Associate the inode with a file structure */
|
2014-09-30 00:46:01 +02:00
|
|
|
|
2023-05-06 20:42:18 +02:00
|
|
|
memset(mq, 0, sizeof(*mq));
|
|
|
|
mq->f_oflags = oflags;
|
|
|
|
mq->f_inode = inode;
|
2020-12-24 13:53:17 +01:00
|
|
|
|
|
|
|
if (created)
|
2014-09-29 22:59:31 +02:00
|
|
|
{
|
2020-12-24 13:53:17 +01:00
|
|
|
*created = 1;
|
2014-09-30 00:46:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The mqueue does not exists. Were we asked to create it? */
|
2014-09-29 22:09:31 +02:00
|
|
|
|
2014-09-30 00:46:01 +02:00
|
|
|
if ((oflags & O_CREAT) == 0)
|
|
|
|
{
|
|
|
|
/* The mqueue does not exist and O_CREAT is not set */
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2020-05-03 22:31:05 +02:00
|
|
|
ret = -ENOENT;
|
2014-09-30 00:46:01 +02:00
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
2014-09-29 22:09:31 +02:00
|
|
|
|
2014-09-30 00:46:01 +02:00
|
|
|
/* Create an inode in the pseudo-filesystem at this path */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = inode_lock();
|
2020-03-30 01:36:19 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
|
|
|
|
2021-07-09 07:43:26 +02:00
|
|
|
ret = inode_reserve(fullpath, mode, &inode);
|
2022-09-06 08:18:45 +02:00
|
|
|
inode_unlock();
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2014-09-30 00:46:01 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2015-09-23 18:34:08 +02:00
|
|
|
/* Allocate memory for the new message queue. The new inode will
|
|
|
|
* be created with a reference count of zero.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2021-07-12 16:15:25 +02:00
|
|
|
ret = nxmq_alloc_msgq(attr, &msgq);
|
|
|
|
if (ret < 0)
|
2014-09-30 00:46:01 +02:00
|
|
|
{
|
|
|
|
goto errout_with_inode;
|
|
|
|
}
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2020-12-22 15:02:48 +01:00
|
|
|
/* Associate the inode with a file structure */
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2023-05-06 20:42:18 +02:00
|
|
|
memset(mq, 0, sizeof(*mq));
|
|
|
|
mq->f_oflags = oflags;
|
|
|
|
mq->f_inode = inode;
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2014-09-30 00:46:01 +02:00
|
|
|
INODE_SET_MQUEUE(inode);
|
2020-12-22 15:02:48 +01:00
|
|
|
inode->u.i_ops = &g_nxmq_fileops;
|
|
|
|
inode->i_private = msgq;
|
2014-09-30 00:46:01 +02:00
|
|
|
msgq->inode = inode;
|
2014-09-30 00:13:07 +02:00
|
|
|
|
2015-09-23 18:34:08 +02:00
|
|
|
/* Set the initial reference count on this inode to one */
|
|
|
|
|
2024-07-03 05:44:27 +02:00
|
|
|
inode->i_crefs++;
|
2020-12-24 13:53:17 +01:00
|
|
|
|
|
|
|
if (created)
|
|
|
|
{
|
|
|
|
*created = 0;
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2014-09-29 22:59:31 +02:00
|
|
|
|
2017-02-05 21:25:45 +01:00
|
|
|
RELEASE_SEARCH(&desc);
|
2023-01-31 10:27:13 +01:00
|
|
|
leave_critical_section(flags);
|
2023-08-18 14:14:38 +02:00
|
|
|
#ifdef CONFIG_FS_NOTIFY
|
|
|
|
notify_open(fullpath, oflags);
|
|
|
|
#endif
|
2020-05-03 22:31:05 +02:00
|
|
|
return OK;
|
2014-09-29 22:59:31 +02:00
|
|
|
|
|
|
|
errout_with_inode:
|
|
|
|
inode_release(inode);
|
2017-02-05 21:25:45 +01:00
|
|
|
|
2014-09-29 22:59:31 +02:00
|
|
|
errout_with_lock:
|
2017-02-05 21:25:45 +01:00
|
|
|
RELEASE_SEARCH(&desc);
|
2023-01-31 10:27:13 +01:00
|
|
|
leave_critical_section(flags);
|
2017-02-05 21:25:45 +01:00
|
|
|
|
2014-09-30 00:46:01 +02:00
|
|
|
errout:
|
2020-05-03 22:31:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-24 13:53:17 +01:00
|
|
|
static mqd_t nxmq_vopen(FAR const char *mq_name, int oflags, va_list ap)
|
|
|
|
{
|
|
|
|
struct file mq;
|
|
|
|
int created;
|
|
|
|
int ret;
|
|
|
|
|
2021-07-16 14:37:19 +02:00
|
|
|
ret = file_mq_vopen(&mq, mq_name, oflags, getumask(), ap, &created);
|
2020-12-24 13:53:17 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-10-26 12:15:16 +02:00
|
|
|
ret = file_allocate(mq.f_inode, mq.f_oflags,
|
|
|
|
mq.f_pos, mq.f_priv, 0, false);
|
2020-12-24 13:53:17 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
file_mq_close(&mq);
|
|
|
|
if (created)
|
|
|
|
{
|
|
|
|
file_mq_unlink(mq_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: file_mq_open
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function establish a connection between a named message queue and
|
|
|
|
* the calling task. This is an internal OS interface. It is functionally
|
|
|
|
* equivalent to mq_open() except that:
|
|
|
|
*
|
|
|
|
* - It is not a cancellation point, and
|
|
|
|
* - It does not modify the errno value.
|
|
|
|
*
|
|
|
|
* See comments with mq_open() for a more complete description of the
|
|
|
|
* behavior of this function
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2024-08-31 12:15:24 +02:00
|
|
|
* mq - address of to-be-initialized struct file instance.
|
2020-12-24 13:53:17 +01:00
|
|
|
* mq_name - Name of the queue to open
|
|
|
|
* oflags - open flags
|
|
|
|
* Optional parameters. When the O_CREAT flag is specified, two optional
|
|
|
|
* parameters are expected:
|
|
|
|
*
|
2021-07-09 07:43:26 +02:00
|
|
|
* 1. mode_t mode, and
|
2020-12-24 13:53:17 +01:00
|
|
|
* 2. struct mq_attr *attr. The mq_maxmsg attribute
|
|
|
|
* is used at the time that the message queue is
|
|
|
|
* created to determine the maximum number of
|
|
|
|
* messages that may be placed in the message queue.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* This is an internal OS interface and should not be used by applications.
|
|
|
|
* It follows the NuttX internal error return policy: Zero (OK) is
|
2024-08-31 12:15:24 +02:00
|
|
|
* returned on success, instance pointed by mq is also initialized.
|
2020-12-24 13:53:17 +01:00
|
|
|
* A negated errno value is returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int file_mq_open(FAR struct file *mq,
|
|
|
|
FAR const char *mq_name, int oflags, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(ap, oflags);
|
2021-07-16 14:37:19 +02:00
|
|
|
ret = file_mq_vopen(mq, mq_name, oflags, 0, ap, NULL);
|
2020-12-24 13:53:17 +01:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxmq_open
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function establish a connection between a named message queue and
|
|
|
|
* the calling task. This is an internal OS interface. It is functionally
|
|
|
|
* equivalent to mq_open() except that:
|
|
|
|
*
|
|
|
|
* - It is not a cancellation point, and
|
|
|
|
* - It does not modify the errno value.
|
|
|
|
*
|
|
|
|
* See comments with mq_open() for a more complete description of the
|
|
|
|
* behavior of this function
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* mq_name - Name of the queue to open
|
|
|
|
* oflags - open flags
|
|
|
|
* Optional parameters. When the O_CREAT flag is specified, two optional
|
|
|
|
* parameters are expected:
|
|
|
|
*
|
2021-07-09 07:43:26 +02:00
|
|
|
* 1. mode_t mode, and
|
2020-12-24 13:53:17 +01:00
|
|
|
* 2. struct mq_attr *attr. The mq_maxmsg attribute
|
|
|
|
* is used at the time that the message queue is
|
|
|
|
* created to determine the maximum number of
|
|
|
|
* messages that may be placed in the message queue.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* This is an internal OS interface and should not be used by applications.
|
|
|
|
* It follows the NuttX internal error return policy: Zero (OK) is
|
|
|
|
* returned on success, mqdes point to the new message queue descriptor.
|
|
|
|
* A negated errno value is returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
mqd_t nxmq_open(FAR const char *mq_name, int oflags, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
mqd_t ret;
|
|
|
|
|
|
|
|
va_start(ap, oflags);
|
|
|
|
ret = nxmq_vopen(mq_name, oflags, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-03 22:31:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: mq_open
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function establish a connection between a named message queue and
|
|
|
|
* the calling task. After a successful call of mq_open(), the task can
|
|
|
|
* reference the message queue using the address returned by the call. The
|
|
|
|
* message queue remains usable until it is closed by a successful call to
|
|
|
|
* mq_close().
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* mq_name - Name of the queue to open
|
|
|
|
* oflags - open flags
|
|
|
|
* Optional parameters. When the O_CREAT flag is specified, two optional
|
|
|
|
* parameters are expected:
|
|
|
|
*
|
2021-07-09 07:43:26 +02:00
|
|
|
* 1. mode_t mode, and
|
2020-05-03 22:31:05 +02:00
|
|
|
* 2. struct mq_attr *attr. The mq_maxmsg attribute
|
|
|
|
* is used at the time that the message queue is
|
|
|
|
* created to determine the maximum number of
|
|
|
|
* messages that may be placed in the message queue.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A message queue descriptor or (mqd_t)-1 (ERROR)
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2020-12-24 13:53:17 +01:00
|
|
|
mqd_t ret;
|
2020-05-03 22:31:05 +02:00
|
|
|
|
2020-12-24 13:53:17 +01:00
|
|
|
va_start(ap, oflags);
|
|
|
|
ret = nxmq_vopen(mq_name, oflags, ap);
|
|
|
|
va_end(ap);
|
2020-05-03 22:31:05 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-08-20 23:42:35 +02:00
|
|
|
set_errno(-ret);
|
2020-12-24 13:53:17 +01:00
|
|
|
return ERROR;
|
2020-05-03 22:31:05 +02:00
|
|
|
}
|
|
|
|
|
2020-12-24 13:53:17 +01:00
|
|
|
return ret;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|