]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/asio/test/read_until.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / asio / test / read_until.cpp
index 6f3fff10981827757a3f1b8de5666a5fbf571e7f..eb0e25c02833641b9b702207d4a04aab63d5b8e1 100644 (file)
@@ -2,7 +2,7 @@
 // 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)
@@ -18,7 +18,8 @@
 
 #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)
@@ -85,12 +86,14 @@ public:
   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_;
@@ -103,8 +106,8 @@ static const char read_data[]
 
 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;
@@ -189,8 +192,8 @@ void test_char_read_until()
 
 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;
@@ -304,8 +307,8 @@ namespace asio {
 
 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;
@@ -407,8 +410,8 @@ void test_char_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;
@@ -423,8 +426,8 @@ void test_char_async_read_until()
   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);
@@ -438,8 +441,8 @@ void test_char_async_read_until()
   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);
@@ -453,8 +456,8 @@ void test_char_async_read_until()
   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);
@@ -467,8 +470,8 @@ void test_char_async_read_until()
   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);
@@ -482,8 +485,8 @@ void test_char_async_read_until()
   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);
@@ -497,8 +500,8 @@ void test_char_async_read_until()
   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);
@@ -511,8 +514,8 @@ void test_char_async_read_until()
   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);
@@ -526,8 +529,8 @@ void test_char_async_read_until()
   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);
@@ -541,8 +544,8 @@ void test_char_async_read_until()
   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);
@@ -552,8 +555,8 @@ void test_char_async_read_until()
   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()
@@ -566,8 +569,8 @@ 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;
@@ -582,8 +585,8 @@ void test_string_async_read_until()
   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);
@@ -597,8 +600,8 @@ void test_string_async_read_until()
   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);
@@ -612,8 +615,8 @@ void test_string_async_read_until()
   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);
@@ -626,8 +629,8 @@ void test_string_async_read_until()
   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);
@@ -641,8 +644,8 @@ void test_string_async_read_until()
   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);
@@ -656,8 +659,8 @@ void test_string_async_read_until()
   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);
@@ -670,8 +673,8 @@ void test_string_async_read_until()
   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);
@@ -685,8 +688,8 @@ void test_string_async_read_until()
   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);
@@ -700,8 +703,8 @@ void test_string_async_read_until()
   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);
@@ -711,8 +714,8 @@ void test_string_async_read_until()
   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()
@@ -725,8 +728,8 @@ 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;
@@ -741,8 +744,8 @@ void test_match_condition_async_read_until()
   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);
@@ -756,8 +759,8 @@ void test_match_condition_async_read_until()
   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);
@@ -771,8 +774,8 @@ void test_match_condition_async_read_until()
   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);
@@ -785,8 +788,8 @@ void test_match_condition_async_read_until()
   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);
@@ -800,8 +803,8 @@ void test_match_condition_async_read_until()
   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);
@@ -815,8 +818,8 @@ void test_match_condition_async_read_until()
   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);
@@ -829,8 +832,8 @@ void test_match_condition_async_read_until()
   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);
@@ -844,8 +847,8 @@ void test_match_condition_async_read_until()
   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);
@@ -859,8 +862,8 @@ void test_match_condition_async_read_until()
   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);
@@ -870,8 +873,8 @@ void test_match_condition_async_read_until()
   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