1

I need to implement synchronous blocking read using boost

boost::asio::streambuf response;
int bytes = boost::asio::read_until(socket_,response,"}\n");

But in some case it fails when the data received doesn't contain the specified delimiter or no data from the server, so I tried to implement the time out for the read, but couldn't find any solution with read_until.

And I found the example here using async_read_until by blocking the read.

deadline_timer_.expires_from_now(boost::posix_time::seconds(5));
boost::asio::streambuf response;
boost::system::error_code ec = boost::asio::error::would_block;
boost::asio::async_read_until(socket_, response, '}\n', var(ec) = boost::lambda::_1);

do io_service_.run_one(); while (ec == boost::asio::error::would_block);
if (ec)
  throw boost::system::system_error(ec);

But this also not success, while debugging the break point put below the above piece code not reached.

What could be the issue?.

Haris
  • 13,645
  • 12
  • 90
  • 121

0 Answers0