// read_until.cpp
// ~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// 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)
#include <cstring>
#include "archetypes/async_result.hpp"
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/io_context.hpp>
+#include <boost/asio/post.hpp>
#include <boost/asio/streambuf.hpp>
#include "unit_test.hpp"
class test_stream
{
public:
- typedef boost::asio::io_service io_service_type;
+ typedef boost::asio::io_context::executor_type executor_type;
- test_stream(boost::asio::io_service& io_service)
- : io_service_(io_service),
+ test_stream(boost::asio::io_context& io_context)
+ : io_context_(io_context),
length_(0),
position_(0),
next_read_length_(0)
{
}
- io_service_type& get_io_service()
+ executor_type get_executor() BOOST_ASIO_NOEXCEPT
{
- return io_service_;
+ return io_context_.get_executor();
}
void reset(const void* data, size_t length)
void async_read_some(const Mutable_Buffers& buffers, Handler handler)
{
size_t bytes_transferred = read_some(buffers);
- io_service_.post(boost::asio::detail::bind_handler(
- handler, boost::system::error_code(), bytes_transferred));
+ boost::asio::post(get_executor(),
+ boost::asio::detail::bind_handler(
+ BOOST_ASIO_MOVE_CAST(Handler)(handler),
+ boost::system::error_code(), bytes_transferred));
}
private:
- io_service_type& io_service_;
+ boost::asio::io_context& io_context_;
enum { max_length = 8192 };
char data_[max_length];
size_t length_;
void test_char_read_until()
{
- boost::asio::io_service ios;
- test_stream s(ios);
+ boost::asio::io_context ioc;
+ test_stream s(ioc);
boost::asio::streambuf sb1;
boost::asio::streambuf sb2(25);
boost::system::error_code ec;
void test_string_read_until()
{
- boost::asio::io_service ios;
- test_stream s(ios);
+ boost::asio::io_context ioc;
+ test_stream s(ioc);
boost::asio::streambuf sb1;
boost::asio::streambuf sb2(25);
boost::system::error_code ec;
void test_match_condition_read_until()
{
- boost::asio::io_service ios;
- test_stream s(ios);
+ boost::asio::io_context ioc;
+ test_stream s(ioc);
boost::asio::streambuf sb1;
boost::asio::streambuf sb2(25);
boost::system::error_code ec;
using std::placeholders::_2;
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
- boost::asio::io_service ios;
- test_stream s(ios);
+ boost::asio::io_context ioc;
+ test_stream s(ioc);
boost::asio::streambuf sb1;
boost::asio::streambuf sb2(25);
boost::system::error_code ec;
boost::asio::async_read_until(s, sb1, 'Z',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb1, 'Z',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb1, 'Z',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb2, 'Z',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, 'Z',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, 'Z',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, 'Y',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
boost::asio::async_read_until(s, sb2, 'Y',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
boost::asio::async_read_until(s, sb2, 'Y',
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
int i = boost::asio::async_read_until(s, sb2, 'Y',
archetypes::lazy_handler());
BOOST_ASIO_CHECK(i == 42);
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
}
void test_string_async_read_until()
using std::placeholders::_2;
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
- boost::asio::io_service ios;
- test_stream s(ios);
+ boost::asio::io_context ioc;
+ test_stream s(ioc);
boost::asio::streambuf sb1;
boost::asio::streambuf sb2(25);
boost::system::error_code ec;
boost::asio::async_read_until(s, sb1, "XYZ",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb1, "XYZ",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb1, "XYZ",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb2, "XYZ",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, "XYZ",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, "XYZ",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, "WXY",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
boost::asio::async_read_until(s, sb2, "WXY",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
boost::asio::async_read_until(s, sb2, "WXY",
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
int i = boost::asio::async_read_until(s, sb2, "WXY",
archetypes::lazy_handler());
BOOST_ASIO_CHECK(i == 42);
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
}
void test_match_condition_async_read_until()
using std::placeholders::_2;
#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
- boost::asio::io_service ios;
- test_stream s(ios);
+ boost::asio::io_context ioc;
+ test_stream s(ioc);
boost::asio::streambuf sb1;
boost::asio::streambuf sb2(25);
boost::system::error_code ec;
boost::asio::async_read_until(s, sb1, match_char('Z'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb1, match_char('Z'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb1, match_char('Z'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 26);
boost::asio::async_read_until(s, sb2, match_char('Z'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, match_char('Z'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, match_char('Z'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(ec == boost::asio::error::not_found);
BOOST_ASIO_CHECK(length == 0);
boost::asio::async_read_until(s, sb2, match_char('Y'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
boost::asio::async_read_until(s, sb2, match_char('Y'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
boost::asio::async_read_until(s, sb2, match_char('Y'),
bindns::bind(async_read_handler, _1, &ec,
_2, &length, &called));
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
BOOST_ASIO_CHECK(called);
BOOST_ASIO_CHECK(!ec);
BOOST_ASIO_CHECK(length == 25);
int i = boost::asio::async_read_until(s, sb2, match_char('Y'),
archetypes::lazy_handler());
BOOST_ASIO_CHECK(i == 42);
- ios.reset();
- ios.run();
+ ioc.restart();
+ ioc.run();
}
BOOST_ASIO_TEST_SUITE