stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork

This commit is contained in:
2026-02-24 18:38:47 +00:00
parent da8c28aaeb
commit 65cb2619a7
13106 changed files with 2484322 additions and 1804 deletions
@@ -0,0 +1,360 @@
//
// impl/buffered_read_stream.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_BUFFERED_READ_STREAM_HPP
#define BOOST_ASIO_IMPL_BUFFERED_READ_STREAM_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename Stream>
std::size_t buffered_read_stream<Stream>::fill()
{
detail::buffer_resize_guard<detail::buffered_stream_storage>
resize_guard(storage_);
std::size_t previous_size = storage_.size();
storage_.resize(storage_.capacity());
storage_.resize(previous_size + next_layer_.read_some(buffer(
storage_.data() + previous_size,
storage_.size() - previous_size)));
resize_guard.commit();
return storage_.size() - previous_size;
}
template <typename Stream>
std::size_t buffered_read_stream<Stream>::fill(boost::system::error_code& ec)
{
detail::buffer_resize_guard<detail::buffered_stream_storage>
resize_guard(storage_);
std::size_t previous_size = storage_.size();
storage_.resize(storage_.capacity());
storage_.resize(previous_size + next_layer_.read_some(buffer(
storage_.data() + previous_size,
storage_.size() - previous_size),
ec));
resize_guard.commit();
return storage_.size() - previous_size;
}
namespace detail
{
template <typename ReadHandler>
class buffered_fill_handler
{
public:
buffered_fill_handler(detail::buffered_stream_storage& storage,
std::size_t previous_size, ReadHandler& handler)
: storage_(storage),
previous_size_(previous_size),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
buffered_fill_handler(const buffered_fill_handler& other)
: storage_(other.storage_),
previous_size_(other.previous_size_),
handler_(other.handler_)
{
}
buffered_fill_handler(buffered_fill_handler&& other)
: storage_(other.storage_),
previous_size_(other.previous_size_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_transferred)
{
storage_.resize(previous_size_ + bytes_transferred);
handler_(ec, bytes_transferred);
}
//private:
detail::buffered_stream_storage& storage_;
std::size_t previous_size_;
ReadHandler handler_;
};
template <typename ReadHandler>
inline void* asio_handler_allocate(std::size_t size,
buffered_fill_handler<ReadHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename ReadHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
buffered_fill_handler<ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename ReadHandler>
inline bool asio_handler_is_continuation(
buffered_fill_handler<ReadHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename ReadHandler>
inline void asio_handler_invoke(Function& function,
buffered_fill_handler<ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename ReadHandler>
inline void asio_handler_invoke(const Function& function,
buffered_fill_handler<ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename Stream>
template <typename ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
buffered_read_stream<Stream>::async_fill(
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
std::size_t previous_size = storage_.size();
storage_.resize(storage_.capacity());
next_layer_.async_read_some(
buffer(
storage_.data() + previous_size,
storage_.size() - previous_size),
detail::buffered_fill_handler<BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void (boost::system::error_code, std::size_t))>(
storage_, previous_size, init.handler));
return init.result.get();
}
template <typename Stream>
template <typename MutableBufferSequence>
std::size_t buffered_read_stream<Stream>::read_some(
const MutableBufferSequence& buffers)
{
if (boost::asio::buffer_size(buffers) == 0)
return 0;
if (storage_.empty())
this->fill();
return this->copy(buffers);
}
template <typename Stream>
template <typename MutableBufferSequence>
std::size_t buffered_read_stream<Stream>::read_some(
const MutableBufferSequence& buffers, boost::system::error_code& ec)
{
ec = boost::system::error_code();
if (boost::asio::buffer_size(buffers) == 0)
return 0;
if (storage_.empty() && !this->fill(ec))
return 0;
return this->copy(buffers);
}
namespace detail
{
template <typename MutableBufferSequence, typename ReadHandler>
class buffered_read_some_handler
{
public:
buffered_read_some_handler(detail::buffered_stream_storage& storage,
const MutableBufferSequence& buffers, ReadHandler& handler)
: storage_(storage),
buffers_(buffers),
handler_(handler)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
buffered_read_some_handler(const buffered_read_some_handler& other)
: storage_(other.storage_),
buffers_(other.buffers_),
handler_(other.handler_)
{
}
buffered_read_some_handler(buffered_read_some_handler&& other)
: storage_(other.storage_),
buffers_(other.buffers_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec, std::size_t)
{
if (ec || storage_.empty())
{
const std::size_t length = 0;
handler_(ec, length);
}
else
{
const std::size_t bytes_copied = boost::asio::buffer_copy(
buffers_, storage_.data(), storage_.size());
storage_.consume(bytes_copied);
handler_(ec, bytes_copied);
}
}
//private:
detail::buffered_stream_storage& storage_;
MutableBufferSequence buffers_;
ReadHandler handler_;
};
template <typename MutableBufferSequence, typename ReadHandler>
inline void* asio_handler_allocate(std::size_t size,
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename MutableBufferSequence, typename ReadHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename MutableBufferSequence, typename ReadHandler>
inline bool asio_handler_is_continuation(
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename MutableBufferSequence,
typename ReadHandler>
inline void asio_handler_invoke(Function& function,
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename MutableBufferSequence,
typename ReadHandler>
inline void asio_handler_invoke(const Function& function,
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename Stream>
template <typename MutableBufferSequence, typename ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
buffered_read_stream<Stream>::async_read_some(
const MutableBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
if (boost::asio::buffer_size(buffers) == 0 || !storage_.empty())
{
next_layer_.async_read_some(boost::asio::mutable_buffers_1(0, 0),
detail::buffered_read_some_handler<
MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void (boost::system::error_code, std::size_t))>(
storage_, buffers, init.handler));
}
else
{
this->async_fill(detail::buffered_read_some_handler<
MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void (boost::system::error_code, std::size_t))>(
storage_, buffers, init.handler));
}
return init.result.get();
}
template <typename Stream>
template <typename MutableBufferSequence>
std::size_t buffered_read_stream<Stream>::peek(
const MutableBufferSequence& buffers)
{
if (storage_.empty())
this->fill();
return this->peek_copy(buffers);
}
template <typename Stream>
template <typename MutableBufferSequence>
std::size_t buffered_read_stream<Stream>::peek(
const MutableBufferSequence& buffers, boost::system::error_code& ec)
{
ec = boost::system::error_code();
if (storage_.empty() && !this->fill(ec))
return 0;
return this->peek_copy(buffers);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_BUFFERED_READ_STREAM_HPP
@@ -0,0 +1,340 @@
//
// impl/buffered_write_stream.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
#define BOOST_ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename Stream>
std::size_t buffered_write_stream<Stream>::flush()
{
std::size_t bytes_written = write(next_layer_,
buffer(storage_.data(), storage_.size()));
storage_.consume(bytes_written);
return bytes_written;
}
template <typename Stream>
std::size_t buffered_write_stream<Stream>::flush(boost::system::error_code& ec)
{
std::size_t bytes_written = write(next_layer_,
buffer(storage_.data(), storage_.size()),
transfer_all(), ec);
storage_.consume(bytes_written);
return bytes_written;
}
namespace detail
{
template <typename WriteHandler>
class buffered_flush_handler
{
public:
buffered_flush_handler(detail::buffered_stream_storage& storage,
WriteHandler& handler)
: storage_(storage),
handler_(handler)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
buffered_flush_handler(const buffered_flush_handler& other)
: storage_(other.storage_),
handler_(other.handler_)
{
}
buffered_flush_handler(buffered_flush_handler&& other)
: storage_(other.storage_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_written)
{
storage_.consume(bytes_written);
handler_(ec, bytes_written);
}
//private:
detail::buffered_stream_storage& storage_;
WriteHandler handler_;
};
template <typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
buffered_flush_handler<WriteHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
buffered_flush_handler<WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename WriteHandler>
inline bool asio_handler_is_continuation(
buffered_flush_handler<WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename WriteHandler>
inline void asio_handler_invoke(Function& function,
buffered_flush_handler<WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
buffered_flush_handler<WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
}
template <typename Stream>
template <typename WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
buffered_write_stream<Stream>::async_flush(
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
async_write(next_layer_, buffer(storage_.data(), storage_.size()),
detail::buffered_flush_handler<BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
storage_, init.handler));
return init.result.get();
}
template <typename Stream>
template <typename ConstBufferSequence>
std::size_t buffered_write_stream<Stream>::write_some(
const ConstBufferSequence& buffers)
{
if (boost::asio::buffer_size(buffers) == 0)
return 0;
if (storage_.size() == storage_.capacity())
this->flush();
return this->copy(buffers);
}
template <typename Stream>
template <typename ConstBufferSequence>
std::size_t buffered_write_stream<Stream>::write_some(
const ConstBufferSequence& buffers, boost::system::error_code& ec)
{
ec = boost::system::error_code();
if (boost::asio::buffer_size(buffers) == 0)
return 0;
if (storage_.size() == storage_.capacity() && !flush(ec))
return 0;
return this->copy(buffers);
}
namespace detail
{
template <typename ConstBufferSequence, typename WriteHandler>
class buffered_write_some_handler
{
public:
buffered_write_some_handler(detail::buffered_stream_storage& storage,
const ConstBufferSequence& buffers, WriteHandler& handler)
: storage_(storage),
buffers_(buffers),
handler_(handler)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
buffered_write_some_handler(const buffered_write_some_handler& other)
: storage_(other.storage_),
buffers_(other.buffers_),
handler_(other.handler_)
{
}
buffered_write_some_handler(buffered_write_some_handler&& other)
: storage_(other.storage_),
buffers_(other.buffers_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec, std::size_t)
{
if (ec)
{
const std::size_t length = 0;
handler_(ec, length);
}
else
{
std::size_t orig_size = storage_.size();
std::size_t space_avail = storage_.capacity() - orig_size;
std::size_t bytes_avail = boost::asio::buffer_size(buffers_);
std::size_t length = bytes_avail < space_avail
? bytes_avail : space_avail;
storage_.resize(orig_size + length);
const std::size_t bytes_copied = boost::asio::buffer_copy(
storage_.data() + orig_size, buffers_, length);
handler_(ec, bytes_copied);
}
}
//private:
detail::buffered_stream_storage& storage_;
ConstBufferSequence buffers_;
WriteHandler handler_;
};
template <typename ConstBufferSequence, typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename ConstBufferSequence, typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename ConstBufferSequence, typename WriteHandler>
inline bool asio_handler_is_continuation(
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename ConstBufferSequence,
typename WriteHandler>
inline void asio_handler_invoke(Function& function,
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename ConstBufferSequence,
typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename Stream>
template <typename ConstBufferSequence, typename WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
buffered_write_stream<Stream>::async_write_some(
const ConstBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
if (boost::asio::buffer_size(buffers) == 0
|| storage_.size() < storage_.capacity())
{
next_layer_.async_write_some(boost::asio::const_buffers_1(0, 0),
detail::buffered_write_some_handler<
ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
storage_, buffers, init.handler));
}
else
{
this->async_flush(detail::buffered_write_some_handler<
ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
storage_, buffers, init.handler));
}
return init.result.get();
}
template <typename Stream>
template <typename ConstBufferSequence>
std::size_t buffered_write_stream<Stream>::copy(
const ConstBufferSequence& buffers)
{
std::size_t orig_size = storage_.size();
std::size_t space_avail = storage_.capacity() - orig_size;
std::size_t bytes_avail = boost::asio::buffer_size(buffers);
std::size_t length = bytes_avail < space_avail ? bytes_avail : space_avail;
storage_.resize(orig_size + length);
return boost::asio::buffer_copy(
storage_.data() + orig_size, buffers, length);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
@@ -0,0 +1,432 @@
//
// impl/connect.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_CONNECT_HPP
#define BOOST_ASIO_IMPL_CONNECT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail
{
struct default_connect_condition
{
template <typename Iterator>
Iterator operator()(const boost::system::error_code&, Iterator next)
{
return next;
}
};
}
template <typename Protocol, typename SocketService, typename Iterator>
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin)
{
boost::system::error_code ec;
Iterator result = connect(s, begin, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename SocketService, typename Iterator>
inline Iterator connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, boost::system::error_code& ec)
{
return connect(s, begin, Iterator(), detail::default_connect_condition(), ec);
}
template <typename Protocol, typename SocketService, typename Iterator>
Iterator connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, Iterator end)
{
boost::system::error_code ec;
Iterator result = connect(s, begin, end, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename SocketService, typename Iterator>
inline Iterator connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, Iterator end, boost::system::error_code& ec)
{
return connect(s, begin, end, detail::default_connect_condition(), ec);
}
template <typename Protocol, typename SocketService,
typename Iterator, typename ConnectCondition>
Iterator connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, ConnectCondition connect_condition)
{
boost::system::error_code ec;
Iterator result = connect(s, begin, connect_condition, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename SocketService,
typename Iterator, typename ConnectCondition>
inline Iterator connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, ConnectCondition connect_condition,
boost::system::error_code& ec)
{
return connect(s, begin, Iterator(), connect_condition, ec);
}
template <typename Protocol, typename SocketService,
typename Iterator, typename ConnectCondition>
Iterator connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, Iterator end, ConnectCondition connect_condition)
{
boost::system::error_code ec;
Iterator result = connect(s, begin, end, connect_condition, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename SocketService,
typename Iterator, typename ConnectCondition>
Iterator connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, Iterator end, ConnectCondition connect_condition,
boost::system::error_code& ec)
{
ec = boost::system::error_code();
for (Iterator iter = begin; iter != end; ++iter)
{
iter = connect_condition(ec, iter);
if (iter != end)
{
s.close(ec);
s.connect(*iter, ec);
if (!ec)
return iter;
}
else
break;
}
if (!ec)
ec = boost::asio::error::not_found;
return end;
}
namespace detail
{
// Enable the empty base class optimisation for the connect condition.
template <typename ConnectCondition>
class base_from_connect_condition
{
protected:
explicit base_from_connect_condition(
const ConnectCondition& connect_condition)
: connect_condition_(connect_condition)
{
}
template <typename Iterator>
void check_condition(const boost::system::error_code& ec,
Iterator& iter, Iterator& end)
{
if (iter != end)
iter = connect_condition_(ec, static_cast<const Iterator&>(iter));
}
private:
ConnectCondition connect_condition_;
};
// The default_connect_condition implementation is essentially a no-op. This
// template specialisation lets us eliminate all costs associated with it.
template <>
class base_from_connect_condition<default_connect_condition>
{
protected:
explicit base_from_connect_condition(const default_connect_condition&)
{
}
template <typename Iterator>
void check_condition(const boost::system::error_code&, Iterator&, Iterator&)
{
}
};
template <typename Protocol, typename SocketService, typename Iterator,
typename ConnectCondition, typename ComposedConnectHandler>
class connect_op : base_from_connect_condition<ConnectCondition>
{
public:
connect_op(basic_socket<Protocol, SocketService>& sock,
const Iterator& begin, const Iterator& end,
const ConnectCondition& connect_condition,
ComposedConnectHandler& handler)
: base_from_connect_condition<ConnectCondition>(connect_condition),
socket_(sock),
iter_(begin),
end_(end),
start_(0),
handler_(BOOST_ASIO_MOVE_CAST(ComposedConnectHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
connect_op(const connect_op& other)
: base_from_connect_condition<ConnectCondition>(other),
socket_(other.socket_),
iter_(other.iter_),
end_(other.end_),
start_(other.start_),
handler_(other.handler_)
{
}
connect_op(connect_op&& other)
: base_from_connect_condition<ConnectCondition>(other),
socket_(other.socket_),
iter_(other.iter_),
end_(other.end_),
start_(other.start_),
handler_(BOOST_ASIO_MOVE_CAST(ComposedConnectHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(boost::system::error_code ec, int start = 0)
{
switch (start_ = start)
{
case 1:
for (;;)
{
this->check_condition(ec, iter_, end_);
if (iter_ != end_)
{
socket_.close(ec);
socket_.async_connect(*iter_,
BOOST_ASIO_MOVE_CAST(connect_op)(*this));
return;
}
if (start)
{
ec = boost::asio::error::not_found;
socket_.get_io_service().post(detail::bind_handler(*this, ec));
return;
}
default:
if (iter_ == end_)
break;
if (!socket_.is_open())
{
ec = boost::asio::error::operation_aborted;
break;
}
if (!ec)
break;
++iter_;
}
handler_(static_cast<const boost::system::error_code&>(ec),
static_cast<const Iterator&>(iter_));
}
}
//private:
basic_socket<Protocol, SocketService>& socket_;
Iterator iter_;
Iterator end_;
int start_;
ComposedConnectHandler handler_;
};
template <typename Protocol, typename SocketService, typename Iterator,
typename ConnectCondition, typename ComposedConnectHandler>
inline void* asio_handler_allocate(std::size_t size,
connect_op<Protocol, SocketService, Iterator,
ConnectCondition, ComposedConnectHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename Protocol, typename SocketService, typename Iterator,
typename ConnectCondition, typename ComposedConnectHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
connect_op<Protocol, SocketService, Iterator,
ConnectCondition, ComposedConnectHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename Protocol, typename SocketService, typename Iterator,
typename ConnectCondition, typename ComposedConnectHandler>
inline bool asio_handler_is_continuation(
connect_op<Protocol, SocketService, Iterator,
ConnectCondition, ComposedConnectHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename Protocol,
typename SocketService, typename Iterator,
typename ConnectCondition, typename ComposedConnectHandler>
inline void asio_handler_invoke(Function& function,
connect_op<Protocol, SocketService, Iterator,
ConnectCondition, ComposedConnectHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename Protocol,
typename SocketService, typename Iterator,
typename ConnectCondition, typename ComposedConnectHandler>
inline void asio_handler_invoke(const Function& function,
connect_op<Protocol, SocketService, Iterator,
ConnectCondition, ComposedConnectHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename Protocol, typename SocketService,
typename Iterator, typename ComposedConnectHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
void (boost::system::error_code, Iterator))
async_connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ComposedConnectHandler.
BOOST_ASIO_COMPOSED_CONNECT_HANDLER_CHECK(
ComposedConnectHandler, handler, Iterator) type_check;
detail::async_result_init<ComposedConnectHandler,
void (boost::system::error_code, Iterator)> init(
BOOST_ASIO_MOVE_CAST(ComposedConnectHandler)(handler));
detail::connect_op<Protocol, SocketService, Iterator,
detail::default_connect_condition, BOOST_ASIO_HANDLER_TYPE(
ComposedConnectHandler, void (boost::system::error_code, Iterator))>(s,
begin, Iterator(), detail::default_connect_condition(), init.handler)(
boost::system::error_code(), 1);
return init.result.get();
}
template <typename Protocol, typename SocketService,
typename Iterator, typename ComposedConnectHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
void (boost::system::error_code, Iterator))
async_connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, Iterator end,
BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ComposedConnectHandler.
BOOST_ASIO_COMPOSED_CONNECT_HANDLER_CHECK(
ComposedConnectHandler, handler, Iterator) type_check;
detail::async_result_init<ComposedConnectHandler,
void (boost::system::error_code, Iterator)> init(
BOOST_ASIO_MOVE_CAST(ComposedConnectHandler)(handler));
detail::connect_op<Protocol, SocketService, Iterator,
detail::default_connect_condition, BOOST_ASIO_HANDLER_TYPE(
ComposedConnectHandler, void (boost::system::error_code, Iterator))>(s,
begin, end, detail::default_connect_condition(), init.handler)(
boost::system::error_code(), 1);
return init.result.get();
}
template <typename Protocol, typename SocketService, typename Iterator,
typename ConnectCondition, typename ComposedConnectHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
void (boost::system::error_code, Iterator))
async_connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, ConnectCondition connect_condition,
BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ComposedConnectHandler.
BOOST_ASIO_COMPOSED_CONNECT_HANDLER_CHECK(
ComposedConnectHandler, handler, Iterator) type_check;
detail::async_result_init<ComposedConnectHandler,
void (boost::system::error_code, Iterator)> init(
BOOST_ASIO_MOVE_CAST(ComposedConnectHandler)(handler));
detail::connect_op<Protocol, SocketService, Iterator,
ConnectCondition, BOOST_ASIO_HANDLER_TYPE(
ComposedConnectHandler, void (boost::system::error_code, Iterator))>(s,
begin, Iterator(), connect_condition, init.handler)(
boost::system::error_code(), 1);
return init.result.get();
}
template <typename Protocol, typename SocketService, typename Iterator,
typename ConnectCondition, typename ComposedConnectHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler,
void (boost::system::error_code, Iterator))
async_connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, Iterator end, ConnectCondition connect_condition,
BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ComposedConnectHandler.
BOOST_ASIO_COMPOSED_CONNECT_HANDLER_CHECK(
ComposedConnectHandler, handler, Iterator) type_check;
detail::async_result_init<ComposedConnectHandler,
void (boost::system::error_code, Iterator)> init(
BOOST_ASIO_MOVE_CAST(ComposedConnectHandler)(handler));
detail::connect_op<Protocol, SocketService, Iterator,
ConnectCondition, BOOST_ASIO_HANDLER_TYPE(
ComposedConnectHandler, void (boost::system::error_code, Iterator))>(s,
begin, end, connect_condition, init.handler)(
boost::system::error_code(), 1);
return init.result.get();
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_CONNECT_HPP
@@ -0,0 +1,130 @@
//
// impl/error.ipp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_ERROR_IPP
#define BOOST_ASIO_IMPL_ERROR_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace error {
#if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
namespace detail {
class netdb_category : public boost::system::error_category
{
public:
const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT
{
return "asio.netdb";
}
std::string message(int value) const
{
if (value == error::host_not_found)
return "Host not found (authoritative)";
if (value == error::host_not_found_try_again)
return "Host not found (non-authoritative), try again later";
if (value == error::no_data)
return "The query is valid, but it does not have associated data";
if (value == error::no_recovery)
return "A non-recoverable error occurred during database lookup";
return "asio.netdb error";
}
};
} // namespace detail
const boost::system::error_category& get_netdb_category()
{
static detail::netdb_category instance;
return instance;
}
namespace detail {
class addrinfo_category : public boost::system::error_category
{
public:
const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT
{
return "asio.addrinfo";
}
std::string message(int value) const
{
if (value == error::service_not_found)
return "Service not found";
if (value == error::socket_type_not_supported)
return "Socket type not supported";
return "asio.addrinfo error";
}
};
} // namespace detail
const boost::system::error_category& get_addrinfo_category()
{
static detail::addrinfo_category instance;
return instance;
}
#endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
namespace detail {
class misc_category : public boost::system::error_category
{
public:
const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT
{
return "asio.misc";
}
std::string message(int value) const
{
if (value == error::already_open)
return "Already open";
if (value == error::eof)
return "End of file";
if (value == error::not_found)
return "Element not found";
if (value == error::fd_set_failure)
return "The descriptor does not fit into the select call's fd_set";
return "asio.misc error";
}
};
} // namespace detail
const boost::system::error_category& get_misc_category()
{
static detail::misc_category instance;
return instance;
}
} // namespace error
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_ERROR_IPP
@@ -0,0 +1,79 @@
//
// impl/handler_alloc_hook.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
#define BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/call_stack.hpp>
#include <boost/asio/handler_alloc_hook.hpp>
#if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
# if defined(BOOST_ASIO_HAS_IOCP)
# include <boost/asio/detail/win_iocp_thread_info.hpp>
# else // defined(BOOST_ASIO_HAS_IOCP)
# include <boost/asio/detail/task_io_service_thread_info.hpp>
# endif // defined(BOOST_ASIO_HAS_IOCP)
#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(BOOST_ASIO_HAS_IOCP)
namespace detail { class win_iocp_io_service; }
#endif // defined(BOOST_ASIO_HAS_IOCP)
void* asio_handler_allocate(std::size_t size, ...)
{
#if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
# if defined(BOOST_ASIO_HAS_IOCP)
typedef detail::win_iocp_io_service io_service_impl;
typedef detail::win_iocp_thread_info thread_info;
# else // defined(BOOST_ASIO_HAS_IOCP)
typedef detail::task_io_service io_service_impl;
typedef detail::task_io_service_thread_info thread_info;
# endif // defined(BOOST_ASIO_HAS_IOCP)
typedef detail::call_stack<io_service_impl, thread_info> call_stack;
return thread_info::allocate(call_stack::top(), size);
#else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
return ::operator new(size);
#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
}
void asio_handler_deallocate(void* pointer, std::size_t size, ...)
{
#if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
# if defined(BOOST_ASIO_HAS_IOCP)
typedef detail::win_iocp_io_service io_service_impl;
typedef detail::win_iocp_thread_info thread_info;
# else // defined(BOOST_ASIO_HAS_IOCP)
typedef detail::task_io_service io_service_impl;
typedef detail::task_io_service_thread_info thread_info;
# endif // defined(BOOST_ASIO_HAS_IOCP)
typedef detail::call_stack<io_service_impl, thread_info> call_stack;
thread_info::deallocate(call_stack::top(), pointer, size);
#else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
(void)size;
::operator delete(pointer);
#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
@@ -0,0 +1,156 @@
//
// impl/io_service.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_IO_SERVICE_HPP
#define BOOST_ASIO_IMPL_IO_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/service_registry.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename Service>
inline Service& use_service(io_service& ios)
{
// Check that Service meets the necessary type requirements.
(void)static_cast<io_service::service*>(static_cast<Service*>(0));
(void)static_cast<const io_service::id*>(&Service::id);
return ios.service_registry_->template use_service<Service>();
}
template <>
inline detail::io_service_impl& use_service<detail::io_service_impl>(
io_service& ios)
{
return ios.impl_;
}
template <typename Service>
inline void add_service(io_service& ios, Service* svc)
{
// Check that Service meets the necessary type requirements.
(void)static_cast<io_service::service*>(static_cast<Service*>(0));
(void)static_cast<const io_service::id*>(&Service::id);
ios.service_registry_->template add_service<Service>(svc);
}
template <typename Service>
inline bool has_service(io_service& ios)
{
// Check that Service meets the necessary type requirements.
(void)static_cast<io_service::service*>(static_cast<Service*>(0));
(void)static_cast<const io_service::id*>(&Service::id);
return ios.service_registry_->template has_service<Service>();
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HAS_IOCP)
# include <boost/asio/detail/win_iocp_io_service.hpp>
#else
# include <boost/asio/detail/task_io_service.hpp>
#endif
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename CompletionHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
io_service::dispatch(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a CompletionHandler.
BOOST_ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check;
detail::async_result_init<
CompletionHandler, void ()> init(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler));
impl_.dispatch(init.handler);
return init.result.get();
}
template <typename CompletionHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
io_service::post(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a CompletionHandler.
BOOST_ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check;
detail::async_result_init<
CompletionHandler, void ()> init(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler));
impl_.post(init.handler);
return init.result.get();
}
template <typename Handler>
#if defined(GENERATING_DOCUMENTATION)
unspecified
#else
inline detail::wrapped_handler<io_service&, Handler>
#endif
io_service::wrap(Handler handler)
{
return detail::wrapped_handler<io_service&, Handler>(*this, handler);
}
inline io_service::work::work(boost::asio::io_service& io_service)
: io_service_impl_(io_service.impl_)
{
io_service_impl_.work_started();
}
inline io_service::work::work(const work& other)
: io_service_impl_(other.io_service_impl_)
{
io_service_impl_.work_started();
}
inline io_service::work::~work()
{
io_service_impl_.work_finished();
}
inline boost::asio::io_service& io_service::work::get_io_service()
{
return io_service_impl_.get_io_service();
}
inline boost::asio::io_service& io_service::service::get_io_service()
{
return owner_;
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_IO_SERVICE_HPP
@@ -0,0 +1,157 @@
//
// impl/io_service.ipp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_IO_SERVICE_IPP
#define BOOST_ASIO_IMPL_IO_SERVICE_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/detail/limits.hpp>
#include <boost/asio/detail/scoped_ptr.hpp>
#include <boost/asio/detail/service_registry.hpp>
#include <boost/asio/detail/throw_error.hpp>
#if defined(BOOST_ASIO_HAS_IOCP)
# include <boost/asio/detail/win_iocp_io_service.hpp>
#else
# include <boost/asio/detail/task_io_service.hpp>
#endif
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
io_service::io_service()
: service_registry_(new boost::asio::detail::service_registry(
*this, static_cast<impl_type*>(0),
(std::numeric_limits<std::size_t>::max)())),
impl_(service_registry_->first_service<impl_type>())
{
}
io_service::io_service(std::size_t concurrency_hint)
: service_registry_(new boost::asio::detail::service_registry(
*this, static_cast<impl_type*>(0), concurrency_hint)),
impl_(service_registry_->first_service<impl_type>())
{
}
io_service::~io_service()
{
delete service_registry_;
}
std::size_t io_service::run()
{
boost::system::error_code ec;
std::size_t s = impl_.run(ec);
boost::asio::detail::throw_error(ec);
return s;
}
std::size_t io_service::run(boost::system::error_code& ec)
{
return impl_.run(ec);
}
std::size_t io_service::run_one()
{
boost::system::error_code ec;
std::size_t s = impl_.run_one(ec);
boost::asio::detail::throw_error(ec);
return s;
}
std::size_t io_service::run_one(boost::system::error_code& ec)
{
return impl_.run_one(ec);
}
std::size_t io_service::poll()
{
boost::system::error_code ec;
std::size_t s = impl_.poll(ec);
boost::asio::detail::throw_error(ec);
return s;
}
std::size_t io_service::poll(boost::system::error_code& ec)
{
return impl_.poll(ec);
}
std::size_t io_service::poll_one()
{
boost::system::error_code ec;
std::size_t s = impl_.poll_one(ec);
boost::asio::detail::throw_error(ec);
return s;
}
std::size_t io_service::poll_one(boost::system::error_code& ec)
{
return impl_.poll_one(ec);
}
void io_service::stop()
{
impl_.stop();
}
bool io_service::stopped() const
{
return impl_.stopped();
}
void io_service::reset()
{
impl_.reset();
}
void io_service::notify_fork(boost::asio::io_service::fork_event event)
{
service_registry_->notify_fork(event);
}
io_service::service::service(boost::asio::io_service& owner)
: owner_(owner),
next_(0)
{
}
io_service::service::~service()
{
}
void io_service::service::fork_service(boost::asio::io_service::fork_event)
{
}
service_already_exists::service_already_exists()
: std::logic_error("Service already exists.")
{
}
invalid_service_owner::invalid_service_owner()
: std::logic_error("Invalid service owner.")
{
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_IO_SERVICE_IPP
@@ -0,0 +1,755 @@
//
// impl/read.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_READ_HPP
#define BOOST_ASIO_IMPL_READ_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <algorithm>
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
#include <boost/asio/detail/array_fwd.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/dependent_type.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename SyncReadStream, typename MutableBufferSequence,
typename CompletionCondition>
std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<
mutable_buffer, MutableBufferSequence> tmp(buffers);
std::size_t total_transferred = 0;
tmp.prepare(detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred)));
while (tmp.begin() != tmp.end())
{
std::size_t bytes_transferred = s.read_some(tmp, ec);
tmp.consume(bytes_transferred);
total_transferred += bytes_transferred;
tmp.prepare(detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred)));
}
return total_transferred;
}
template <typename SyncReadStream, typename MutableBufferSequence>
inline std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s, buffers, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
template <typename SyncReadStream, typename MutableBufferSequence>
inline std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
boost::system::error_code& ec)
{
return read(s, buffers, transfer_all(), ec);
}
template <typename SyncReadStream, typename MutableBufferSequence,
typename CompletionCondition>
inline std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s, buffers, completion_condition, ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncReadStream, typename Allocator,
typename CompletionCondition>
std::size_t read(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
std::size_t total_transferred = 0;
std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
std::size_t bytes_available = read_size_helper(b, max_size);
while (bytes_available > 0)
{
std::size_t bytes_transferred = s.read_some(b.prepare(bytes_available), ec);
b.commit(bytes_transferred);
total_transferred += bytes_transferred;
max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
bytes_available = read_size_helper(b, max_size);
}
return total_transferred;
}
template <typename SyncReadStream, typename Allocator>
inline std::size_t read(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s, b, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
template <typename SyncReadStream, typename Allocator>
inline std::size_t read(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
boost::system::error_code& ec)
{
return read(s, b, transfer_all(), ec);
}
template <typename SyncReadStream, typename Allocator,
typename CompletionCondition>
inline std::size_t read(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s, b, completion_condition, ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename AsyncReadStream, typename MutableBufferSequence,
typename CompletionCondition, typename ReadHandler>
class read_op
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_op(AsyncReadStream& stream, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_op(const read_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_op(read_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
switch (start_ = start)
{
case 1:
buffers_.prepare(this->check_for_completion(ec, total_transferred_));
for (;;)
{
stream_.async_read_some(buffers_,
BOOST_ASIO_MOVE_CAST(read_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
buffers_.prepare(this->check_for_completion(ec, total_transferred_));
if ((!ec && bytes_transferred == 0)
|| buffers_.begin() == buffers_.end())
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncReadStream& stream_;
boost::asio::detail::consuming_buffers<
mutable_buffer, MutableBufferSequence> buffers_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
template <typename AsyncReadStream,
typename CompletionCondition, typename ReadHandler>
class read_op<AsyncReadStream, boost::asio::mutable_buffers_1,
CompletionCondition, ReadHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_op(AsyncReadStream& stream,
const boost::asio::mutable_buffers_1& buffers,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffer_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_op(const read_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_op(read_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
stream_.async_read_some(
boost::asio::buffer(buffer_ + total_transferred_, n),
BOOST_ASIO_MOVE_CAST(read_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncReadStream& stream_;
boost::asio::mutable_buffer buffer_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename Elem,
typename CompletionCondition, typename ReadHandler>
class read_op<AsyncReadStream, boost::array<Elem, 2>,
CompletionCondition, ReadHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_op(AsyncReadStream& stream, const boost::array<Elem, 2>& buffers,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_op(const read_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_op(read_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
boost::array<boost::asio::mutable_buffer, 2> >::type bufs = {{
boost::asio::mutable_buffer(buffers_[0]),
boost::asio::mutable_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
stream_.async_read_some(bufs, BOOST_ASIO_MOVE_CAST(read_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncReadStream& stream_;
boost::array<Elem, 2> buffers_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
#if defined(BOOST_ASIO_HAS_STD_ARRAY)
template <typename AsyncReadStream, typename Elem,
typename CompletionCondition, typename ReadHandler>
class read_op<AsyncReadStream, std::array<Elem, 2>,
CompletionCondition, ReadHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_op(AsyncReadStream& stream, const std::array<Elem, 2>& buffers,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_op(const read_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_op(read_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
std::array<boost::asio::mutable_buffer, 2> >::type bufs = {{
boost::asio::mutable_buffer(buffers_[0]),
boost::asio::mutable_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
stream_.async_read_some(bufs, BOOST_ASIO_MOVE_CAST(read_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncReadStream& stream_;
std::array<Elem, 2> buffers_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
#endif // defined(BOOST_ASIO_HAS_STD_ARRAY)
template <typename AsyncReadStream, typename MutableBufferSequence,
typename CompletionCondition, typename ReadHandler>
inline void* asio_handler_allocate(std::size_t size,
read_op<AsyncReadStream, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename AsyncReadStream, typename MutableBufferSequence,
typename CompletionCondition, typename ReadHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
read_op<AsyncReadStream, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename AsyncReadStream, typename MutableBufferSequence,
typename CompletionCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_op<AsyncReadStream, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename AsyncReadStream,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void asio_handler_invoke(Function& function,
read_op<AsyncReadStream, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename AsyncReadStream,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void asio_handler_invoke(const Function& function,
read_op<AsyncReadStream, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename AsyncReadStream, typename MutableBufferSequence,
typename CompletionCondition, typename ReadHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::read_op<AsyncReadStream, MutableBufferSequence,
CompletionCondition, BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void (boost::system::error_code, std::size_t))>(
s, buffers, completion_condition, init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
template <typename AsyncReadStream, typename MutableBufferSequence,
typename ReadHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::read_op<AsyncReadStream, MutableBufferSequence,
detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void (boost::system::error_code, std::size_t))>(
s, buffers, transfer_all(), init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename AsyncReadStream, typename Allocator,
typename CompletionCondition, typename ReadHandler>
class read_streambuf_op
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_streambuf_op(AsyncReadStream& stream,
basic_streambuf<Allocator>& streambuf,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
streambuf_(streambuf),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_streambuf_op(const read_streambuf_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
streambuf_(other.streambuf_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_streambuf_op(read_streambuf_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
streambuf_(other.streambuf_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size, bytes_available;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available = read_size_helper(streambuf_, max_size);
for (;;)
{
stream_.async_read_some(streambuf_.prepare(bytes_available),
BOOST_ASIO_MOVE_CAST(read_streambuf_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
streambuf_.commit(bytes_transferred);
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available = read_size_helper(streambuf_, max_size);
if ((!ec && bytes_transferred == 0) || bytes_available == 0)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncReadStream& stream_;
boost::asio::basic_streambuf<Allocator>& streambuf_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline void* asio_handler_allocate(std::size_t size,
read_streambuf_op<AsyncReadStream, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename AsyncReadStream, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
read_streambuf_op<AsyncReadStream, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename AsyncReadStream, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_streambuf_op<AsyncReadStream, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename AsyncReadStream,
typename Allocator, typename CompletionCondition, typename ReadHandler>
inline void asio_handler_invoke(Function& function,
read_streambuf_op<AsyncReadStream, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename AsyncReadStream,
typename Allocator, typename CompletionCondition, typename ReadHandler>
inline void asio_handler_invoke(const Function& function,
read_streambuf_op<AsyncReadStream, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename AsyncReadStream, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read(AsyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::read_streambuf_op<AsyncReadStream, Allocator,
CompletionCondition, BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void (boost::system::error_code, std::size_t))>(
s, b, completion_condition, init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
template <typename AsyncReadStream, typename Allocator, typename ReadHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read(AsyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::read_streambuf_op<AsyncReadStream, Allocator,
detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void (boost::system::error_code, std::size_t))>(
s, b, transfer_all(), init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_READ_HPP
@@ -0,0 +1,812 @@
//
// impl/read_at.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_READ_AT_HPP
#define BOOST_ASIO_IMPL_READ_AT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <algorithm>
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
#include <boost/asio/detail/array_fwd.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/dependent_type.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
typename CompletionCondition>
std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<
mutable_buffer, MutableBufferSequence> tmp(buffers);
std::size_t total_transferred = 0;
tmp.prepare(detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred)));
while (tmp.begin() != tmp.end())
{
std::size_t bytes_transferred = d.read_some_at(
offset + total_transferred, tmp, ec);
tmp.consume(bytes_transferred);
total_transferred += bytes_transferred;
tmp.prepare(detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred)));
}
return total_transferred;
}
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_at(
d, offset, buffers, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
boost::system::error_code& ec)
{
return read_at(d, offset, buffers, transfer_all(), ec);
}
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
typename CompletionCondition>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_at(
d, offset, buffers, completion_condition, ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition>
std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
std::size_t total_transferred = 0;
std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
std::size_t bytes_available = read_size_helper(b, max_size);
while (bytes_available > 0)
{
std::size_t bytes_transferred = d.read_some_at(
offset + total_transferred, b.prepare(bytes_available), ec);
b.commit(bytes_transferred);
total_transferred += bytes_transferred;
max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
bytes_available = read_size_helper(b, max_size);
}
return total_transferred;
}
template <typename SyncRandomAccessReadDevice, typename Allocator>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_at(
d, offset, b, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
template <typename SyncRandomAccessReadDevice, typename Allocator>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
boost::system::error_code& ec)
{
return read_at(d, offset, b, transfer_all(), ec);
}
template <typename SyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_at(
d, offset, b, completion_condition, ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
class read_at_op
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_at_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_at_op(const read_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_at_op(read_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
switch (start_ = start)
{
case 1:
buffers_.prepare(this->check_for_completion(ec, total_transferred_));
for (;;)
{
device_.async_read_some_at(offset_ + total_transferred_,
buffers_, BOOST_ASIO_MOVE_CAST(read_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
buffers_.prepare(this->check_for_completion(ec, total_transferred_));
if ((!ec && bytes_transferred == 0)
|| buffers_.begin() == buffers_.end())
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessReadDevice& device_;
uint64_t offset_;
boost::asio::detail::consuming_buffers<
mutable_buffer, MutableBufferSequence> buffers_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
template <typename AsyncRandomAccessReadDevice,
typename CompletionCondition, typename ReadHandler>
class read_at_op<AsyncRandomAccessReadDevice,
boost::asio::mutable_buffers_1, CompletionCondition, ReadHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_at_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, const boost::asio::mutable_buffers_1& buffers,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffer_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_at_op(const read_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_at_op(read_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
device_.async_read_some_at(offset_ + total_transferred_,
boost::asio::buffer(buffer_ + total_transferred_, n),
BOOST_ASIO_MOVE_CAST(read_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessReadDevice& device_;
uint64_t offset_;
boost::asio::mutable_buffer buffer_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
template <typename AsyncRandomAccessReadDevice, typename Elem,
typename CompletionCondition, typename ReadHandler>
class read_at_op<AsyncRandomAccessReadDevice, boost::array<Elem, 2>,
CompletionCondition, ReadHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_at_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, const boost::array<Elem, 2>& buffers,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_at_op(const read_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_at_op(read_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
boost::array<boost::asio::mutable_buffer, 2> >::type bufs = {{
boost::asio::mutable_buffer(buffers_[0]),
boost::asio::mutable_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
device_.async_read_some_at(offset_ + total_transferred_,
bufs, BOOST_ASIO_MOVE_CAST(read_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessReadDevice& device_;
uint64_t offset_;
boost::array<Elem, 2> buffers_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
#if defined(BOOST_ASIO_HAS_STD_ARRAY)
template <typename AsyncRandomAccessReadDevice, typename Elem,
typename CompletionCondition, typename ReadHandler>
class read_at_op<AsyncRandomAccessReadDevice, std::array<Elem, 2>,
CompletionCondition, ReadHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_at_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, const std::array<Elem, 2>& buffers,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_at_op(const read_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_at_op(read_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
std::array<boost::asio::mutable_buffer, 2> >::type bufs = {{
boost::asio::mutable_buffer(buffers_[0]),
boost::asio::mutable_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
device_.async_read_some_at(offset_ + total_transferred_,
bufs, BOOST_ASIO_MOVE_CAST(read_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessReadDevice& device_;
uint64_t offset_;
std::array<Elem, 2> buffers_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
#endif // defined(BOOST_ASIO_HAS_STD_ARRAY)
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void* asio_handler_allocate(std::size_t size,
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline bool asio_handler_is_continuation(
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void asio_handler_invoke(Function& function,
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline void asio_handler_invoke(const Function& function,
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
typename ReadHandler>
inline read_at_op<AsyncRandomAccessReadDevice,
MutableBufferSequence, CompletionCondition, ReadHandler>
make_read_at_op(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, ReadHandler handler)
{
return read_at_op<AsyncRandomAccessReadDevice,
MutableBufferSequence, CompletionCondition, ReadHandler>(
d, offset, buffers, completion_condition, handler);
}
} // namespace detail
template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
typename CompletionCondition, typename ReadHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
CompletionCondition, BOOST_ASIO_HANDLER_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))>(
d, offset, buffers, completion_condition, init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
typename ReadHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))>(
d, offset, buffers, transfer_all(), init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
class read_at_streambuf_op
: detail::base_from_completion_cond<CompletionCondition>
{
public:
read_at_streambuf_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, basic_streambuf<Allocator>& streambuf,
CompletionCondition completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
streambuf_(streambuf),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
read_at_streambuf_op(const read_at_streambuf_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
streambuf_(other.streambuf_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_at_streambuf_op(read_at_streambuf_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
streambuf_(other.streambuf_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size, bytes_available;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available = read_size_helper(streambuf_, max_size);
for (;;)
{
device_.async_read_some_at(offset_ + total_transferred_,
streambuf_.prepare(bytes_available),
BOOST_ASIO_MOVE_CAST(read_at_streambuf_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
streambuf_.commit(bytes_transferred);
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available = read_size_helper(streambuf_, max_size);
if ((!ec && bytes_transferred == 0) || bytes_available == 0)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessReadDevice& device_;
uint64_t offset_;
boost::asio::basic_streambuf<Allocator>& streambuf_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline void* asio_handler_allocate(std::size_t size,
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename AsyncRandomAccessReadDevice,
typename Allocator, typename CompletionCondition, typename ReadHandler>
inline void asio_handler_invoke(Function& function,
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename AsyncRandomAccessReadDevice,
typename Allocator, typename CompletionCondition, typename ReadHandler>
inline void asio_handler_invoke(const Function& function,
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, BOOST_ASIO_HANDLER_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))>(
d, offset, b, completion_condition, init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename ReadHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))>(
d, offset, b, transfer_all(), init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_READ_AT_HPP
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,61 @@
//
// impl/serial_port_base.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.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)
//
#ifndef BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
#define BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
inline serial_port_base::baud_rate::baud_rate(unsigned int rate)
: value_(rate)
{
}
inline unsigned int serial_port_base::baud_rate::value() const
{
return value_;
}
inline serial_port_base::flow_control::type
serial_port_base::flow_control::value() const
{
return value_;
}
inline serial_port_base::parity::type serial_port_base::parity::value() const
{
return value_;
}
inline serial_port_base::stop_bits::type
serial_port_base::stop_bits::value() const
{
return value_;
}
inline unsigned int serial_port_base::character_size::value() const
{
return value_;
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
@@ -0,0 +1,556 @@
//
// impl/serial_port_base.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.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)
//
#ifndef BOOST_ASIO_IMPL_SERIAL_PORT_BASE_IPP
#define BOOST_ASIO_IMPL_SERIAL_PORT_BASE_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_SERIAL_PORT)
#include <stdexcept>
#include <boost/asio/error.hpp>
#include <boost/asio/serial_port_base.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#if defined(GENERATING_DOCUMENTATION)
# define BOOST_ASIO_OPTION_STORAGE implementation_defined
#elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
# define BOOST_ASIO_OPTION_STORAGE DCB
#else
# define BOOST_ASIO_OPTION_STORAGE termios
#endif
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
boost::system::error_code serial_port_base::baud_rate::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
storage.BaudRate = value_;
#else
speed_t baud;
switch (value_)
{
// Do POSIX-specified rates first.
case 0: baud = B0; break;
case 50: baud = B50; break;
case 75: baud = B75; break;
case 110: baud = B110; break;
case 134: baud = B134; break;
case 150: baud = B150; break;
case 200: baud = B200; break;
case 300: baud = B300; break;
case 600: baud = B600; break;
case 1200: baud = B1200; break;
case 1800: baud = B1800; break;
case 2400: baud = B2400; break;
case 4800: baud = B4800; break;
case 9600: baud = B9600; break;
case 19200: baud = B19200; break;
case 38400: baud = B38400; break;
// And now the extended ones conditionally.
# ifdef B7200
case 7200: baud = B7200; break;
# endif
# ifdef B14400
case 14400: baud = B14400; break;
# endif
# ifdef B57600
case 57600: baud = B57600; break;
# endif
# ifdef B115200
case 115200: baud = B115200; break;
# endif
# ifdef B230400
case 230400: baud = B230400; break;
# endif
# ifdef B460800
case 460800: baud = B460800; break;
# endif
# ifdef B500000
case 500000: baud = B500000; break;
# endif
# ifdef B576000
case 576000: baud = B576000; break;
# endif
# ifdef B921600
case 921600: baud = B921600; break;
# endif
# ifdef B1000000
case 1000000: baud = B1000000; break;
# endif
# ifdef B1152000
case 1152000: baud = B1152000; break;
# endif
# ifdef B2000000
case 2000000: baud = B2000000; break;
# endif
# ifdef B3000000
case 3000000: baud = B3000000; break;
# endif
# ifdef B3500000
case 3500000: baud = B3500000; break;
# endif
# ifdef B4000000
case 4000000: baud = B4000000; break;
# endif
default:
ec = boost::asio::error::invalid_argument;
return ec;
}
# if defined(_BSD_SOURCE)
::cfsetspeed(&storage, baud);
# else
::cfsetispeed(&storage, baud);
::cfsetospeed(&storage, baud);
# endif
#endif
ec = boost::system::error_code();
return ec;
}
boost::system::error_code serial_port_base::baud_rate::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
value_ = storage.BaudRate;
#else
speed_t baud = ::cfgetospeed(&storage);
switch (baud)
{
// First do those specified by POSIX.
case B0: value_ = 0; break;
case B50: value_ = 50; break;
case B75: value_ = 75; break;
case B110: value_ = 110; break;
case B134: value_ = 134; break;
case B150: value_ = 150; break;
case B200: value_ = 200; break;
case B300: value_ = 300; break;
case B600: value_ = 600; break;
case B1200: value_ = 1200; break;
case B1800: value_ = 1800; break;
case B2400: value_ = 2400; break;
case B4800: value_ = 4800; break;
case B9600: value_ = 9600; break;
case B19200: value_ = 19200; break;
case B38400: value_ = 38400; break;
// Now conditionally handle a bunch of extended rates.
# ifdef B7200
case B7200: value_ = 7200; break;
# endif
# ifdef B14400
case B14400: value_ = 14400; break;
# endif
# ifdef B57600
case B57600: value_ = 57600; break;
# endif
# ifdef B115200
case B115200: value_ = 115200; break;
# endif
# ifdef B230400
case B230400: value_ = 230400; break;
# endif
# ifdef B460800
case B460800: value_ = 460800; break;
# endif
# ifdef B500000
case B500000: value_ = 500000; break;
# endif
# ifdef B576000
case B576000: value_ = 576000; break;
# endif
# ifdef B921600
case B921600: value_ = 921600; break;
# endif
# ifdef B1000000
case B1000000: value_ = 1000000; break;
# endif
# ifdef B1152000
case B1152000: value_ = 1152000; break;
# endif
# ifdef B2000000
case B2000000: value_ = 2000000; break;
# endif
# ifdef B3000000
case B3000000: value_ = 3000000; break;
# endif
# ifdef B3500000
case B3500000: value_ = 3500000; break;
# endif
# ifdef B4000000
case B4000000: value_ = 4000000; break;
# endif
default:
value_ = 0;
ec = boost::asio::error::invalid_argument;
return ec;
}
#endif
ec = boost::system::error_code();
return ec;
}
serial_port_base::flow_control::flow_control(
serial_port_base::flow_control::type t)
: value_(t)
{
if (t != none && t != software && t != hardware)
{
std::out_of_range ex("invalid flow_control value");
boost::asio::detail::throw_exception(ex);
}
}
boost::system::error_code serial_port_base::flow_control::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
storage.fOutxCtsFlow = FALSE;
storage.fOutxDsrFlow = FALSE;
storage.fTXContinueOnXoff = TRUE;
storage.fDtrControl = DTR_CONTROL_ENABLE;
storage.fDsrSensitivity = FALSE;
storage.fOutX = FALSE;
storage.fInX = FALSE;
storage.fRtsControl = RTS_CONTROL_ENABLE;
switch (value_)
{
case none:
break;
case software:
storage.fOutX = TRUE;
storage.fInX = TRUE;
break;
case hardware:
storage.fOutxCtsFlow = TRUE;
storage.fRtsControl = RTS_CONTROL_HANDSHAKE;
break;
default:
break;
}
#else
switch (value_)
{
case none:
storage.c_iflag &= ~(IXOFF | IXON);
# if defined(_BSD_SOURCE)
storage.c_cflag &= ~CRTSCTS;
# elif defined(__QNXNTO__)
storage.c_cflag &= ~(IHFLOW | OHFLOW);
# endif
break;
case software:
storage.c_iflag |= IXOFF | IXON;
# if defined(_BSD_SOURCE)
storage.c_cflag &= ~CRTSCTS;
# elif defined(__QNXNTO__)
storage.c_cflag &= ~(IHFLOW | OHFLOW);
# endif
break;
case hardware:
# if defined(_BSD_SOURCE)
storage.c_iflag &= ~(IXOFF | IXON);
storage.c_cflag |= CRTSCTS;
break;
# elif defined(__QNXNTO__)
storage.c_iflag &= ~(IXOFF | IXON);
storage.c_cflag |= (IHFLOW | OHFLOW);
break;
# else
ec = boost::asio::error::operation_not_supported;
return ec;
# endif
default:
break;
}
#endif
ec = boost::system::error_code();
return ec;
}
boost::system::error_code serial_port_base::flow_control::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
if (storage.fOutX && storage.fInX)
{
value_ = software;
}
else if (storage.fOutxCtsFlow && storage.fRtsControl == RTS_CONTROL_HANDSHAKE)
{
value_ = hardware;
}
else
{
value_ = none;
}
#else
if (storage.c_iflag & (IXOFF | IXON))
{
value_ = software;
}
# if defined(_BSD_SOURCE)
else if (storage.c_cflag & CRTSCTS)
{
value_ = hardware;
}
# elif defined(__QNXNTO__)
else if (storage.c_cflag & IHFLOW && storage.c_cflag & OHFLOW)
{
value_ = hardware;
}
# endif
else
{
value_ = none;
}
#endif
ec = boost::system::error_code();
return ec;
}
serial_port_base::parity::parity(serial_port_base::parity::type t)
: value_(t)
{
if (t != none && t != odd && t != even)
{
std::out_of_range ex("invalid parity value");
boost::asio::detail::throw_exception(ex);
}
}
boost::system::error_code serial_port_base::parity::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
switch (value_)
{
case none:
storage.fParity = FALSE;
storage.Parity = NOPARITY;
break;
case odd:
storage.fParity = TRUE;
storage.Parity = ODDPARITY;
break;
case even:
storage.fParity = TRUE;
storage.Parity = EVENPARITY;
break;
default:
break;
}
#else
switch (value_)
{
case none:
storage.c_iflag |= IGNPAR;
storage.c_cflag &= ~(PARENB | PARODD);
break;
case even:
storage.c_iflag &= ~(IGNPAR | PARMRK);
storage.c_iflag |= INPCK;
storage.c_cflag |= PARENB;
storage.c_cflag &= ~PARODD;
break;
case odd:
storage.c_iflag &= ~(IGNPAR | PARMRK);
storage.c_iflag |= INPCK;
storage.c_cflag |= (PARENB | PARODD);
break;
default:
break;
}
#endif
ec = boost::system::error_code();
return ec;
}
boost::system::error_code serial_port_base::parity::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
if (storage.Parity == EVENPARITY)
{
value_ = even;
}
else if (storage.Parity == ODDPARITY)
{
value_ = odd;
}
else
{
value_ = none;
}
#else
if (storage.c_cflag & PARENB)
{
if (storage.c_cflag & PARODD)
{
value_ = odd;
}
else
{
value_ = even;
}
}
else
{
value_ = none;
}
#endif
ec = boost::system::error_code();
return ec;
}
serial_port_base::stop_bits::stop_bits(
serial_port_base::stop_bits::type t)
: value_(t)
{
if (t != one && t != onepointfive && t != two)
{
std::out_of_range ex("invalid stop_bits value");
boost::asio::detail::throw_exception(ex);
}
}
boost::system::error_code serial_port_base::stop_bits::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
switch (value_)
{
case one:
storage.StopBits = ONESTOPBIT;
break;
case onepointfive:
storage.StopBits = ONE5STOPBITS;
break;
case two:
storage.StopBits = TWOSTOPBITS;
break;
default:
break;
}
#else
switch (value_)
{
case one:
storage.c_cflag &= ~CSTOPB;
break;
case two:
storage.c_cflag |= CSTOPB;
break;
default:
ec = boost::asio::error::operation_not_supported;
return ec;
}
#endif
ec = boost::system::error_code();
return ec;
}
boost::system::error_code serial_port_base::stop_bits::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
if (storage.StopBits == ONESTOPBIT)
{
value_ = one;
}
else if (storage.StopBits == ONE5STOPBITS)
{
value_ = onepointfive;
}
else if (storage.StopBits == TWOSTOPBITS)
{
value_ = two;
}
else
{
value_ = one;
}
#else
value_ = (storage.c_cflag & CSTOPB) ? two : one;
#endif
ec = boost::system::error_code();
return ec;
}
serial_port_base::character_size::character_size(unsigned int t)
: value_(t)
{
if (t < 5 || t > 8)
{
std::out_of_range ex("invalid character_size value");
boost::asio::detail::throw_exception(ex);
}
}
boost::system::error_code serial_port_base::character_size::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
storage.ByteSize = value_;
#else
storage.c_cflag &= ~CSIZE;
switch (value_)
{
case 5: storage.c_cflag |= CS5; break;
case 6: storage.c_cflag |= CS6; break;
case 7: storage.c_cflag |= CS7; break;
case 8: storage.c_cflag |= CS8; break;
default: break;
}
#endif
ec = boost::system::error_code();
return ec;
}
boost::system::error_code serial_port_base::character_size::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
value_ = storage.ByteSize;
#else
if ((storage.c_cflag & CSIZE) == CS5) { value_ = 5; }
else if ((storage.c_cflag & CSIZE) == CS6) { value_ = 6; }
else if ((storage.c_cflag & CSIZE) == CS7) { value_ = 7; }
else if ((storage.c_cflag & CSIZE) == CS8) { value_ = 8; }
else
{
// Hmmm, use 8 for now.
value_ = 8;
}
#endif
ec = boost::system::error_code();
return ec;
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#undef BOOST_ASIO_OPTION_STORAGE
#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
#endif // BOOST_ASIO_IMPL_SERIAL_PORT_BASE_IPP
@@ -0,0 +1,355 @@
//
// impl/spawn.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_SPAWN_HPP
#define BOOST_ASIO_IMPL_SPAWN_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/atomic_count.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/detail/shared_ptr.hpp>
#include <boost/asio/handler_type.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
template <typename Handler, typename T>
class coro_handler
{
public:
coro_handler(basic_yield_context<Handler> ctx)
: coro_(ctx.coro_.lock()),
ca_(ctx.ca_),
handler_(ctx.handler_),
ready_(0),
ec_(ctx.ec_),
value_(0)
{
}
void operator()(T value)
{
*ec_ = boost::system::error_code();
*value_ = BOOST_ASIO_MOVE_CAST(T)(value);
if (--*ready_ == 0)
(*coro_)();
}
void operator()(boost::system::error_code ec, T value)
{
*ec_ = ec;
*value_ = BOOST_ASIO_MOVE_CAST(T)(value);
if (--*ready_ == 0)
(*coro_)();
}
//private:
shared_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
typename basic_yield_context<Handler>::caller_type& ca_;
Handler& handler_;
atomic_count* ready_;
boost::system::error_code* ec_;
T* value_;
};
template <typename Handler>
class coro_handler<Handler, void>
{
public:
coro_handler(basic_yield_context<Handler> ctx)
: coro_(ctx.coro_.lock()),
ca_(ctx.ca_),
handler_(ctx.handler_),
ready_(0),
ec_(ctx.ec_)
{
}
void operator()()
{
*ec_ = boost::system::error_code();
if (--*ready_ == 0)
(*coro_)();
}
void operator()(boost::system::error_code ec)
{
*ec_ = ec;
if (--*ready_ == 0)
(*coro_)();
}
//private:
shared_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
typename basic_yield_context<Handler>::caller_type& ca_;
Handler& handler_;
atomic_count* ready_;
boost::system::error_code* ec_;
};
template <typename Handler, typename T>
inline void* asio_handler_allocate(std::size_t size,
coro_handler<Handler, T>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename Handler, typename T>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
coro_handler<Handler, T>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename Handler, typename T>
inline bool asio_handler_is_continuation(coro_handler<Handler, T>*)
{
return true;
}
template <typename Function, typename Handler, typename T>
inline void asio_handler_invoke(Function& function,
coro_handler<Handler, T>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename Handler, typename T>
inline void asio_handler_invoke(const Function& function,
coro_handler<Handler, T>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename Handler, typename ReturnType>
struct handler_type<basic_yield_context<Handler>, ReturnType()>
{
typedef detail::coro_handler<Handler, void> type;
};
template <typename Handler, typename ReturnType, typename Arg1>
struct handler_type<basic_yield_context<Handler>, ReturnType(Arg1)>
{
typedef detail::coro_handler<Handler, Arg1> type;
};
template <typename Handler, typename ReturnType>
struct handler_type<basic_yield_context<Handler>,
ReturnType(boost::system::error_code)>
{
typedef detail::coro_handler<Handler, void> type;
};
template <typename Handler, typename ReturnType, typename Arg2>
struct handler_type<basic_yield_context<Handler>,
ReturnType(boost::system::error_code, Arg2)>
{
typedef detail::coro_handler<Handler, Arg2> type;
};
template <typename Handler, typename T>
class async_result<detail::coro_handler<Handler, T> >
{
public:
typedef T type;
explicit async_result(detail::coro_handler<Handler, T>& h)
: handler_(h),
ca_(h.ca_),
ready_(2)
{
h.ready_ = &ready_;
out_ec_ = h.ec_;
if (!out_ec_) h.ec_ = &ec_;
h.value_ = &value_;
}
type get()
{
handler_.coro_.reset(); // Must not hold shared_ptr to coro while suspended.
if (--ready_ != 0)
ca_();
if (!out_ec_ && ec_) throw boost::system::system_error(ec_);
return BOOST_ASIO_MOVE_CAST(type)(value_);
}
private:
detail::coro_handler<Handler, T>& handler_;
typename basic_yield_context<Handler>::caller_type& ca_;
detail::atomic_count ready_;
boost::system::error_code* out_ec_;
boost::system::error_code ec_;
type value_;
};
template <typename Handler>
class async_result<detail::coro_handler<Handler, void> >
{
public:
typedef void type;
explicit async_result(detail::coro_handler<Handler, void>& h)
: handler_(h),
ca_(h.ca_),
ready_(2)
{
h.ready_ = &ready_;
out_ec_ = h.ec_;
if (!out_ec_) h.ec_ = &ec_;
}
void get()
{
handler_.coro_.reset(); // Must not hold shared_ptr to coro while suspended.
if (--ready_ != 0)
ca_();
if (!out_ec_ && ec_) throw boost::system::system_error(ec_);
}
private:
detail::coro_handler<Handler, void>& handler_;
typename basic_yield_context<Handler>::caller_type& ca_;
detail::atomic_count ready_;
boost::system::error_code* out_ec_;
boost::system::error_code ec_;
};
namespace detail {
template <typename Handler, typename Function>
struct spawn_data : private noncopyable
{
spawn_data(BOOST_ASIO_MOVE_ARG(Handler) handler,
bool call_handler, BOOST_ASIO_MOVE_ARG(Function) function)
: handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler)),
call_handler_(call_handler),
function_(BOOST_ASIO_MOVE_CAST(Function)(function))
{
}
weak_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
Handler handler_;
bool call_handler_;
Function function_;
};
template <typename Handler, typename Function>
struct coro_entry_point
{
void operator()(typename basic_yield_context<Handler>::caller_type& ca)
{
shared_ptr<spawn_data<Handler, Function> > data(data_);
#if !defined(BOOST_COROUTINES_UNIDIRECT) && !defined(BOOST_COROUTINES_V2)
ca(); // Yield until coroutine pointer has been initialised.
#endif // !defined(BOOST_COROUTINES_UNIDIRECT) && !defined(BOOST_COROUTINES_V2)
const basic_yield_context<Handler> yield(
data->coro_, ca, data->handler_);
(data->function_)(yield);
if (data->call_handler_)
(data->handler_)();
}
shared_ptr<spawn_data<Handler, Function> > data_;
};
template <typename Handler, typename Function>
struct spawn_helper
{
void operator()()
{
typedef typename basic_yield_context<Handler>::callee_type callee_type;
coro_entry_point<Handler, Function> entry_point = { data_ };
shared_ptr<callee_type> coro(new callee_type(entry_point, attributes_));
data_->coro_ = coro;
(*coro)();
}
shared_ptr<spawn_data<Handler, Function> > data_;
boost::coroutines::attributes attributes_;
};
inline void default_spawn_handler() {}
} // namespace detail
template <typename Handler, typename Function>
void spawn(BOOST_ASIO_MOVE_ARG(Handler) handler,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes)
{
detail::spawn_helper<Handler, Function> helper;
helper.data_.reset(
new detail::spawn_data<Handler, Function>(
BOOST_ASIO_MOVE_CAST(Handler)(handler), true,
BOOST_ASIO_MOVE_CAST(Function)(function)));
helper.attributes_ = attributes;
boost_asio_handler_invoke_helpers::invoke(helper, helper.data_->handler_);
}
template <typename Handler, typename Function>
void spawn(basic_yield_context<Handler> ctx,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes)
{
Handler handler(ctx.handler_); // Explicit copy that might be moved from.
detail::spawn_helper<Handler, Function> helper;
helper.data_.reset(
new detail::spawn_data<Handler, Function>(
BOOST_ASIO_MOVE_CAST(Handler)(handler), false,
BOOST_ASIO_MOVE_CAST(Function)(function)));
helper.attributes_ = attributes;
boost_asio_handler_invoke_helpers::invoke(helper, helper.data_->handler_);
}
template <typename Function>
void spawn(boost::asio::io_service::strand strand,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes)
{
boost::asio::spawn(strand.wrap(&detail::default_spawn_handler),
BOOST_ASIO_MOVE_CAST(Function)(function), attributes);
}
template <typename Function>
void spawn(boost::asio::io_service& io_service,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes)
{
boost::asio::spawn(boost::asio::io_service::strand(io_service),
BOOST_ASIO_MOVE_CAST(Function)(function), attributes);
}
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SPAWN_HPP
@@ -0,0 +1,73 @@
//
// impl/src.hpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_SRC_HPP
#define BOOST_ASIO_IMPL_SRC_HPP
#define BOOST_ASIO_SOURCE
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# error Do not compile Asio library source with BOOST_ASIO_HEADER_ONLY defined
#endif
#include <boost/asio/impl/error.ipp>
#include <boost/asio/impl/handler_alloc_hook.ipp>
#include <boost/asio/impl/io_service.ipp>
#include <boost/asio/impl/serial_port_base.ipp>
#include <boost/asio/detail/impl/buffer_sequence_adapter.ipp>
#include <boost/asio/detail/impl/descriptor_ops.ipp>
#include <boost/asio/detail/impl/dev_poll_reactor.ipp>
#include <boost/asio/detail/impl/epoll_reactor.ipp>
#include <boost/asio/detail/impl/eventfd_select_interrupter.ipp>
#include <boost/asio/detail/impl/handler_tracking.ipp>
#include <boost/asio/detail/impl/kqueue_reactor.ipp>
#include <boost/asio/detail/impl/pipe_select_interrupter.ipp>
#include <boost/asio/detail/impl/posix_event.ipp>
#include <boost/asio/detail/impl/posix_mutex.ipp>
#include <boost/asio/detail/impl/posix_thread.ipp>
#include <boost/asio/detail/impl/posix_tss_ptr.ipp>
#include <boost/asio/detail/impl/reactive_descriptor_service.ipp>
#include <boost/asio/detail/impl/reactive_serial_port_service.ipp>
#include <boost/asio/detail/impl/reactive_socket_service_base.ipp>
#include <boost/asio/detail/impl/resolver_service_base.ipp>
#include <boost/asio/detail/impl/select_reactor.ipp>
#include <boost/asio/detail/impl/service_registry.ipp>
#include <boost/asio/detail/impl/signal_set_service.ipp>
#include <boost/asio/detail/impl/socket_ops.ipp>
#include <boost/asio/detail/impl/socket_select_interrupter.ipp>
#include <boost/asio/detail/impl/strand_service.ipp>
#include <boost/asio/detail/impl/task_io_service.ipp>
#include <boost/asio/detail/impl/throw_error.ipp>
#include <boost/asio/detail/impl/timer_queue_ptime.ipp>
#include <boost/asio/detail/impl/timer_queue_set.ipp>
#include <boost/asio/detail/impl/win_iocp_handle_service.ipp>
#include <boost/asio/detail/impl/win_iocp_io_service.ipp>
#include <boost/asio/detail/impl/win_iocp_serial_port_service.ipp>
#include <boost/asio/detail/impl/win_iocp_socket_service_base.ipp>
#include <boost/asio/detail/impl/win_event.ipp>
#include <boost/asio/detail/impl/win_mutex.ipp>
#include <boost/asio/detail/impl/win_object_handle_service.ipp>
#include <boost/asio/detail/impl/win_static_mutex.ipp>
#include <boost/asio/detail/impl/win_thread.ipp>
#include <boost/asio/detail/impl/win_tss_ptr.ipp>
#include <boost/asio/detail/impl/winrt_ssocket_service_base.ipp>
#include <boost/asio/detail/impl/winrt_timer_scheduler.ipp>
#include <boost/asio/detail/impl/winsock_init.ipp>
#include <boost/asio/generic/detail/impl/endpoint.ipp>
#include <boost/asio/ip/impl/address.ipp>
#include <boost/asio/ip/impl/address_v4.ipp>
#include <boost/asio/ip/impl/address_v6.ipp>
#include <boost/asio/ip/impl/host_name.ipp>
#include <boost/asio/ip/detail/impl/endpoint.ipp>
#include <boost/asio/local/detail/impl/endpoint.ipp>
#endif // BOOST_ASIO_IMPL_SRC_HPP
@@ -0,0 +1,179 @@
//
// impl/use_future.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_USE_FUTURE_HPP
#define BOOST_ASIO_IMPL_USE_FUTURE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <future>
#include <boost/asio/async_result.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/handler_type.hpp>
#include <boost/system/system_error.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Completion handler to adapt a promise as a completion handler.
template <typename T>
class promise_handler
{
public:
// Construct from use_future special value.
template <typename Alloc>
promise_handler(use_future_t<Alloc> uf)
: promise_(std::allocate_shared<std::promise<T> >(
BOOST_ASIO_REBIND_ALLOC(Alloc, char)(uf.get_allocator()),
std::allocator_arg,
BOOST_ASIO_REBIND_ALLOC(Alloc, char)(uf.get_allocator())))
{
}
void operator()(T t)
{
promise_->set_value(t);
}
void operator()(const boost::system::error_code& ec, T t)
{
if (ec)
promise_->set_exception(
std::make_exception_ptr(
boost::system::system_error(ec)));
else
promise_->set_value(t);
}
//private:
std::shared_ptr<std::promise<T> > promise_;
};
// Completion handler to adapt a void promise as a completion handler.
template <>
class promise_handler<void>
{
public:
// Construct from use_future special value. Used during rebinding.
template <typename Alloc>
promise_handler(use_future_t<Alloc> uf)
: promise_(std::allocate_shared<std::promise<void> >(
BOOST_ASIO_REBIND_ALLOC(Alloc, char)(uf.get_allocator()),
std::allocator_arg,
BOOST_ASIO_REBIND_ALLOC(Alloc, char)(uf.get_allocator())))
{
}
void operator()()
{
promise_->set_value();
}
void operator()(const boost::system::error_code& ec)
{
if (ec)
promise_->set_exception(
std::make_exception_ptr(
boost::system::system_error(ec)));
else
promise_->set_value();
}
//private:
std::shared_ptr<std::promise<void> > promise_;
};
// Ensure any exceptions thrown from the handler are propagated back to the
// caller via the future.
template <typename Function, typename T>
void asio_handler_invoke(Function f, promise_handler<T>* h)
{
std::shared_ptr<std::promise<T> > p(h->promise_);
try
{
f();
}
catch (...)
{
p->set_exception(std::current_exception());
}
}
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
// Handler traits specialisation for promise_handler.
template <typename T>
class async_result<detail::promise_handler<T> >
{
public:
// The initiating function will return a future.
typedef std::future<T> type;
// Constructor creates a new promise for the async operation, and obtains the
// corresponding future.
explicit async_result(detail::promise_handler<T>& h)
{
value_ = h.promise_->get_future();
}
// Obtain the future to be returned from the initiating function.
type get() { return std::move(value_); }
private:
type value_;
};
// Handler type specialisation for use_future.
template <typename Allocator, typename ReturnType>
struct handler_type<use_future_t<Allocator>, ReturnType()>
{
typedef detail::promise_handler<void> type;
};
// Handler type specialisation for use_future.
template <typename Allocator, typename ReturnType, typename Arg1>
struct handler_type<use_future_t<Allocator>, ReturnType(Arg1)>
{
typedef detail::promise_handler<Arg1> type;
};
// Handler type specialisation for use_future.
template <typename Allocator, typename ReturnType>
struct handler_type<use_future_t<Allocator>,
ReturnType(boost::system::error_code)>
{
typedef detail::promise_handler<void> type;
};
// Handler type specialisation for use_future.
template <typename Allocator, typename ReturnType, typename Arg2>
struct handler_type<use_future_t<Allocator>,
ReturnType(boost::system::error_code, Arg2)>
{
typedef detail::promise_handler<Arg2> type;
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_USE_FUTURE_HPP
@@ -0,0 +1,767 @@
//
// impl/write.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_WRITE_HPP
#define BOOST_ASIO_IMPL_WRITE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
#include <boost/asio/detail/array_fwd.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/dependent_type.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename SyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition>
std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<
const_buffer, ConstBufferSequence> tmp(buffers);
std::size_t total_transferred = 0;
tmp.prepare(detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred)));
while (tmp.begin() != tmp.end())
{
std::size_t bytes_transferred = s.write_some(tmp, ec);
tmp.consume(bytes_transferred);
total_transferred += bytes_transferred;
tmp.prepare(detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred)));
}
return total_transferred;
}
template <typename SyncWriteStream, typename ConstBufferSequence>
inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s, buffers, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
template <typename SyncWriteStream, typename ConstBufferSequence>
inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
boost::system::error_code& ec)
{
return write(s, buffers, transfer_all(), ec);
}
template <typename SyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition>
inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s, buffers, completion_condition, ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncWriteStream, typename Allocator,
typename CompletionCondition>
std::size_t write(SyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
std::size_t bytes_transferred = write(s, b.data(), completion_condition, ec);
b.consume(bytes_transferred);
return bytes_transferred;
}
template <typename SyncWriteStream, typename Allocator>
inline std::size_t write(SyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s, b, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
template <typename SyncWriteStream, typename Allocator>
inline std::size_t write(SyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
boost::system::error_code& ec)
{
return write(s, b, transfer_all(), ec);
}
template <typename SyncWriteStream, typename Allocator,
typename CompletionCondition>
inline std::size_t write(SyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s, b, completion_condition, ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
class write_op
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_op(AsyncWriteStream& stream, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_op(const write_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_op(write_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
switch (start_ = start)
{
case 1:
buffers_.prepare(this->check_for_completion(ec, total_transferred_));
for (;;)
{
stream_.async_write_some(buffers_,
BOOST_ASIO_MOVE_CAST(write_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
buffers_.prepare(this->check_for_completion(ec, total_transferred_));
if ((!ec && bytes_transferred == 0)
|| buffers_.begin() == buffers_.end())
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncWriteStream& stream_;
boost::asio::detail::consuming_buffers<
const_buffer, ConstBufferSequence> buffers_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
template <typename AsyncWriteStream,
typename CompletionCondition, typename WriteHandler>
class write_op<AsyncWriteStream, boost::asio::mutable_buffers_1,
CompletionCondition, WriteHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_op(AsyncWriteStream& stream,
const boost::asio::mutable_buffers_1& buffers,
CompletionCondition completion_condition,
WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffer_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_op(const write_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_op(write_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
stream_.async_write_some(
boost::asio::buffer(buffer_ + total_transferred_, n),
BOOST_ASIO_MOVE_CAST(write_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncWriteStream& stream_;
boost::asio::mutable_buffer buffer_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
template <typename AsyncWriteStream,
typename CompletionCondition, typename WriteHandler>
class write_op<AsyncWriteStream, boost::asio::const_buffers_1,
CompletionCondition, WriteHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_op(AsyncWriteStream& stream,
const boost::asio::const_buffers_1& buffers,
CompletionCondition completion_condition,
WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffer_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_op(const write_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_op(write_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
stream_.async_write_some(
boost::asio::buffer(buffer_ + total_transferred_, n),
BOOST_ASIO_MOVE_CAST(write_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncWriteStream& stream_;
boost::asio::const_buffer buffer_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
template <typename AsyncWriteStream, typename Elem,
typename CompletionCondition, typename WriteHandler>
class write_op<AsyncWriteStream, boost::array<Elem, 2>,
CompletionCondition, WriteHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_op(AsyncWriteStream& stream, const boost::array<Elem, 2>& buffers,
CompletionCondition completion_condition, WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_op(const write_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_op(write_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
boost::array<boost::asio::const_buffer, 2> >::type bufs = {{
boost::asio::const_buffer(buffers_[0]),
boost::asio::const_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
stream_.async_write_some(bufs, BOOST_ASIO_MOVE_CAST(write_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncWriteStream& stream_;
boost::array<Elem, 2> buffers_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
#if defined(BOOST_ASIO_HAS_STD_ARRAY)
template <typename AsyncWriteStream, typename Elem,
typename CompletionCondition, typename WriteHandler>
class write_op<AsyncWriteStream, std::array<Elem, 2>,
CompletionCondition, WriteHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_op(AsyncWriteStream& stream, const std::array<Elem, 2>& buffers,
CompletionCondition completion_condition, WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
stream_(stream),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_op(const write_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_op(write_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
std::array<boost::asio::const_buffer, 2> >::type bufs = {{
boost::asio::const_buffer(buffers_[0]),
boost::asio::const_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
stream_.async_write_some(bufs, BOOST_ASIO_MOVE_CAST(write_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncWriteStream& stream_;
std::array<Elem, 2> buffers_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
#endif // defined(BOOST_ASIO_HAS_STD_ARRAY)
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
write_op<AsyncWriteStream, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
write_op<AsyncWriteStream, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline bool asio_handler_is_continuation(
write_op<AsyncWriteStream, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename AsyncWriteStream,
typename ConstBufferSequence, typename CompletionCondition,
typename WriteHandler>
inline void asio_handler_invoke(Function& function,
write_op<AsyncWriteStream, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename AsyncWriteStream,
typename ConstBufferSequence, typename CompletionCondition,
typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
write_op<AsyncWriteStream, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
detail::write_op<AsyncWriteStream, ConstBufferSequence,
CompletionCondition, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
s, buffers, completion_condition, init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename WriteHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
detail::write_op<AsyncWriteStream, ConstBufferSequence,
detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
s, buffers, transfer_all(), init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename Allocator, typename WriteHandler>
class write_streambuf_handler
{
public:
write_streambuf_handler(boost::asio::basic_streambuf<Allocator>& streambuf,
WriteHandler& handler)
: streambuf_(streambuf),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_streambuf_handler(const write_streambuf_handler& other)
: streambuf_(other.streambuf_),
handler_(other.handler_)
{
}
write_streambuf_handler(write_streambuf_handler&& other)
: streambuf_(other.streambuf_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_transferred)
{
streambuf_.consume(bytes_transferred);
handler_(ec, bytes_transferred);
}
//private:
boost::asio::basic_streambuf<Allocator>& streambuf_;
WriteHandler handler_;
};
template <typename Allocator, typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
write_streambuf_handler<Allocator, WriteHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename Allocator, typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
write_streambuf_handler<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename Allocator, typename WriteHandler>
inline bool asio_handler_is_continuation(
write_streambuf_handler<Allocator, WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename Allocator, typename WriteHandler>
inline void asio_handler_invoke(Function& function,
write_streambuf_handler<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename Allocator, typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
write_streambuf_handler<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
} // namespace detail
template <typename AsyncWriteStream, typename Allocator,
typename CompletionCondition, typename WriteHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write(AsyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
async_write(s, b.data(), completion_condition,
detail::write_streambuf_handler<Allocator, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
b, init.handler));
return init.result.get();
}
template <typename AsyncWriteStream, typename Allocator, typename WriteHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write(AsyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
async_write(s, b.data(), transfer_all(),
detail::write_streambuf_handler<Allocator, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
b, init.handler));
return init.result.get();
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_WRITE_HPP
@@ -0,0 +1,827 @@
//
// impl/write_at.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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)
//
#ifndef BOOST_ASIO_IMPL_WRITE_AT_HPP
#define BOOST_ASIO_IMPL_WRITE_AT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
#include <boost/asio/detail/array_fwd.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/dependent_type.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition>
std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<
const_buffer, ConstBufferSequence> tmp(buffers);
std::size_t total_transferred = 0;
tmp.prepare(detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred)));
while (tmp.begin() != tmp.end())
{
std::size_t bytes_transferred = d.write_some_at(
offset + total_transferred, tmp, ec);
tmp.consume(bytes_transferred);
total_transferred += bytes_transferred;
tmp.prepare(detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred)));
}
return total_transferred;
}
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write_at(
d, offset, buffers, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write_at");
return bytes_transferred;
}
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
boost::system::error_code& ec)
{
return write_at(d, offset, buffers, transfer_all(), ec);
}
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write_at(
d, offset, buffers, completion_condition, ec);
boost::asio::detail::throw_error(ec, "write_at");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncRandomAccessWriteDevice, typename Allocator,
typename CompletionCondition>
std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
std::size_t bytes_transferred = write_at(
d, offset, b.data(), completion_condition, ec);
b.consume(bytes_transferred);
return bytes_transferred;
}
template <typename SyncRandomAccessWriteDevice, typename Allocator>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write_at(d, offset, b, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write_at");
return bytes_transferred;
}
template <typename SyncRandomAccessWriteDevice, typename Allocator>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
boost::system::error_code& ec)
{
return write_at(d, offset, b, transfer_all(), ec);
}
template <typename SyncRandomAccessWriteDevice, typename Allocator,
typename CompletionCondition>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write_at(
d, offset, b, completion_condition, ec);
boost::asio::detail::throw_error(ec, "write_at");
return bytes_transferred;
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
class write_at_op
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_at_op(AsyncRandomAccessWriteDevice& device,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_at_op(const write_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
switch (start_ = start)
{
case 1:
buffers_.prepare(this->check_for_completion(ec, total_transferred_));
for (;;)
{
device_.async_write_some_at(
offset_ + total_transferred_, buffers_,
BOOST_ASIO_MOVE_CAST(write_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
buffers_.prepare(this->check_for_completion(ec, total_transferred_));
if ((!ec && bytes_transferred == 0)
|| buffers_.begin() == buffers_.end())
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessWriteDevice& device_;
uint64_t offset_;
boost::asio::detail::consuming_buffers<
const_buffer, ConstBufferSequence> buffers_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
template <typename AsyncRandomAccessWriteDevice,
typename CompletionCondition, typename WriteHandler>
class write_at_op<AsyncRandomAccessWriteDevice,
boost::asio::mutable_buffers_1, CompletionCondition, WriteHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_at_op(AsyncRandomAccessWriteDevice& device,
uint64_t offset, const boost::asio::mutable_buffers_1& buffers,
CompletionCondition completion_condition,
WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffer_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_at_op(const write_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
device_.async_write_some_at(offset_ + total_transferred_,
boost::asio::buffer(buffer_ + total_transferred_, n),
BOOST_ASIO_MOVE_CAST(write_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessWriteDevice& device_;
uint64_t offset_;
boost::asio::mutable_buffer buffer_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
template <typename AsyncRandomAccessWriteDevice,
typename CompletionCondition, typename WriteHandler>
class write_at_op<AsyncRandomAccessWriteDevice, boost::asio::const_buffers_1,
CompletionCondition, WriteHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_at_op(AsyncRandomAccessWriteDevice& device,
uint64_t offset, const boost::asio::const_buffers_1& buffers,
CompletionCondition completion_condition,
WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffer_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_at_op(const write_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffer_(other.buffer_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
device_.async_write_some_at(offset_ + total_transferred_,
boost::asio::buffer(buffer_ + total_transferred_, n),
BOOST_ASIO_MOVE_CAST(write_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == boost::asio::buffer_size(buffer_))
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessWriteDevice& device_;
uint64_t offset_;
boost::asio::const_buffer buffer_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
template <typename AsyncRandomAccessWriteDevice, typename Elem,
typename CompletionCondition, typename WriteHandler>
class write_at_op<AsyncRandomAccessWriteDevice, boost::array<Elem, 2>,
CompletionCondition, WriteHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_at_op(AsyncRandomAccessWriteDevice& device,
uint64_t offset, const boost::array<Elem, 2>& buffers,
CompletionCondition completion_condition, WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_at_op(const write_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
boost::array<boost::asio::const_buffer, 2> >::type bufs = {{
boost::asio::const_buffer(buffers_[0]),
boost::asio::const_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
device_.async_write_some_at(offset_ + total_transferred_,
bufs, BOOST_ASIO_MOVE_CAST(write_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessWriteDevice& device_;
uint64_t offset_;
boost::array<Elem, 2> buffers_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
#if defined(BOOST_ASIO_HAS_STD_ARRAY)
template <typename AsyncRandomAccessWriteDevice, typename Elem,
typename CompletionCondition, typename WriteHandler>
class write_at_op<AsyncRandomAccessWriteDevice, std::array<Elem, 2>,
CompletionCondition, WriteHandler>
: detail::base_from_completion_cond<CompletionCondition>
{
public:
write_at_op(AsyncRandomAccessWriteDevice& device,
uint64_t offset, const std::array<Elem, 2>& buffers,
CompletionCondition completion_condition, WriteHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffers_(buffers),
start_(0),
total_transferred_(0),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_at_op(const write_at_op& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: detail::base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
typename boost::asio::detail::dependent_type<Elem,
std::array<boost::asio::const_buffer, 2> >::type bufs = {{
boost::asio::const_buffer(buffers_[0]),
boost::asio::const_buffer(buffers_[1]) }};
std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
std::size_t n = 0;
switch (start_ = start)
{
case 1:
n = this->check_for_completion(ec, total_transferred_);
for (;;)
{
bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
bufs[1] = boost::asio::buffer(
bufs[1] + (total_transferred_ < buffer_size0
? 0 : total_transferred_ - buffer_size0),
n - boost::asio::buffer_size(bufs[0]));
device_.async_write_some_at(offset_ + total_transferred_,
bufs, BOOST_ASIO_MOVE_CAST(write_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|| total_transferred_ == buffer_size0 + buffer_size1)
break;
}
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessWriteDevice& device_;
uint64_t offset_;
std::array<Elem, 2> buffers_;
int start_;
std::size_t total_transferred_;
WriteHandler handler_;
};
#endif // defined(BOOST_ASIO_HAS_STD_ARRAY)
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline bool asio_handler_is_continuation(
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename CompletionCondition,
typename WriteHandler>
inline void asio_handler_invoke(Function& function,
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename CompletionCondition,
typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline write_at_op<AsyncRandomAccessWriteDevice,
ConstBufferSequence, CompletionCondition, WriteHandler>
make_write_at_op(AsyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteHandler handler)
{
return write_at_op<AsyncRandomAccessWriteDevice,
ConstBufferSequence, CompletionCondition, WriteHandler>(
d, offset, buffers, completion_condition, handler);
}
} // namespace detail
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
CompletionCondition, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
d, offset, buffers, completion_condition, init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename WriteHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
d, offset, buffers, transfer_all(), init.handler)(
boost::system::error_code(), 0, 1);
return init.result.get();
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename Allocator, typename WriteHandler>
class write_at_streambuf_op
{
public:
write_at_streambuf_op(
boost::asio::basic_streambuf<Allocator>& streambuf,
WriteHandler& handler)
: streambuf_(streambuf),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
write_at_streambuf_op(const write_at_streambuf_op& other)
: streambuf_(other.streambuf_),
handler_(other.handler_)
{
}
write_at_streambuf_op(write_at_streambuf_op&& other)
: streambuf_(other.streambuf_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_transferred)
{
streambuf_.consume(bytes_transferred);
handler_(ec, bytes_transferred);
}
//private:
boost::asio::basic_streambuf<Allocator>& streambuf_;
WriteHandler handler_;
};
template <typename Allocator, typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename Allocator, typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename Allocator, typename WriteHandler>
inline bool asio_handler_is_continuation(
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename Allocator, typename WriteHandler>
inline void asio_handler_invoke(Function& function,
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename Allocator, typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Allocator, typename WriteHandler>
inline write_at_streambuf_op<Allocator, WriteHandler>
make_write_at_streambuf_op(
boost::asio::basic_streambuf<Allocator>& b, WriteHandler handler)
{
return write_at_streambuf_op<Allocator, WriteHandler>(b, handler);
}
} // namespace detail
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename CompletionCondition, typename WriteHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
async_write_at(d, offset, b.data(), completion_condition,
detail::write_at_streambuf_op<Allocator, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
b, init.handler));
return init.result.get();
}
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename WriteHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
async_write_at(d, offset, b.data(), transfer_all(),
detail::write_at_streambuf_op<Allocator, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
b, init.handler));
return init.result.get();
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_WRITE_AT_HPP