1.mq_open等相关系统函数使用
#include <iostream>
#include <algorithm>
#include <cstring>
#include <mqueue.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
using namespace std;
int main(int argc, char **argv)
{
mqd_t mqd;
struct mq_attr mqAttr;
mqAttr.mq_maxmsg = 100;
mqAttr.mq_msgsize = 100;
int flag = O_RDWR | O_CREAT;
const char *pPath = "/myqueue.1234";
if (-1 == (mqd = mq_open(pPath, flag, 0666, NULL)))
{
cout << "create mq failed!" << endl;
cout << errno << endl;
}
int len = 12;
char buff[12] = "abcde";
mq_send(mqd, buff, len, 2);
mq_getattr(mqd, &mqAttr);
cout << "maxsize:" << mqAttr.mq_msgsize << endl;
char *recvBuff = new char[mqAttr.mq_msgsize];
unsigned int priority = 0;
ssize_t recNum = mq_receive(mqd, recvBuff, 8192, &priority);
cout << recvBuff << endl;
delete [] recvBuff;
recvBuff = NULL;
mq_unlink(pPath);
return 0;
}