Skip to content

Commit

Permalink
mqueue: Add _MQ_OPEN, _MQ_CLOSE and _MQ_UNLINK macro
Browse files Browse the repository at this point in the history
and replace mq_open, mq_close and mq_unlink with these in libnx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 authored and Ouss4 committed Feb 19, 2021
1 parent 9a1b726 commit a4c6b17
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
6 changes: 6 additions & 0 deletions include/nuttx/mqueue.h
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
25 changes: 15 additions & 10 deletions libs/libnx/nxmu/nx_connect.c
Expand Up @@ -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>

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions libs/libnx/nxmu/nx_disconnect.c
Expand Up @@ -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>

Expand Down Expand Up @@ -90,6 +90,6 @@ void nx_disconnect(NXHANDLE handle)
{
snprintf(climqname, sizeof(climqname),
NX_CLIENT_MQNAMEFMT, conn->cid);
mq_unlink(climqname);
_MQ_UNLINK(climqname);
}
}
4 changes: 2 additions & 2 deletions libs/libnx/nxmu/nx_eventhandler.c
Expand Up @@ -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 */

Expand Down

0 comments on commit a4c6b17

Please sign in to comment.