mqueue: Add _MQ_OPEN, _MQ_CLOSE and _MQ_UNLINK macro

and replace mq_open, mq_close and mq_unlink with these in libnx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2021-02-15 13:11:27 +08:00
committed by Abdelatif Guettouche
parent 9a1b726bae
commit a4c6b179bb
4 changed files with 25 additions and 14 deletions
+15 -10
View File
@@ -43,11 +43,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <mqueue.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/signal.h>
#include <nuttx/mqueue.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxmu.h>
@@ -139,13 +139,16 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname)
attr.mq_flags = 0;
#ifdef CONFIG_NX_BLOCKING
conn->crdmq = mq_open(climqname, O_RDONLY|O_CREAT, 0666, &attr);
conn->crdmq = _MQ_OPEN(climqname, O_RDONLY | O_CREAT, 0666, &attr);
#else
conn->crdmq = mq_open(climqname, O_RDONLY|O_CREAT|O_NONBLOCK, 0666, &attr);
conn->crdmq = _MQ_OPEN(climqname, O_RDONLY | O_CREAT | O_NONBLOCK,
0666, &attr);
#endif
if (conn->crdmq == (mqd_t)-1)
if (conn->crdmq < 0)
{
gerr("ERROR: mq_open(%s) failed: %d\n", climqname, errno);
_NX_SETERRNO(conn->crdmq);
gerr("ERROR: _MQ_OPEN(%s) failed: %d\n", climqname,
_NX_GETERRNO(conn->crdmq));
goto errout_with_conn;
}
@@ -155,10 +158,12 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname)
attr.mq_msgsize = NX_MXSVRMSGLEN;
attr.mq_flags = 0;
conn->cwrmq = mq_open(svrmqname, O_WRONLY|O_CREAT, 0666, &attr);
if (conn->cwrmq == (mqd_t)-1)
conn->cwrmq = _MQ_OPEN(svrmqname, O_WRONLY | O_CREAT, 0666, &attr);
if (conn->cwrmq < 0)
{
gerr("ERROR: mq_open(%s) failed: %d\n", svrmqname, errno);
_NX_SETERRNO(conn->cwrmq);
gerr("ERROR: _MQ_OPEN(%s) failed: %d\n", svrmqname,
_NX_GETERRNO(conn->crdmq));
goto errout_with_rmq;
}
@@ -197,9 +202,9 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname)
return (NXHANDLE)conn;
errout_with_wmq:
mq_close(conn->cwrmq);
_MQ_CLOSE(conn->cwrmq);
errout_with_rmq:
mq_close(conn->crdmq);
_MQ_CLOSE(conn->crdmq);
errout_with_conn:
lib_ufree(conn);
errout:
+2 -2
View File
@@ -40,10 +40,10 @@
#include <nuttx/config.h>
#include <stdio.h>
#include <mqueue.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/mqueue.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxmu.h>
@@ -90,6 +90,6 @@ void nx_disconnect(NXHANDLE handle)
{
snprintf(climqname, sizeof(climqname),
NX_CLIENT_MQNAMEFMT, conn->cid);
mq_unlink(climqname);
_MQ_UNLINK(climqname);
}
}
+2 -2
View File
@@ -80,8 +80,8 @@ static inline void nx_disconnected(FAR struct nxmu_conn_s *conn)
{
/* Close the server and client MQs */
mq_close(conn->cwrmq);
mq_close(conn->crdmq);
_MQ_CLOSE(conn->cwrmq);
_MQ_CLOSE(conn->crdmq);
/* And free the client structure */