Question: I cannot find a way to make what seems to be one of the simplest thing with the boost asio library : 

> 
> Read all the data available in a serial port
> 
> 
> 

For example in Qt there is a `readAll()` method from `QextSerialPort`.

Actually, all the examples I found are about reading a certain amount of data, or multi threaded. 

In my case I need it to read the data from a GSM controller. The response size depends on the sent command and the controller context so I can't specify it.

Answer: 
Try this:

```
boost::asio::read(
    sock,
    boost::asio::buffer(buf),
    boost::asio::transfer_at_least(1),
    ec
);

```
You want the [`transfer_all()` completion condition](http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/transfer_all.html) combined with the `read()` or `async_read()` free functions:

```
boost::array<char, 128> buf;
boost::system::error_code ec;
std::size_t n = boost::asio::read(
    sock, boost::asio::buffer(buf),
    boost::asio::transfer_all(), ec);
if (ec)
{
  // An error occurred.
}
else
{
  // n == 128
}

```