如下为使用两个结构进行设置 消息队列
struct msqid_ds tmsgbuf;
tmsgbuf.msg_qbytes = m_nMsgMaxSize;
struct msginfo tmsginfo;
tmsginfo.msgmax = m_nMsgMaxSize;
tmsginfo.msgmnb = m_nMsgMaxSize;
if(msgctl(m_nMsgID, IPC_SET, &tmsgbuf) == -1)
{
perror("err:set ipcmsgbuf fail!");
return -1;
}
if(msgctl(m_nMsgID, IPC_SET, (struct msqid_ds*)&tmsginfo) == -1)
{
perror("err:set ipcmsginfo fail!");
return -1;
}
如果msqid_ds设置了,再设置 tmsginfo,会对先前设置的msqid_ds有影响
而且根据设置前后消息队列的大小和单条消息大小 限制 值 的打印,发现 只能通过 msg_qbytes 来设置消息队列整体大小,设置单条大小 msgmax 和 通过msgmnb 设置整体大小,都是不合理的。
总结,
1. 如果要设置消息整体大小,就是用 tmsgbuf.msg_qbytes ,通过msgctl(m_nMsgID, IPC_SET, &tmsgbuf) 设置,不要使用tmsginfo.msgmnb
2.程序中,只能设置消息整体大小,不能设置单条大小,要设置大条大小需通过 命令行或修改配置文件
3.不要将 msgctl(m_nMsgID, IPC_SET, &tmsgbuf) 和msgctl(m_nMsgID, IPC_SET, (struct msqid_ds*)&tmsginfo) 混用