|
Boost Users : |
Subject: [Boost-users] throw and catch exception
From: Christer Borgqvist (christer.borgqvist10_at_[hidden])
Date: 2011-10-20 02:32:02
I have a code like this
when execute the IdHTTPServDataEMVObj.Exequte();
it will throw a std::runtime_error
if running one thread all is fine, the catch is excequted, but if running
two threads then the application crash.
What is the problem, have i miss something
appreciate any help.
huvcbo..
void server(boost::asio::io_service& io_service, short port)
{
tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
for (;;)
{
socket_ptr sock(new tcp::socket(io_service));
a.accept(*sock);
boost::thread t(boost::bind(socketclientEMVthread, sock, logFunc,
mygetFunc, mybackFunc, statusUpdateFunc));
}
}
the client thread
void socketclientEMVthread( socket_ptr sock)
{
cout << "connect on port " << sock->remote_endpoint().port() << endl;
for (;;) {
char data[max_length];
boost::system::error_code error;
size_t length = sock->read_some(boost::asio::buffer(data),
error);
if (error == boost::asio::error::eof)
break; // Connection closed cleanly by peer.
else if (error)
throw boost::system::system_error(error); // Some other
error.
std::string trans_in(data), trans_out;
CIdHTTPServDataEMVObj IdHTTPServDataEMVObj(trans_in);
try {
// this is thrown
IdHTTPServDataEMVObj.Exequte();
if ( IdHTTPServDataEMVObj.txBufferlen > 0 &&
IdHTTPServDataEMVObj.txBufferlen !=
std::string::npos) {
trans_out = IdHTTPServDataEMVObj.txBuffer;
}
else {
trans_out = trans_in;
}
}
catch(trans_error &te) {
trans_out = te.what();
boost::asio::write(*sock, boost::asio::buffer(trans_out,
trans_out.size()));
break;
}
boost::asio::write(*sock, boost::asio::buffer(trans_out,
trans_out.size()));
break;
}
}
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