Rajat Singh
2013-02-15 06:21:14 UTC
I got the following error in handleRead function at boost::asio::read when
I send and receive more than 100000 of messages.
"terminate called after throwing an instance of 'boost::exception_detail::
clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error>
//Read Function
void start()
{
boost::asio::async_read(_socket,
boost::asio::buffer(_messageHeader, 8),
_strand.wrap(
boost::bind(
handleRead,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
)
);
}
void handleRead(const boost::system::error_code& e,
std::size_t bytesTransferred)
{
if (!e) {
BOOST_STATIC_ASSERT( sizeof(MessageHeader) == 8 );
Message message;
message.header.fromString(
std::string(_messageHeader.data(),
sizeof(MessageHeader)
)
);
boost::asio::read(_socket,
boost::asio::buffer(_buffer, message.header.length));
message.body = std::string(_buffer.data(),
message.header.length);
this->start();
}
else {
this->close();
}
}
//Implemented message queue to write message
void sendResponse(const Message& response)
{
std::string stringToSend(response.toString());
boost::system::error_code error;
boost::asio::ip::tcp::endpoint endpoint =
socket().remote_endpoint(error);
if ( error ) {
this->close();
}
_strand.post(
boost::bind(
&CclConnection::writeImpl,
shared_from_this(),
stringToSend
)
);
}
void CclConnection::writeImpl(const std::string &message)
{
_outbox.push_back( message );
if ( _outbox.size() > 1 ) {
return;
}
this->write();
}
void CclConnection::write()
{
const std::string& message = _outbox[0];
boost::asio::async_write(
_socket,
boost::asio::buffer( message.c_str(), message.size() ),
_strand.wrap(
boost::bind(
&CclConnection::writeHandler,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
)
);
}
void CclConnection::writeHandler(
const boost::system::error_code& e,
const size_t bytesTransferred
)
{
_outbox.pop_front();
if ( e ) {
this->close();
}
if ( !_outbox.empty() ) {
this->write();
}
}
I send and receive more than 100000 of messages.
"terminate called after throwing an instance of 'boost::exception_detail::
clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error>
' what(): asio.ssl error"
Implementation is below//Read Function
void start()
{
boost::asio::async_read(_socket,
boost::asio::buffer(_messageHeader, 8),
_strand.wrap(
boost::bind(
handleRead,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
)
);
}
void handleRead(const boost::system::error_code& e,
std::size_t bytesTransferred)
{
if (!e) {
BOOST_STATIC_ASSERT( sizeof(MessageHeader) == 8 );
Message message;
message.header.fromString(
std::string(_messageHeader.data(),
sizeof(MessageHeader)
)
);
boost::asio::read(_socket,
boost::asio::buffer(_buffer, message.header.length));
message.body = std::string(_buffer.data(),
message.header.length);
this->start();
}
else {
this->close();
}
}
//Implemented message queue to write message
void sendResponse(const Message& response)
{
std::string stringToSend(response.toString());
boost::system::error_code error;
boost::asio::ip::tcp::endpoint endpoint =
socket().remote_endpoint(error);
if ( error ) {
this->close();
}
_strand.post(
boost::bind(
&CclConnection::writeImpl,
shared_from_this(),
stringToSend
)
);
}
void CclConnection::writeImpl(const std::string &message)
{
_outbox.push_back( message );
if ( _outbox.size() > 1 ) {
return;
}
this->write();
}
void CclConnection::write()
{
const std::string& message = _outbox[0];
boost::asio::async_write(
_socket,
boost::asio::buffer( message.c_str(), message.size() ),
_strand.wrap(
boost::bind(
&CclConnection::writeHandler,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
)
);
}
void CclConnection::writeHandler(
const boost::system::error_code& e,
const size_t bytesTransferred
)
{
_outbox.pop_front();
if ( e ) {
this->close();
}
if ( !_outbox.empty() ) {
this->write();
}
}
--
*Rajat Singh*
*
*
*Rajat Singh*
*
*