| Home | Libraries | People | FAQ | More

# boost::asio::read_until

## Functions

template<typename Sync_Read_Stream, typename Allocator>
std::size_t | boost::asio::read_until (Sync_Read_Stream &s, boost::asio::basic_streambuf< Allocator > &b, char delim)
| Read data into a streambuf until a delimiter is encountered.
template<typename Sync_Read_Stream, typename Allocator, typename Error_Handler>
std::size_t | boost::asio::read_until (Sync_Read_Stream &s, boost::asio::basic_streambuf< Allocator > &b, char delim, Error_Handler error_handler)
| Read data into a streambuf until a delimiter is encountered.
template<typename Sync_Read_Stream, typename Allocator>
std::size_t | boost::asio::read_until (Sync_Read_Stream &s, boost::asio::basic_streambuf< Allocator > &b, const boost::regex &expr)
| Read data into a streambuf until a regular expression is located.
template<typename Sync_Read_Stream, typename Allocator, typename Error_Handler>
std::size_t | boost::asio::read_until (Sync_Read_Stream &s, boost::asio::basic_streambuf< Allocator > &b, const boost::regex &expr, Error_Handler error_handler)
| Read data into a streambuf until a regular expression is located.

## Function Documentation

template<typename Sync_Read_Stream, typename Allocator>

std::size_t boost::asio::read_until | ( | Sync_Read_Stream & | s,
|  | boost::asio::basic_streambuf< Allocator > & | b,
|  | char | delim |
| ) |  |  |

Read data into a streambuf until a delimiter is encountered.

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 Sync_Read_Stream concept.
  | b | A streambuf object into which the data will be read.
  | delim | The delimiter character.

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

Exceptions:

  | Sync_Read_Stream::error_type | 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);

Note:
  This overload is equivalent to calling:

       boost::asio::read_until(
           s, b, delim,
           boost::asio::throw_error());

template<typename Sync_Read_Stream, typename Allocator, typename Error_Handler>

std::size_t boost::asio::read_until | ( | Sync_Read_Stream & | s,
|  | boost::asio::basic_streambuf< Allocator > & | b,
|  | char | delim,
|  | Error_Handler | error_handler |
| ) |  |  |

Read data into a streambuf until a delimiter is encountered.

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 Sync_Read_Stream concept.
  | b | A streambuf object into which the data will be read.
  | delim | The delimiter character.
  | error_handler | A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:
       void error_handler(
         const Sync_Read_Stream::error_type& error // Result of operation.
       );
  The error handler is only called if the completion_condition indicates that the operation is complete.

Returns:
  The number of bytes in the streambuf's get area up to and including the delimiter. Returns 0 if an error occurred and the error handler did not throw an exception.

template<typename Sync_Read_Stream, typename Allocator>

std::size_t boost::asio::read_until | ( | Sync_Read_Stream & | s,
|  | boost::asio::basic_streambuf< Allocator > & | b,
|  | const boost::regex & | expr |
| ) |  |  |

Read data into a streambuf until a regular expression is located.

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

- A substring of the streambuf's get area matches the regular expression.

- 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 data that matches the regular expression, the function returns immediately.

Parameters:

  | s | The stream from which the data is to be read. The type must support the Sync_Read_Stream concept.
  | b | A streambuf object into which the data will be read.
  | expr | The regular expression.

Returns:
  The number of bytes in the streambuf's get area up to and including the substring that matches the regular expression.

Exceptions:

  | Sync_Read_Stream::error_type | Thrown on failure.

Example:
  To read data into a streambuf until a CR-LF sequence is encountered:

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

Note:
  This overload is equivalent to calling:

       boost::asio::read_until(
           s, b, expr,
           boost::asio::throw_error());

template<typename Sync_Read_Stream, typename Allocator, typename Error_Handler>

std::size_t boost::asio::read_until | ( | Sync_Read_Stream & | s,
|  | boost::asio::basic_streambuf< Allocator > & | b,
|  | const boost::regex & | expr,
|  | Error_Handler | error_handler |
| ) |  |  |

Read data into a streambuf until a regular expression is located.

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

- A substring of the streambuf's get area matches the regular expression.

- 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 data that matches the regular expression, the function returns immediately.

Parameters:

  | s | The stream from which the data is to be read. The type must support the Sync_Read_Stream concept.
  | b | A streambuf object into which the data will be read.
  | expr | The regular expression.
  | error_handler | A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:
       void error_handler(
         const Sync_Read_Stream::error_type& error // Result of operation.
       );
  The error handler is only called if the completion_condition indicates that the operation is complete.

Returns:
  The number of bytes in the streambuf's get area up to and including the substring that matches the regular expression.

| Copyright © 2003 - 2006 Christopher M. Kohlhoff