summaryrefslogtreecommitdiff
path: root/boost/asio/buffer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/asio/buffer.hpp')
-rw-r--r--boost/asio/buffer.hpp149
1 files changed, 124 insertions, 25 deletions
diff --git a/boost/asio/buffer.hpp b/boost/asio/buffer.hpp
index 532cfd1b59..450face65e 100644
--- a/boost/asio/buffer.hpp
+++ b/boost/asio/buffer.hpp
@@ -2,7 +2,7 @@
// buffer.hpp
// ~~~~~~~~~~
//
-// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -20,16 +20,15 @@
#include <cstring>
#include <string>
#include <vector>
-#include <boost/detail/workaround.hpp>
#include <boost/asio/detail/array_fwd.hpp>
-#if defined(BOOST_MSVC)
+#if defined(BOOST_ASIO_MSVC)
# if defined(_HAS_ITERATOR_DEBUGGING) && (_HAS_ITERATOR_DEBUGGING != 0)
# if !defined(BOOST_ASIO_DISABLE_BUFFER_DEBUGGING)
# define BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
# endif // !defined(BOOST_ASIO_DISABLE_BUFFER_DEBUGGING)
# endif // defined(_HAS_ITERATOR_DEBUGGING)
-#endif // defined(BOOST_MSVC)
+#endif // defined(BOOST_ASIO_MSVC)
#if defined(__GNUC__)
# if defined(_GLIBCXX_DEBUG)
@@ -40,14 +39,21 @@
#endif // defined(__GNUC__)
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
-# include <boost/function.hpp>
+# include <boost/asio/detail/function.hpp>
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
-#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) \
- || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
-# include <boost/type_traits/is_const.hpp>
-#endif // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
- // || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
+#if defined(BOOST_ASIO_HAS_BOOST_WORKAROUND)
+# include <boost/detail/workaround.hpp>
+# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) \
+ || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
+# define BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND
+# endif // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
+ // || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
+#endif // defined(BOOST_ASIO_HAS_BOOST_WORKAROUND)
+
+#if defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
+# include <boost/asio/detail/type_traits.hpp>
+#endif // defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
#include <boost/asio/detail/push_options.hpp>
@@ -102,14 +108,14 @@ public:
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
mutable_buffer(void* data, std::size_t size,
- boost::function<void()> debug_check)
+ boost::asio::detail::function<void()> debug_check)
: data_(data),
size_(size),
debug_check_(debug_check)
{
}
- const boost::function<void()>& get_debug_check() const
+ const boost::asio::detail::function<void()>& get_debug_check() const
{
return debug_check_;
}
@@ -125,7 +131,7 @@ private:
std::size_t size_;
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
- boost::function<void()> debug_check_;
+ boost::asio::detail::function<void()> debug_check_;
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
};
@@ -232,14 +238,14 @@ public:
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
const_buffer(const void* data, std::size_t size,
- boost::function<void()> debug_check)
+ boost::asio::detail::function<void()> debug_check)
: data_(data),
size_(size),
debug_check_(debug_check)
{
}
- const boost::function<void()>& get_debug_check() const
+ const boost::asio::detail::function<void()>& get_debug_check() const
{
return debug_check_;
}
@@ -255,7 +261,7 @@ private:
std::size_t size_;
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
- boost::function<void()> debug_check_;
+ boost::asio::detail::function<void()> debug_check_;
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
};
@@ -512,12 +518,12 @@ public:
~buffer_debug_check()
{
-#if BOOST_WORKAROUND(BOOST_MSVC, == 1400)
+#if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC == 1400)
// MSVC 8's string iterator checking may crash in a std::string::iterator
// object's destructor when the iterator points to an already-destroyed
// std::string object, unless the iterator is cleared first.
iter_ = Iterator();
-#endif // BOOST_WORKAROUND(BOOST_MSVC, == 1400)
+#endif // defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC == 1400)
}
void operator()()
@@ -612,6 +618,9 @@ private:
* vector<unsigned char> data(boost::asio::buffer_size(buffers));
* boost::asio::buffer_copy(boost::asio::buffer(data), buffers); @endcode
*
+ * Note that @ref buffer_copy is implemented in terms of @c memcpy, and
+ * consequently it cannot be used to copy between overlapping memory regions.
+ *
* @par Buffer Invalidation
*
* A buffer object does not have any ownership of the memory it refers to. It
@@ -828,8 +837,7 @@ inline const_buffers_1 buffer(const PodType (&data)[N],
? N * sizeof(PodType) : max_size_in_bytes));
}
-#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) \
- || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
+#if defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
// Borland C++ and Sun Studio think the overloads:
//
@@ -864,7 +872,7 @@ struct buffer_types_base<true>
template <typename PodType>
struct buffer_types
- : public buffer_types_base<boost::is_const<PodType>::value>
+ : public buffer_types_base<is_const<PodType>::value>
{
};
@@ -896,8 +904,7 @@ buffer(boost::array<PodType, N>& data, std::size_t max_size_in_bytes)
? data.size() * sizeof(PodType) : max_size_in_bytes));
}
-#else // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
- // || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
+#else // defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
/// Create a new modifiable buffer that represents the given POD array.
/**
@@ -961,8 +968,7 @@ inline const_buffers_1 buffer(boost::array<const PodType, N>& data,
? data.size() * sizeof(PodType) : max_size_in_bytes));
}
-#endif // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
- // || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
+#endif // defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
/// Create a new non-modifiable buffer that represents the given POD array.
/**
@@ -1262,6 +1268,9 @@ inline const_buffers_1 buffer(
*
* This prevents buffer overflow, regardless of the buffer sizes used in the
* copy operation.
+ *
+ * Note that @ref buffer_copy is implemented in terms of @c memcpy, and
+ * consequently it cannot be used to copy between overlapping memory regions.
*/
/*@{*/
@@ -1280,6 +1289,9 @@ inline const_buffers_1 buffer(
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffer& target,
const const_buffer& source)
@@ -1307,6 +1319,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffer& target,
const const_buffers_1& source)
@@ -1330,6 +1345,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffer& target,
const mutable_buffer& source)
@@ -1353,6 +1371,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffer& target,
const mutable_buffers_1& source)
@@ -1375,6 +1396,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename ConstBufferSequence>
std::size_t buffer_copy(const mutable_buffer& target,
@@ -1412,6 +1436,9 @@ std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffers_1& target,
const const_buffer& source)
@@ -1434,6 +1461,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffers_1& target,
const const_buffers_1& source)
@@ -1458,6 +1488,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffers_1& target,
const mutable_buffer& source)
@@ -1482,6 +1515,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffers_1& target,
const mutable_buffers_1& source)
@@ -1505,6 +1541,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename ConstBufferSequence>
inline std::size_t buffer_copy(const mutable_buffers_1& target,
@@ -1528,6 +1567,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence>
std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -1565,6 +1607,9 @@ std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence>
inline std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -1589,6 +1634,9 @@ inline std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence>
inline std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -1613,6 +1661,9 @@ inline std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence>
inline std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -1636,6 +1687,9 @@ inline std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(target)
*
* @li @c buffer_size(source)
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence, typename ConstBufferSequence>
std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -1701,6 +1755,9 @@ std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffer& target,
const const_buffer& source, std::size_t max_bytes_to_copy)
@@ -1727,6 +1784,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffer& target,
const const_buffers_1& source, std::size_t max_bytes_to_copy)
@@ -1754,6 +1814,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffer& target,
const mutable_buffer& source, std::size_t max_bytes_to_copy)
@@ -1781,6 +1844,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffer& target,
const mutable_buffers_1& source, std::size_t max_bytes_to_copy)
@@ -1808,6 +1874,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename ConstBufferSequence>
inline std::size_t buffer_copy(const mutable_buffer& target,
@@ -1835,6 +1904,9 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffers_1& target,
const const_buffer& source, std::size_t max_bytes_to_copy)
@@ -1861,6 +1933,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffers_1& target,
const const_buffers_1& source, std::size_t max_bytes_to_copy)
@@ -1888,6 +1963,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffers_1& target,
const mutable_buffer& source, std::size_t max_bytes_to_copy)
@@ -1915,6 +1993,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
inline std::size_t buffer_copy(const mutable_buffers_1& target,
const mutable_buffers_1& source, std::size_t max_bytes_to_copy)
@@ -1942,6 +2023,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename ConstBufferSequence>
inline std::size_t buffer_copy(const mutable_buffers_1& target,
@@ -1970,6 +2054,9 @@ inline std::size_t buffer_copy(const mutable_buffers_1& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence>
inline std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -1998,6 +2085,9 @@ inline std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence>
inline std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -2027,6 +2117,9 @@ inline std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence>
inline std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -2056,6 +2149,9 @@ inline std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence>
inline std::size_t buffer_copy(const MutableBufferSequence& target,
@@ -2084,6 +2180,9 @@ inline std::size_t buffer_copy(const MutableBufferSequence& target,
* @li @c buffer_size(source)
*
* @li @c max_bytes_to_copy
+ *
+ * This function is implemented in terms of @c memcpy, and consequently it
+ * cannot be used to copy between overlapping memory regions.
*/
template <typename MutableBufferSequence, typename ConstBufferSequence>
std::size_t buffer_copy(const MutableBufferSequence& target,