i've created an async beast server that gets a request from a browser, opens a second socket , writes the request , gets the response and sends it back to the browser. all async . as the "send back to browser" action waits to the read handler completion to trigger
void
on_write(
boost::system::error_code ec,
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
if(ec)
return fail2(ec, "write");
std::cout << "===========on_write============" << std::endl;
stopper("async_write" , 0);
stopper("on_write" , 1);
// Receive the HTTP response
http::async_read(redirect_stream_, redirect_buffer_, redirect_res_,
std::bind(
&session2::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
}
void
on_read(
boost::system::error_code ec,
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
if(ec)
return fail2(ec, "read");
std::cout << "===========on_read============" << std::endl;
stopper("on_write" , 0);
stopper("on_read" , 1);
// Write the message to standard out
std::cout << redirect_res_.base() << std::endl;
http::async_write(stream_, redirect_res_,
std::bind(
&session2::start_shutdown,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
// Gracefully close the stream
}
it seems (from checks i have done) that it takes to long before the "write to browser" action is triggered (the on_read function) is there a better way to reduce the response to browser time? maybe by "read_some" method?