mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
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:
committed by
Abdelatif Guettouche
parent
9a1b726bae
commit
a4c6b179bb
@@ -60,6 +60,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
||||||
|
# define _MQ_OPEN nxmq_open
|
||||||
|
# define _MQ_CLOSE(d) nxmq_close(d)
|
||||||
|
# define _MQ_UNLINK(n) nxmq_unlink(n)
|
||||||
# define _MQ_SEND(d,m,l,p) nxmq_send(d,m,l,p)
|
# define _MQ_SEND(d,m,l,p) nxmq_send(d,m,l,p)
|
||||||
# define _MQ_TIMEDSEND(d,m,l,p,t) nxmq_timedsend(d,m,l,p,t)
|
# define _MQ_TIMEDSEND(d,m,l,p,t) nxmq_timedsend(d,m,l,p,t)
|
||||||
# define _MQ_RECEIVE(d,m,l,p) nxmq_receive(d,m,l,p)
|
# define _MQ_RECEIVE(d,m,l,p) nxmq_receive(d,m,l,p)
|
||||||
@@ -68,6 +71,9 @@
|
|||||||
# define _MQ_SETERRNO(r) set_errno(-(r))
|
# define _MQ_SETERRNO(r) set_errno(-(r))
|
||||||
# define _MQ_GETERRVAL(r) (r)
|
# define _MQ_GETERRVAL(r) (r)
|
||||||
#else
|
#else
|
||||||
|
# define _MQ_OPEN mq_open
|
||||||
|
# define _MQ_CLOSE(d) mq_close(d)
|
||||||
|
# define _MQ_UNLINK(n) mq_unlink(n)
|
||||||
# define _MQ_SEND(d,m,l,p) mq_send(d,m,l,p)
|
# define _MQ_SEND(d,m,l,p) mq_send(d,m,l,p)
|
||||||
# define _MQ_TIMEDSEND(d,m,l,p,t) mq_timedsend(d,m,l,p,t)
|
# define _MQ_TIMEDSEND(d,m,l,p,t) mq_timedsend(d,m,l,p,t)
|
||||||
# define _MQ_RECEIVE(d,m,l,p) mq_receive(d,m,l,p)
|
# define _MQ_RECEIVE(d,m,l,p) mq_receive(d,m,l,p)
|
||||||
|
|||||||
@@ -43,11 +43,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <mqueue.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/signal.h>
|
#include <nuttx/signal.h>
|
||||||
|
#include <nuttx/mqueue.h>
|
||||||
#include <nuttx/nx/nx.h>
|
#include <nuttx/nx/nx.h>
|
||||||
#include <nuttx/nx/nxmu.h>
|
#include <nuttx/nx/nxmu.h>
|
||||||
|
|
||||||
@@ -139,13 +139,16 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname)
|
|||||||
attr.mq_flags = 0;
|
attr.mq_flags = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_NX_BLOCKING
|
#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
|
#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
|
#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;
|
goto errout_with_conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,10 +158,12 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname)
|
|||||||
attr.mq_msgsize = NX_MXSVRMSGLEN;
|
attr.mq_msgsize = NX_MXSVRMSGLEN;
|
||||||
attr.mq_flags = 0;
|
attr.mq_flags = 0;
|
||||||
|
|
||||||
conn->cwrmq = mq_open(svrmqname, O_WRONLY|O_CREAT, 0666, &attr);
|
conn->cwrmq = _MQ_OPEN(svrmqname, O_WRONLY | O_CREAT, 0666, &attr);
|
||||||
if (conn->cwrmq == (mqd_t)-1)
|
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;
|
goto errout_with_rmq;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,9 +202,9 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname)
|
|||||||
return (NXHANDLE)conn;
|
return (NXHANDLE)conn;
|
||||||
|
|
||||||
errout_with_wmq:
|
errout_with_wmq:
|
||||||
mq_close(conn->cwrmq);
|
_MQ_CLOSE(conn->cwrmq);
|
||||||
errout_with_rmq:
|
errout_with_rmq:
|
||||||
mq_close(conn->crdmq);
|
_MQ_CLOSE(conn->crdmq);
|
||||||
errout_with_conn:
|
errout_with_conn:
|
||||||
lib_ufree(conn);
|
lib_ufree(conn);
|
||||||
errout:
|
errout:
|
||||||
|
|||||||
@@ -40,10 +40,10 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <mqueue.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/mqueue.h>
|
||||||
#include <nuttx/nx/nx.h>
|
#include <nuttx/nx/nx.h>
|
||||||
#include <nuttx/nx/nxmu.h>
|
#include <nuttx/nx/nxmu.h>
|
||||||
|
|
||||||
@@ -90,6 +90,6 @@ void nx_disconnect(NXHANDLE handle)
|
|||||||
{
|
{
|
||||||
snprintf(climqname, sizeof(climqname),
|
snprintf(climqname, sizeof(climqname),
|
||||||
NX_CLIENT_MQNAMEFMT, conn->cid);
|
NX_CLIENT_MQNAMEFMT, conn->cid);
|
||||||
mq_unlink(climqname);
|
_MQ_UNLINK(climqname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ static inline void nx_disconnected(FAR struct nxmu_conn_s *conn)
|
|||||||
{
|
{
|
||||||
/* Close the server and client MQs */
|
/* Close the server and client MQs */
|
||||||
|
|
||||||
mq_close(conn->cwrmq);
|
_MQ_CLOSE(conn->cwrmq);
|
||||||
mq_close(conn->crdmq);
|
_MQ_CLOSE(conn->crdmq);
|
||||||
|
|
||||||
/* And free the client structure */
|
/* And free the client structure */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user