#define DELAY 1
func()
{
auto readHandler = [&](const boost::system::error_code& ec, std::size_t bytesRead)->void
{
if(ec)
{
// Something went wrong
std::cerr << ec.message() << "\n";
}
};
string line;
Sleep(DELAY);
for(;;)
{
serial.async_read_some(boost::asio::buffer(&c, 1), readHandler);
line += c;
}
}
Why sleep is required before entering a loop. Without sleep, nothing is received by the buffer.