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:
parent
9a1b726bae
commit
a4c6b179bb
@ -60,6 +60,9 @@
|
||||
*/
|
||||
|
||||
#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_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)
|
||||
@ -68,6 +71,9 @@
|
||||
# define _MQ_SETERRNO(r) set_errno(-(r))
|
||||
# define _MQ_GETERRVAL(r) (r)
|
||||
#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_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)
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user