Hello all,
I want to implement a timedout asynchronous socket read. My application extends json_rpc_server:
myapi::myapi(cppcms::service &srv) :cppcms::rpc::json_rpc_server(srv) ...
I have this class, "base_who", which has this method:
std::string base_who::timedout_request(cppcms::service &srv, std::string command){
... /* connect the socket, send some command etc */ ...
booster::aio::deadline_timer timer(srv.get_io_service());
timer.expires_from_now(booster::ptime::seconds(100));
timer.async_wait(std::bind(&base_who::on_timeout,shared_from_this(),std::placeholders::_1));
std::cout << "AFTER ASYNC WAIT" << std::endl;
the_socket.async_read_some(
booster::aio::buffer(async_buffer_,sizeof(async_buffer_)),
std::bind(&base_who::on_read,shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
... /* etc */ ...
}
The problem is that when I call timer.async_wait, something happens and I receive "Internal Service Error" somewhere. The line "AFTER ASYNC WAIT" is never reached.
I think this is because of this (from timer's async_wait method description):
/// Wait asynchronously for the timer.
///
/// If io_service is not assigned throws system::system_error, all other errors reported via \a h
So, I think the io_service is not correctly assigned.
The base_who class is used in a method in myapi and timedout_request is called from there:
void myapi::request(std::string command) {
base_who myconnection(ip, port);
myconnection.timedout_request(service(), std::string("some_command"));
... /* etc */ ...
}
Do I use timer.async_wait correctly? I saw something similar in the json_rpc_chat example, but that uses <boost/bind.hpp>. I would like to not include it, use just "booster".
What could be the problem?
Thank you,
--
Fatol Sergiu Adrian
Team Leader & Senior PHP Developer
Arobs Transilvania Software
adi...@ar...
Skype: sergiu.adrian
Olimpia Business Center
98-100 Dorobantilor, 2nd Floor
400609 Cluj-Napoca Romania
Co-Founder -- Sosetaria.ro
http://sosetaria.ro
|