In message queue created return ENOSPC error if size exceeds the configured size of pre-allocatd messages; Use ENOSPC vs ENOMEM per OpenGroup.org. From Pierre-Noel Bouteville
This commit is contained in:
parent
d007a49194
commit
ff87e2e02a
@ -52,17 +52,8 @@
|
||||
#include "inode/inode.h"
|
||||
#include "mqueue/mqueue.h"
|
||||
|
||||
#if 0
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
#include "sched/sched.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-procesor Definitions
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
@ -220,7 +211,7 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
|
||||
msgq = (FAR struct mqueue_inode_s*)mq_msgqalloc(mode, attr);
|
||||
if (!msgq)
|
||||
{
|
||||
errcode = ENOMEM;
|
||||
errcode = ENOSPC;
|
||||
goto errout_with_inode;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <mqueue.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/sched.h>
|
||||
@ -77,7 +78,7 @@
|
||||
*
|
||||
* Description:
|
||||
* This function implements a part of the POSIX message queue open logic.
|
||||
* It allocates and initializes a structu mqueue_inode_s structure.
|
||||
* It allocates and initializes a struct mqueue_inode_s structure.
|
||||
*
|
||||
* Parameters:
|
||||
* mode - mode_t value is ignored
|
||||
@ -86,7 +87,7 @@
|
||||
* messages that may be placed in the message queue.
|
||||
*
|
||||
* Return Value:
|
||||
* The allocated and initalized message queue structure or NULL in the
|
||||
* The allocated and initialized message queue structure or NULL in the
|
||||
* event of a failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -96,9 +97,21 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode,
|
||||
{
|
||||
FAR struct mqueue_inode_s *msgq;
|
||||
|
||||
/* Check if the caller is attempting to allocate a message for messages
|
||||
* larger than the configured maximum message size.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(!attr || attr->mq_msgsize <= MQ_MAX_BYTES);
|
||||
if (attr && attr->mq_msgsize > MQ_MAX_BYTES)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Allocate memory for the new message queue. */
|
||||
|
||||
msgq = (FAR struct mqueue_inode_s*)kmm_zalloc(sizeof(struct mqueue_inode_s));
|
||||
msgq = (FAR struct mqueue_inode_s*)
|
||||
kmm_zalloc(sizeof(struct mqueue_inode_s));
|
||||
|
||||
if (msgq)
|
||||
{
|
||||
/* Initialize the new named message queue */
|
||||
@ -107,15 +120,8 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode,
|
||||
if (attr)
|
||||
{
|
||||
msgq->maxmsgs = (int16_t)attr->mq_maxmsg;
|
||||
if (attr->mq_msgsize <= MQ_MAX_BYTES)
|
||||
{
|
||||
msgq->maxmsgsize = (int16_t)attr->mq_msgsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
msgq->maxmsgsize = MQ_MAX_BYTES;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msgq->maxmsgs = MQ_MAX_MSGS;
|
||||
|
@ -98,7 +98,7 @@ struct mqueue_msg_s
|
||||
#else
|
||||
uint16_t msglen; /* Message data length */
|
||||
#endif
|
||||
uint8_t mail[MQ_MAX_BYTES]; /* Message data */
|
||||
char mail[MQ_MAX_BYTES]; /* Message data */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user