|
Boost Users : |
Subject: [Boost-users] [message_queue.hpp]boost::interprocess_exception::library_error
From: rohini chandra pallapothu (rohinichandrap_at_[hidden])
Date: 2010-11-29 13:48:18
Hi,
I am trying to use boost message queues for interprocess communincation
between a command and a server. I had been receiving the below exception in
the server.
boost::interprocess_exception::library_error
Below is the server code I had problems with. The exception was consistent
when the maximum message size argument passed to the constructor while
creating a message queue was greater than the size of the data I was trying
to receive.I am trying to receive an integer. When I assigned the
max_msg_size variable a size greater than the size of int, it threw an
exception. When I assigned the size of int, it is working fine. But I want
to understand the correct reason behind the exception. Is it not allowed
to receive a message which is less than the maximum message size because the
name maximum message size itself says that it should only not exceed. I am
working on a 64 bit SUSE 11.
I had even tried to change the /proc/sys/kernel/shmmax value after reading
one of the discussion on the same exception in the BOOST archives which did
not work. Could anyone please help. Please let me know if you need more
information.
#include <boost/interprocess/sync/named_mutex.hpp>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <iostream>
using namespace std;
using namespace boost::interprocess;
int main(){
cout<<"in main"<<endl;
cout<<"size of int is "<<sizeof(int)<<endl; //4 on my platform
unsigned int priority;
std::size_t recvd_size;
std::size_t max_msg_size=sizeof(int); //not working when
assigned a larger value than I was sending.
std::size_t max_no_msgs=10;
int i;
message_queue::remove("TestQueue");
cout<<"message queue removed if any"<<endl;
try{
//create a message queue.
message_queue mq(create_only,"TestQueue",max_no_msgs,max_msg_size);
cout<<"message queue created"<<endl;
mq.receive(&i,sizeof(i),recvd_size,priority);
}
catch(interprocess_exception &ex){
std::cout <<ex.what() << std::endl;
return 1;
}
cout<<"message received"<<endl;
cout<<"message received is"<<i<<endl;
return 0;
}
Thanks in advance.
Best Regards,
Rohini Chandra
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net