All, used to think that I was sane, now not so sure.
I am trying to create a message queue whose mq_msgsize attribute is OTHER than 8192, which seems to be the default. I have attached my code below -- it has a number of printf's showing the value. If you can point out what I doing wrong, I will be eternally grateful.
bool Subscriber::Subscribe( void )
{
mqd_t qid;
bool brv = false;
msg_topic_t topic = this->GetTopic();
struct mq_attr q_attr;
int rv = 0;
if (VALID_TOPIC( topic ))
{
if (this->GetName().length() > 0)
{
string qnamestr = this->GetName();
if (qnamestr[0] != '/')
{
qnamestr = "/" + qnamestr;
this->SetName(qnamestr);
}
const char * qname = (const char *) qnamestr.c_str();
q_attr.mq_msgsize = 256;
q_attr.mq_curmsgs = 0;
q_attr.mq_flags = O_NONBLOCK;
q_attr.mq_maxmsg = 10;
qid = mq_open( qname, O_RDONLY|O_CREAT, 0644, &q_attr );
if ((mqd_t) -1 != qid)
{
rv = mq_getattr(qid, &q_attr );
if (rv != 0)
{ perror(" get_attr1 failed: "); }
printf(" queue size is now: %d\n", q_attr.mq_msgsize);
if (q_attr.mq_msgsize > 1024)
{
struct mq_attr old_attr;
q_attr.mq_msgsize = 1024;
rv = mq_setattr( qid, &q_attr, &old_attr);
if (rv != 0)
{ perror(" could not update message size: "); }
rv = mq_getattr(qid, &q_attr );
if (rv != 0)
{ perror(" get_attr2 failed: "); }
printf(" queue size is now: %d\n", q_attr.mq_msgsize);
}
this->SetOutboxID( qid );
brv = true;
DLOG(INFO) << " qid = " << qid << endl;
MessageCenter * mc = MessageCenter::GetInstance();
mc->AddSubscriber( (Subscriber *) this );
}
}
}
drain_queue( this->GetOutboxID());
return( brv );
}
The output looks like this: queue size is now: 8192 queue size is now: 8192 queue size is now: 8192
Thank you!
The manpage says:
The mq_maxmsg and mq_msgsize fields are set when the message queue is created by mq_open(3)
and
The only attribute that can be modified is the setting of the O_NONBLOCK flag in mq_flags. The other fields in newattr are ignored.