创建消息队列 msg_id

const int BaseMsgq::proj_id_ = static_cast<int>('a');
const char *BaseMsgq::pathname_ = "/root";

BaseMsgq::BaseMsgq()
{
    msgq_key_ = ftok(pathname_, proj_id_);
    if (msgq_key_ < 0)
    {
        LOG_ERROR("fail to ftok('%s', %d).\n", pathname_, proj_id_);
        throw -1;
    }
    
    msgq_id_ = msgget(msgq_key_, IPC_EXCL);
    if (msgq_id_ < 0)
    {
        msgq_id_ = msgget(msgq_key_, IPC_CREAT | 0666);
        if (msgq_id_ < 0)
        {
            LOG_ERROR("fail to msgget.\n");
            throw -1;
        }
    }   
        
    clear();
}      

猜你喜欢

转载自blog.csdn.net/centnetHY/article/details/83542558
今日推荐