asio 0.3.8rc3 Home | Reference | Tutorial | Examples | Design
Reference Class Hierarchy | Class Index | Member Index

asio::buffer


Detailed Description

The asio::buffer function is used to create a buffer object to represent raw memory, an array of POD elements, or a vector of POD elements.

The simplest use case involves reading or writing a single buffer of a specified size:

 sock.write(asio::buffer(data, size)); 

In the above example, the return value of asio::buffer meets the requirements of the ConstBufferSequence concept so that it may be directly passed to the socket's write function. A buffer created for modifiable memory also meets the requirements of the MutableBufferSequence concept.

An individual buffer may be created from a builtin array, std::vector or boost::array of POD elements. This helps prevent buffer overruns by automatically determining the size of the buffer:

 char d1[128];
 size_t bytes_transferred = sock.read(asio::buffer(d1));

 std::vector<char> d2(128);
 bytes_transferred = sock.read(asio::buffer(d2));

 boost::array<char, 128> d3;
 bytes_transferred = sock.read(asio::buffer(d3)); 

To read or write using multiple buffers (i.e. scatter-gather I/O), multiple buffer objects may be assigned into a container that supports the MutableBufferSequence (for read) or ConstBufferSequence (for write) concepts:

 char d1[128];
 std::vector<char> d2(128);
 boost::array<char, 128> d3;

 boost::array<mutable_buffer, 3> bufs1 = {
   asio::buffer(d1),
   asio::buffer(d2),
   asio::buffer(d3) };
 bytes_transferred = sock.read(bufs1);

 std::vector<const_buffer> bufs2;
 bufs2.push_back(asio::buffer(d1));
 bufs2.push_back(asio::buffer(d2));
 bufs2.push_back(asio::buffer(d3));
 bytes_transferred = sock.write(bufs2); 


Functions

mutable_buffers_1 asio::buffer (const mutable_buffer &b)
 Create a new modifiable buffer from an existing buffer.
mutable_buffers_1 asio::buffer (const mutable_buffer &b, std::size_t max_size_in_bytes)
 Create a new modifiable buffer from an existing buffer.
const_buffers_1 asio::buffer (const const_buffer &b)
 Create a new non-modifiable buffer from an existing buffer.
const_buffers_1 asio::buffer (const const_buffer &b, std::size_t max_size_in_bytes)
 Create a new non-modifiable buffer from an existing buffer.
mutable_buffers_1 asio::buffer (void *data, std::size_t size_in_bytes)
 Create a new modifiable buffer that represents the given memory range.
const_buffers_1 asio::buffer (const void *data, std::size_t size_in_bytes)
 Create a new non-modifiable buffer that represents the given memory range.
template<typename PodType, std::size_t N>
mutable_buffers_1 asio::buffer (PodType(&data)[N])
 Create a new modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
mutable_buffers_1 asio::buffer (PodType(&data)[N], std::size_t max_size_in_bytes)
 Create a new modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer (const PodType(&data)[N])
 Create a new non-modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer (const PodType(&data)[N], std::size_t max_size_in_bytes)
 Create a new non-modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
mutable_buffers_1 asio::buffer (boost::array< PodType, N > &data)
 Create a new modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
mutable_buffers_1 asio::buffer (boost::array< PodType, N > &data, std::size_t max_size_in_bytes)
 Create a new modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer (boost::array< const PodType, N > &data)
 Create a new non-modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer (boost::array< const PodType, N > &data, std::size_t max_size_in_bytes)
 Create a new non-modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer (const boost::array< PodType, N > &data)
 Create a new non-modifiable buffer that represents the given POD array.
template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer (const boost::array< PodType, N > &data, std::size_t max_size_in_bytes)
 Create a new non-modifiable buffer that represents the given POD array.
template<typename PodType, typename Allocator>
mutable_buffers_1 asio::buffer (std::vector< PodType, Allocator > &data)
 Create a new modifiable buffer that represents the given POD vector.
template<typename PodType, typename Allocator>
mutable_buffers_1 asio::buffer (std::vector< PodType, Allocator > &data, std::size_t max_size_in_bytes)
 Create a new modifiable buffer that represents the given POD vector.
template<typename PodType, typename Allocator>
const_buffers_1 asio::buffer (const std::vector< PodType, Allocator > &data)
 Create a new non-modifiable buffer that represents the given POD vector.
template<typename PodType, typename Allocator>
const_buffers_1 asio::buffer (const std::vector< PodType, Allocator > &data, std::size_t max_size_in_bytes)
 Create a new non-modifiable buffer that represents the given POD vector.
const_buffers_1 asio::buffer (const std::string &data)
 Create a new non-modifiable buffer that represents the given string.
const_buffers_1 asio::buffer (const std::string &data, std::size_t max_size_in_bytes)
 Create a new non-modifiable buffer that represents the given string.


Function Documentation

mutable_buffers_1 asio::buffer ( const mutable_buffer &  b  ) 

Create a new modifiable buffer from an existing buffer.

mutable_buffers_1 asio::buffer ( const mutable_buffer &  b,
std::size_t  max_size_in_bytes 
)

Create a new modifiable buffer from an existing buffer.

const_buffers_1 asio::buffer ( const const_buffer &  b  ) 

Create a new non-modifiable buffer from an existing buffer.

const_buffers_1 asio::buffer ( const const_buffer &  b,
std::size_t  max_size_in_bytes 
)

Create a new non-modifiable buffer from an existing buffer.

mutable_buffers_1 asio::buffer ( void *  data,
std::size_t  size_in_bytes 
)

Create a new modifiable buffer that represents the given memory range.

const_buffers_1 asio::buffer ( const void *  data,
std::size_t  size_in_bytes 
)

Create a new non-modifiable buffer that represents the given memory range.

template<typename PodType, std::size_t N>
mutable_buffers_1 asio::buffer ( PodType &  data[N]  ) 

Create a new modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
mutable_buffers_1 asio::buffer ( PodType &  data[N],
std::size_t  max_size_in_bytes 
)

Create a new modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer ( const PodType &  data[N]  ) 

Create a new non-modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer ( const PodType &  data[N],
std::size_t  max_size_in_bytes 
)

Create a new non-modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
mutable_buffers_1 asio::buffer ( boost::array< PodType, N > &  data  ) 

Create a new modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
mutable_buffers_1 asio::buffer ( boost::array< PodType, N > &  data,
std::size_t  max_size_in_bytes 
)

Create a new modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer ( boost::array< const PodType, N > &  data  ) 

Create a new non-modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer ( boost::array< const PodType, N > &  data,
std::size_t  max_size_in_bytes 
)

Create a new non-modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer ( const boost::array< PodType, N > &  data  ) 

Create a new non-modifiable buffer that represents the given POD array.

template<typename PodType, std::size_t N>
const_buffers_1 asio::buffer ( const boost::array< PodType, N > &  data,
std::size_t  max_size_in_bytes 
)

Create a new non-modifiable buffer that represents the given POD array.

template<typename PodType, typename Allocator>
mutable_buffers_1 asio::buffer ( std::vector< PodType, Allocator > &  data  ) 

Create a new modifiable buffer that represents the given POD vector.

Note:
The buffer is invalidated by any vector operation that would also invalidate iterators.

template<typename PodType, typename Allocator>
mutable_buffers_1 asio::buffer ( std::vector< PodType, Allocator > &  data,
std::size_t  max_size_in_bytes 
)

Create a new modifiable buffer that represents the given POD vector.

Note:
The buffer is invalidated by any vector operation that would also invalidate iterators.

template<typename PodType, typename Allocator>
const_buffers_1 asio::buffer ( const std::vector< PodType, Allocator > &  data  ) 

Create a new non-modifiable buffer that represents the given POD vector.

Note:
The buffer is invalidated by any vector operation that would also invalidate iterators.

template<typename PodType, typename Allocator>
const_buffers_1 asio::buffer ( const std::vector< PodType, Allocator > &  data,
std::size_t  max_size_in_bytes 
)

Create a new non-modifiable buffer that represents the given POD vector.

Note:
The buffer is invalidated by any vector operation that would also invalidate iterators.

const_buffers_1 asio::buffer ( const std::string &  data  ) 

Create a new non-modifiable buffer that represents the given string.

Note:
The buffer is invalidated by any non-const operation called on the given string object.

const_buffers_1 asio::buffer ( const std::string &  data,
std::size_t  max_size_in_bytes 
)

Create a new non-modifiable buffer that represents the given string.

Note:
The buffer is invalidated by any non-const operation called on the given string object.

asio 0.3.8rc3 Home | Reference | Tutorial | Examples | Design