Realistic 3D camera system
3D camera system components
Functions | Variables
asio::async_read

Start an asynchronous operation to read a certain amount of data from a stream. More...

Functions

template<typename AsyncReadStream , typename MutableBufferSequence , typename ReadHandler >
 asio::ASIO_INITFN_RESULT_TYPE (ReadHandler, void(asio::error_code, std::size_t)) async_read(AsyncReadStream &s
 
const MutableBufferSequence CompletionCondition asio::ASIO_MOVE_ARG (ReadHandler) handler)
 
template<typename AsyncReadStream , typename MutableBufferSequence , typename CompletionCondition , typename ReadHandler >
 asio::ASIO_INITFN_RESULT_TYPE (ReadHandler, void(asio::error_code, std::size_t)) async_read(AsyncReadStream &s
 

Variables

const MutableBufferSequence & asio::buffers
 
const MutableBufferSequence CompletionCondition asio::completion_condition
 
asio::basic_streambuf< Allocator > & asio::b
 
asio::basic_streambuf< Allocator > CompletionCondition asio::ASIO_MOVE_ARG (ReadHandler) handler)
 

Detailed Description

Start an asynchronous operation to read a certain amount of data from a stream.

Function Documentation

template<typename AsyncReadStream , typename MutableBufferSequence , typename CompletionCondition , typename ReadHandler >
asio::ASIO_INITFN_RESULT_TYPE ( ReadHandler  ,
void(asio::error_code, std::size_t)   
)
inline

Start an asynchronous operation to read a certain amount of data from a stream. This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The supplied buffers are full. That is, the bytes transferred is equal to the sum of the buffer sizes.
  • The completion_condition function object returns 0.
Parameters
sThe stream from which the data is to be read. The type must support the AsyncReadStream concept.
buffersOne or more buffers into which the data will be read. The sum of the buffer sizes indicates the maximum number of bytes to read from the stream. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
completion_conditionThe function object to be called to determine whether the read operation is complete. The signature of the function object must be:
std::size_t completion_condition(
// Result of latest async_read_some operation.
const asio::error_code& error,
// Number of bytes transferred so far.
std::size_t bytes_transferred
);
A return value of 0 indicates that the read operation is complete. A non-zero return value indicates the maximum number of bytes to be read on the next call to the stream's async_read_some function.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
const asio::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes copied into the
// buffers. If an error occurred,
// this will be the number of
// bytes successfully transferred
// prior to the error.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Example
To read into a single data buffer use the asio::buffer function as follows:
asio::async_read(s,
asio::buffer(data, size),
handler);
See the asio::buffer documentation for information on reading into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

Start an asynchronous operation to read a certain amount of data from a stream. This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The supplied buffer is full (that is, it has reached maximum size).
  • The completion_condition function object returns 0.

This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.

Parameters
sThe stream from which the data is to be read. The type must support the AsyncReadStream concept.
bA basic_streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
completion_conditionThe function object to be called to determine whether the read operation is complete. The signature of the function object must be:
std::size_t completion_condition(
// Result of latest async_read_some operation.
const asio::error_code& error,
// Number of bytes transferred so far.
std::size_t bytes_transferred
);
A return value of 0 indicates that the read operation is complete. A non-zero return value indicates the maximum number of bytes to be read on the next call to the stream's async_read_some function.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
const asio::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes copied into the
// buffers. If an error occurred,
// this will be the number of
// bytes successfully transferred
// prior to the error.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().

Start an asynchronous operation to read a certain amount of data at the specified offset. This function is used to asynchronously read a certain number of bytes of data from a random access device at the specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The supplied buffers are full. That is, the bytes transferred is equal to the sum of the buffer sizes.
  • The completion_condition function object returns 0.
Parameters
dThe device from which the data is to be read. The type must support the AsyncRandomAccessReadDevice concept.
offsetThe offset at which the data will be read.
buffersOne or more buffers into which the data will be read. The sum of the buffer sizes indicates the maximum number of bytes to read from the device. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
completion_conditionThe function object to be called to determine whether the read operation is complete. The signature of the function object must be:
std::size_t completion_condition(
// Result of latest async_read_some_at operation.
const asio::error_code& error,
// Number of bytes transferred so far.
std::size_t bytes_transferred
);
A return value of 0 indicates that the read operation is complete. A non-zero return value indicates the maximum number of bytes to be read on the next call to the device's async_read_some_at function.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
// Result of operation.
const asio::error_code& error,
// Number of bytes copied into the buffers. If an error
// occurred, this will be the number of bytes successfully
// transferred prior to the error.
std::size_t bytes_transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Example
To read into a single data buffer use the asio::buffer function as follows:
asio::async_read_at(d, 42,
asio::buffer(data, size),
handler);
See the asio::buffer documentation for information on reading into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

Start an asynchronous operation to read a certain amount of data at the specified offset. This function is used to asynchronously read a certain number of bytes of data from a random access device at the specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The completion_condition function object returns 0.

This operation is implemented in terms of zero or more calls to the device's async_read_some_at function.

Parameters
dThe device from which the data is to be read. The type must support the AsyncRandomAccessReadDevice concept.
offsetThe offset at which the data will be read.
bA basic_streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
completion_conditionThe function object to be called to determine whether the read operation is complete. The signature of the function object must be:
std::size_t completion_condition(
// Result of latest async_read_some_at operation.
const asio::error_code& error,
// Number of bytes transferred so far.
std::size_t bytes_transferred
);
A return value of 0 indicates that the read operation is complete. A non-zero return value indicates the maximum number of bytes to be read on the next call to the device's async_read_some_at function.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
// Result of operation.
const asio::error_code& error,
// Number of bytes copied into the buffers. If an error
// occurred, this will be the number of bytes successfully
// transferred prior to the error.
std::size_t bytes_transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().

Start an asynchronous operation to read data into a streambuf until a function object indicates a match. This function is used to asynchronously read data into the specified streambuf until a user-defined match condition function object, when applied to the data contained in the streambuf, indicates a successful match. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The match condition function object returns a std::pair where the second element evaluates to true.
  • An error occurred.

This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. If the match condition function object already indicates a match, this asynchronous operation completes immediately. The program must ensure that the stream performs no other read operations (such as async_read, async_read_until, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.

Parameters
sThe stream from which the data is to be read. The type must support the AsyncReadStream concept.
bA streambuf object into which the data will be read.
match_conditionThe function object to be called to determine whether a match exists. The signature of the function object must be:
pair<iterator, bool> match_condition(iterator begin, iterator end);
where iterator represents the type:
buffers_iterator<basic_streambuf<Allocator>::const_buffers_type>
The iterator parameters begin and end define the range of bytes to be scanned to determine whether there is a match. The first member of the return value is an iterator marking one-past-the-end of the bytes that have been consumed by the match function. This iterator is used to calculate the begin parameter for any subsequent invocation of the match condition. The second member of the return value is true if a match has been found, false otherwise.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
// Result of operation.
const asio::error_code& error,
// The number of bytes in the streambuf's get
// area that have been fully consumed by the
// match function. O if an error occurred.
std::size_t bytes_transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note
After a successful async_read_until operation, the streambuf may contain additional data beyond that which matched the function object. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.
The default implementation of the is_match_condition type trait evaluates to true for function pointers and function objects with a result_type typedef. It must be specialised for other user-defined function objects.
Examples
To asynchronously read data into a streambuf until whitespace is encountered:
std::pair<iterator, bool>
match_whitespace(iterator begin, iterator end)
{
iterator i = begin;
while (i != end)
if (std::isspace(*i++))
return std::make_pair(i, true);
return std::make_pair(i, false);
}
...
void handler(const asio::error_code& e, std::size_t size);
...
asio::streambuf b;
asio::async_read_until(s, b, match_whitespace, handler);

To asynchronously read data into a streambuf until a matching character is found:

class match_char
{
public:
explicit match_char(char c) : c_(c) {}
template <typename Iterator>
std::pair<Iterator, bool> operator()(
Iterator begin, Iterator end) const
{
Iterator i = begin;
while (i != end)
if (c_ == *i++)
return std::make_pair(i, true);
return std::make_pair(i, false);
}
private:
char c_;
};
namespace asio {
template <> struct is_match_condition<match_char>
: public boost::true_type {};
} // namespace asio
...
void handler(const asio::error_code& e, std::size_t size);
...
asio::streambuf b;
asio::async_read_until(s, b, match_char('a'), handler);
template<typename AsyncReadStream , typename MutableBufferSequence , typename ReadHandler >
asio::ASIO_INITFN_RESULT_TYPE ( ReadHandler  ,
void(asio::error_code, std::size_t)   
)
inline

Start an asynchronous operation to read a certain amount of data from a stream. This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The supplied buffers are full. That is, the bytes transferred is equal to the sum of the buffer sizes.
  • An error occurred.

This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.

Parameters
sThe stream from which the data is to be read. The type must support the AsyncReadStream concept.
buffersOne or more buffers into which the data will be read. The sum of the buffer sizes indicates the maximum number of bytes to read from the stream. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
const asio::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes copied into the
// buffers. If an error occurred,
// this will be the number of
// bytes successfully transferred
// prior to the error.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Example
To read into a single data buffer use the asio::buffer function as follows:
asio::async_read(s, asio::buffer(data, size), handler);
See the asio::buffer documentation for information on reading into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.
Note
This overload is equivalent to calling:
asio::async_read(
s, buffers,
handler);

Start an asynchronous operation to read a certain amount of data from a stream. This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The supplied buffer is full (that is, it has reached maximum size).
  • An error occurred.

This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.

Parameters
sThe stream from which the data is to be read. The type must support the AsyncReadStream concept.
bA basic_streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
const asio::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes copied into the
// buffers. If an error occurred,
// this will be the number of
// bytes successfully transferred
// prior to the error.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note
This overload is equivalent to calling:
asio::async_read(
s, b,
handler);

Start an asynchronous operation to read a certain amount of data at the specified offset. This function is used to asynchronously read a certain number of bytes of data from a random access device at the specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The supplied buffers are full. That is, the bytes transferred is equal to the sum of the buffer sizes.
  • An error occurred.

This operation is implemented in terms of zero or more calls to the device's async_read_some_at function.

Parameters
dThe device from which the data is to be read. The type must support the AsyncRandomAccessReadDevice concept.
offsetThe offset at which the data will be read.
buffersOne or more buffers into which the data will be read. The sum of the buffer sizes indicates the maximum number of bytes to read from the device. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
// Result of operation.
const asio::error_code& error,
// Number of bytes copied into the buffers. If an error
// occurred, this will be the number of bytes successfully
// transferred prior to the error.
std::size_t bytes_transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Example
To read into a single data buffer use the asio::buffer function as follows:
asio::async_read_at(d, 42, asio::buffer(data, size), handler);
See the asio::buffer documentation for information on reading into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.
Note
This overload is equivalent to calling:
asio::async_read_at(
d, 42, buffers,
handler);

Start an asynchronous operation to read a certain amount of data at the specified offset. This function is used to asynchronously read a certain number of bytes of data from a random access device at the specified offset. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • An error occurred.

This operation is implemented in terms of zero or more calls to the device's async_read_some_at function.

Parameters
dThe device from which the data is to be read. The type must support the AsyncRandomAccessReadDevice concept.
offsetThe offset at which the data will be read.
bA basic_streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
// Result of operation.
const asio::error_code& error,
// Number of bytes copied into the buffers. If an error
// occurred, this will be the number of bytes successfully
// transferred prior to the error.
std::size_t bytes_transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note
This overload is equivalent to calling:
asio::async_read_at(
d, 42, b,
handler);

Start an asynchronous operation to read data into a streambuf until it contains a specified delimiter. This function is used to asynchronously read data into the specified streambuf until the streambuf's get area contains the specified delimiter. The function call always returns immediately. The asynchronous operation will continue 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 async_read_some function, and is known as a composed operation. If the streambuf's get area already contains the delimiter, this asynchronous operation completes immediately. The program must ensure that the stream performs no other read operations (such as async_read, async_read_until, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.

Parameters
sThe stream from which the data is to be read. The type must support the AsyncReadStream concept.
bA streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
delimThe delimiter character.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
// Result of operation.
const asio::error_code& error,
// The number of bytes in the streambuf's get
// area up to and including the delimiter.
// 0 if an error occurred.
std::size_t bytes_transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note
After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.
Example
To asynchronously read data into a streambuf until a newline is encountered:
...
void handler(const asio::error_code& e, std::size_t size)
{
if (!e)
{
std::istream is(&b);
std::string line;
std::getline(is, line);
...
}
}
...
asio::async_read_until(s, b, '\n', handler);
After the async_read_until operation completes successfully, the buffer b contains the delimiter:
{ 'a', 'b', ..., 'c', '\n', 'd', 'e', ... }
The call to std::getline then extracts the data up to and including the delimiter, so that the string line contains:
{ 'a', 'b', ..., 'c', '\n' }
The remaining data is left in the buffer b as follows:
{ 'd', 'e', ... }
This data may be the start of a new line, to be extracted by a subsequent async_read_until operation.

Start an asynchronous operation to read data into a streambuf until it contains a specified delimiter. This function is used to asynchronously read data into the specified streambuf until the streambuf's get area contains the specified delimiter. The function call always returns immediately. The asynchronous operation will continue 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 async_read_some function, and is known as a composed operation. If the streambuf's get area already contains the delimiter, this asynchronous operation completes immediately. The program must ensure that the stream performs no other read operations (such as async_read, async_read_until, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.

Parameters
sThe stream from which the data is to be read. The type must support the AsyncReadStream concept.
bA streambuf object into which the data will be read. Ownership of the streambuf is retained by the caller, which must guarantee that it remains valid until the handler is called.
delimThe delimiter string.
handlerThe handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
// Result of operation.
const asio::error_code& error,
// The number of bytes in the streambuf's get
// area up to and including the delimiter.
// 0 if an error occurred.
std::size_t bytes_transferred
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note
After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.
Example
To asynchronously read data into a streambuf until a newline is encountered:
...
void handler(const asio::error_code& e, std::size_t size)
{
if (!e)
{
std::istream is(&b);
std::string line;
std::getline(is, line);
...
}
}
...
asio::async_read_until(s, b, "\r\n", handler);
After the async_read_until operation completes successfully, the buffer b contains the delimiter:
{ 'a', 'b', ..., 'c', '\r', '\n', 'd', 'e', ... }
The call to std::getline then extracts the data up to and including the delimiter, so that the string line contains:
{ 'a', 'b', ..., 'c', '\r', '\n' }
The remaining data is left in the buffer b as follows:
{ 'd', 'e', ... }
This data may be the start of a new line, to be extracted by a subsequent async_read_until operation.
const MutableBufferSequence CompletionCondition asio::ASIO_MOVE_ARG ( ReadHandler  )

Definition at line 523 of file read.hpp.

Variable Documentation

uint64_t basic_streambuf< Allocator > CompletionCondition asio::ASIO_MOVE_ARG ( ReadHandler  )

Definition at line 704 of file read.hpp.

uint64_t basic_streambuf< Allocator > & asio::b

Definition at line 702 of file read.hpp.

uint64_t const ConstBufferSequence & asio::buffers

Definition at line 521 of file read.hpp.

uint64_t basic_streambuf< Allocator > CompletionCondition asio::completion_condition

Definition at line 521 of file read.hpp.