read_until (1 of 6 overloads)

| Home | Libraries | People | FAQ | More

#### read_until (1 of 6 overloads)

Read data into a streambuf until a delimiter is encountered.

    template<
        typename SyncReadStream,
        typename Allocator>
    std::size_t read_until(
        SyncReadStream & s,
        boost::asio::basic_streambuf< Allocator > & b,
        char delim);

This function is used to read data into the specified streambuf until the streambuf's get area contains the specified delimiter. The call will block until one of the following conditions is true:

- The get area of the streambuf contains the specified delimiter.
- An error occurred.

This operation is implemented in terms of zero or more calls to the stream's read_some function. If the streambuf's get area already contains the delimiter, the function returns immediately.

###### Parameters

s

  The stream from which the data is to be read. The type must support the SyncReadStream concept.

b

  A streambuf object into which the data will be read.

delim

  The delimiter character.

###### Return Value

The number of bytes in the streambuf's get area up to and including the delimiter.

###### Exceptions

boost::system::system_error

  Thrown on failure.

###### Example

To read data into a streambuf until a newline is encountered:

    boost::asio::streambuf b;
    boost::asio::read_until(s, b, '\n');
    std::istream is(&b);
    std::string line;
    std::getline(is, line);