repo_name
stringclasses
10 values
file_path
stringlengths
29
222
content
stringlengths
24
926k
extention
stringclasses
5 values
asio
data/projects/asio/example/cpp11/allocation/server.cpp
// // server.cpp // ~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <array> #include <cstdlib> #include <iostream> #include <memory> #include <type_traits> #include <utility> #include <boost/asio.hpp> using boost::asio::ip::tcp; // Class to manage the memory to be used for handler-based custom allocation. // It contains a single block of memory which may be returned for allocation // requests. If the memory is in use when an allocation request is made, the // allocator delegates allocation to the global heap. class handler_memory { public: handler_memory() : in_use_(false) { } handler_memory(const handler_memory&) = delete; handler_memory& operator=(const handler_memory&) = delete; void* allocate(std::size_t size) { if (!in_use_ && size < sizeof(storage_)) { in_use_ = true; return &storage_; } else { return ::operator new(size); } } void deallocate(void* pointer) { if (pointer == &storage_) { in_use_ = false; } else { ::operator delete(pointer); } } private: // Storage space used for handler-based custom memory allocation. typename std::aligned_storage<1024>::type storage_; // Whether the handler-based custom allocation storage has been used. bool in_use_; }; // The allocator to be associated with the handler objects. This allocator only // needs to satisfy the C++11 minimal allocator requirements. template <typename T> class handler_allocator { public: using value_type = T; explicit handler_allocator(handler_memory& mem) : memory_(mem) { } template <typename U> handler_allocator(const handler_allocator<U>& other) noexcept : memory_(other.memory_) { } bool operator==(const handler_allocator& other) const noexcept { return &memory_ == &other.memory_; } bool operator!=(const handler_allocator& other) const noexcept { return &memory_ != &other.memory_; } T* allocate(std::size_t n) const { return static_cast<T*>(memory_.allocate(sizeof(T) * n)); } void deallocate(T* p, std::size_t /*n*/) const { return memory_.deallocate(p); } private: template <typename> friend class handler_allocator; // The underlying memory. handler_memory& memory_; }; class session : public std::enable_shared_from_this<session> { public: session(tcp::socket socket) : socket_(std::move(socket)) { } void start() { do_read(); } private: void do_read() { auto self(shared_from_this()); socket_.async_read_some(boost::asio::buffer(data_), boost::asio::bind_allocator( handler_allocator<int>(handler_memory_), [this, self](boost::system::error_code ec, std::size_t length) { if (!ec) { do_write(length); } })); } void do_write(std::size_t length) { auto self(shared_from_this()); boost::asio::async_write(socket_, boost::asio::buffer(data_, length), boost::asio::bind_allocator( handler_allocator<int>(handler_memory_), [this, self](boost::system::error_code ec, std::size_t /*length*/) { if (!ec) { do_read(); } })); } // The socket used to communicate with the client. tcp::socket socket_; // Buffer used to store data received from the client. std::array<char, 1024> data_; // The memory to use for handler-based custom memory allocation. handler_memory handler_memory_; }; class server { public: server(boost::asio::io_context& io_context, short port) : acceptor_(io_context, tcp::endpoint(tcp::v4(), port)) { do_accept(); } private: void do_accept() { acceptor_.async_accept( [this](boost::system::error_code ec, tcp::socket socket) { if (!ec) { std::make_shared<session>(std::move(socket))->start(); } do_accept(); }); } tcp::acceptor acceptor_; }; int main(int argc, char* argv[]) { try { if (argc != 2) { std::cerr << "Usage: server <port>\n"; return 1; } boost::asio::io_context io_context; server s(io_context, std::atoi(argv[1])); io_context.run(); } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; } return 0; }
cpp
asio
data/projects/asio/example/cpp20/operations/c_callback_wrapper.cpp
// // c_callback_wrapper.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio.hpp> #include <iostream> #include <memory> #include <new> //------------------------------------------------------------------------------ // This is a mock implementation of a C-based API that uses the function pointer // plus void* context idiom for exposing a callback. void read_input(const char* prompt, void (*cb)(void*, const char*), void* arg) { std::thread( [prompt = std::string(prompt), cb, arg] { std::cout << prompt << ": "; std::cout.flush(); std::string line; std::getline(std::cin, line); cb(arg, line.c_str()); }).detach(); } //------------------------------------------------------------------------------ // This is an asynchronous operation that wraps the C-based API. // To map our completion handler into a function pointer / void* callback, we // need to allocate some state that will live for the duration of the // operation. A pointer to this state will be passed to the C-based API. template <boost::asio::completion_handler_for<void(std::string)> Handler> class read_input_state { public: read_input_state(Handler&& handler) : handler_(std::move(handler)), work_(boost::asio::make_work_guard(handler_)) { } // Create the state using the handler's associated allocator. static read_input_state* create(Handler&& handler) { // A unique_ptr deleter that is used to destroy uninitialised objects. struct deleter { // Get the handler's associated allocator type. If the handler does not // specify an associated allocator, we will use a recycling allocator as // the default. As the associated allocator is a proto-allocator, we must // rebind it to the correct type before we can use it to allocate objects. typename std::allocator_traits< boost::asio::associated_allocator_t<Handler, boost::asio::recycling_allocator<void>>>::template rebind_alloc<read_input_state> alloc; void operator()(read_input_state* ptr) { std::allocator_traits<decltype(alloc)>::deallocate(alloc, ptr, 1); } } d{boost::asio::get_associated_allocator(handler, boost::asio::recycling_allocator<void>())}; // Allocate memory for the state. std::unique_ptr<read_input_state, deleter> uninit_ptr( std::allocator_traits<decltype(d.alloc)>::allocate(d.alloc, 1), d); // Construct the state into the newly allocated memory. This might throw. read_input_state* ptr = new (uninit_ptr.get()) read_input_state(std::move(handler)); // Release ownership of the memory and return the newly allocated state. uninit_ptr.release(); return ptr; } static void callback(void* arg, const char* result) { read_input_state* self = static_cast<read_input_state*>(arg); // A unique_ptr deleter that is used to destroy initialised objects. struct deleter { // Get the handler's associated allocator type. If the handler does not // specify an associated allocator, we will use a recycling allocator as // the default. As the associated allocator is a proto-allocator, we must // rebind it to the correct type before we can use it to allocate objects. typename std::allocator_traits< boost::asio::associated_allocator_t<Handler, boost::asio::recycling_allocator<void>>>::template rebind_alloc<read_input_state> alloc; void operator()(read_input_state* ptr) { std::allocator_traits<decltype(alloc)>::destroy(alloc, ptr); std::allocator_traits<decltype(alloc)>::deallocate(alloc, ptr, 1); } } d{boost::asio::get_associated_allocator(self->handler_, boost::asio::recycling_allocator<void>())}; // To conform to the rules regarding asynchronous operations and memory // allocation, we must make a copy of the state and deallocate the memory // before dispatching the completion handler. std::unique_ptr<read_input_state, deleter> state_ptr(self, d); read_input_state state(std::move(*self)); state_ptr.reset(); // Dispatch the completion handler through the handler's associated // executor, using the handler's associated allocator. boost::asio::dispatch(state.work_.get_executor(), boost::asio::bind_allocator(d.alloc, [ handler = std::move(state.handler_), result = std::string(result) ]() mutable { std::move(handler)(result); })); } private: Handler handler_; // According to the rules for asynchronous operations, we need to track // outstanding work against the handler's associated executor until the // asynchronous operation is complete. boost::asio::executor_work_guard< boost::asio::associated_executor_t<Handler>> work_; }; // The initiating function for the asynchronous operation. template <boost::asio::completion_token_for<void(std::string)> CompletionToken> auto async_read_input(const std::string& prompt, CompletionToken&& token) { // Define a function object that contains the code to launch the asynchronous // operation. This is passed the concrete completion handler, followed by any // additional arguments that were passed through the call to async_initiate. auto init = []( boost::asio::completion_handler_for<void(std::string)> auto handler, const std::string& prompt) { // The body of the initiation function object creates the long-lived state // and passes it to the C-based API, along with the function pointer. using state_type = read_input_state<decltype(handler)>; read_input(prompt.c_str(), &state_type::callback, state_type::create(std::move(handler))); }; // The async_initiate function is used to transform the supplied completion // token to the completion handler. When calling this function we explicitly // specify the completion signature of the operation. We must also return the // result of the call since the completion token may produce a return value, // such as a future. return boost::asio::async_initiate<CompletionToken, void(std::string)>( init, // First, pass the function object that launches the operation, token, // then the completion token that will be transformed to a handler, prompt); // and, finally, any additional arguments to the function object. } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; // Test our asynchronous operation using a lambda as a callback. We will use // an io_context to obtain an associated executor. async_read_input("Enter your name", boost::asio::bind_executor(io_context, [](const std::string& result) { std::cout << "Hello " << result << "\n"; })); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. auto op = async_read_input("Enter your name", boost::asio::deferred); // Launch our asynchronous operation using a lambda as a callback. We will use // an io_context to obtain an associated executor. std::move(op)( boost::asio::bind_executor(io_context, [](const std::string& result) { std::cout << "Hello " << result << "\n"; })); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<std::string> f = async_read_input("Enter your name", boost::asio::use_future); std::string result = f.get(); std::cout << "Hello " << result << "\n"; } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/composed_4.cpp
// // composed_4.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/bind_executor.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/use_future.hpp> #include <boost/asio/write.hpp> #include <cstring> #include <functional> #include <iostream> #include <string> #include <type_traits> #include <utility> using boost::asio::ip::tcp; // NOTE: This example requires the new boost::asio::async_initiate function. For // an example that works with the Networking TS style of completion tokens, // please see an older version of asio. //------------------------------------------------------------------------------ // In this composed operation we repackage an existing operation, but with a // different completion handler signature. We will also intercept an empty // message as an invalid argument, and propagate the corresponding error to the // user. The asynchronous operation requirements are met by delegating // responsibility to the underlying operation. template < boost::asio::completion_token_for<void(boost::system::error_code)> CompletionToken> auto async_write_message(tcp::socket& socket, const char* message, CompletionToken&& token) // The return type of the initiating function is deduced from the combination // of: // // - the CompletionToken type, // - the completion handler signature, and // - the asynchronous operation's initiation function object. // // When the completion token is a simple callback, the return type is always // void. In this example, when the completion token is boost::asio::yield_context // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the // completion token is boost::asio::use_future it would be std::future<void>. When // the completion token is boost::asio::deferred, the return type differs for each // asynchronous operation. // // In C++20 we can omit the return type as it is automatically deduced from // the return type of boost::asio::async_initiate. { // In addition to determining the mechanism by which an asynchronous // operation delivers its result, a completion token also determines the time // when the operation commences. For example, when the completion token is a // simple callback the operation commences before the initiating function // returns. However, if the completion token's delivery mechanism uses a // future, we might instead want to defer initiation of the operation until // the returned future object is waited upon. // // To enable this, when implementing an asynchronous operation we must // package the initiation step as a function object. The initiation function // object's call operator is passed the concrete completion handler produced // by the completion token. This completion handler matches the asynchronous // operation's completion handler signature, which in this example is: // // void(boost::system::error_code error) // // The initiation function object also receives any additional arguments // required to start the operation. (Note: We could have instead passed these // arguments in the lambda capture set. However, we should prefer to // propagate them as function call arguments as this allows the completion // token to optimise how they are passed. For example, a lazy future which // defers initiation would need to make a decay-copy of the arguments, but // when using a simple callback the arguments can be trivially forwarded // straight through.) auto initiation = []( boost::asio::completion_handler_for<void(boost::system::error_code)> auto&& completion_handler, tcp::socket& socket, const char* message) { // The post operation has a completion handler signature of: // // void() // // and the async_write operation has a completion handler signature of: // // void(boost::system::error_code error, std::size n) // // Both of these operations' completion handler signatures differ from our // operation's completion handler signature. We will adapt our completion // handler to these signatures by using std::bind, which drops the // additional arguments. // // However, it is essential to the correctness of our composed operation // that we preserve the executor of the user-supplied completion handler. // The std::bind function will not do this for us, so we must do this by // first obtaining the completion handler's associated executor (defaulting // to the I/O executor - in this case the executor of the socket - if the // completion handler does not have its own) ... auto executor = boost::asio::get_associated_executor( completion_handler, socket.get_executor()); // ... and then binding this executor to our adapted completion handler // using the boost::asio::bind_executor function. std::size_t length = std::strlen(message); if (length == 0) { boost::asio::post( boost::asio::bind_executor(executor, std::bind(std::forward<decltype(completion_handler)>( completion_handler), boost::asio::error::invalid_argument))); } else { boost::asio::async_write(socket, boost::asio::buffer(message, length), boost::asio::bind_executor(executor, std::bind(std::forward<decltype(completion_handler)>( completion_handler), std::placeholders::_1))); } }; // The boost::asio::async_initiate function takes: // // - our initiation function object, // - the completion token, // - the completion handler signature, and // - any additional arguments we need to initiate the operation. // // It then asks the completion token to create a completion handler (i.e. a // callback) with the specified signature, and invoke the initiation function // object with this completion handler as well as the additional arguments. // The return value of async_initiate is the result of our operation's // initiating function. // // Note that we wrap non-const reference arguments in std::reference_wrapper // to prevent incorrect decay-copies of these objects. return boost::asio::async_initiate< CompletionToken, void(boost::system::error_code)>( initiation, token, std::ref(socket), message); } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using a lambda as a callback. async_write_message(socket, "", [](const boost::system::error_code& error) { if (!error) { std::cout << "Message sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. boost::asio::async_operation auto op = async_write_message(socket, "", boost::asio::deferred); // Launch the operation using a lambda as a callback. std::move(op)( [](const boost::system::error_code& error) { if (!error) { std::cout << "Message sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<void> f = async_write_message( socket, "", boost::asio::use_future); io_context.run(); try { // Get the result of the operation. f.get(); std::cout << "Message sent\n"; } catch (const std::exception& e) { std::cout << "Exception: " << e.what() << "\n"; } } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/composed_2.cpp
// // composed_2.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/use_future.hpp> #include <boost/asio/write.hpp> #include <cstring> #include <iostream> #include <string> #include <type_traits> #include <utility> using boost::asio::ip::tcp; // NOTE: This example requires the new boost::asio::async_initiate function. For // an example that works with the Networking TS style of completion tokens, // please see an older version of asio. //------------------------------------------------------------------------------ // This next simplest example of a composed asynchronous operation involves // repackaging multiple operations but choosing to invoke just one of them. All // of these underlying operations have the same completion signature. The // asynchronous operation requirements are met by delegating responsibility to // the underlying operations. template < boost::asio::completion_token_for<void(boost::system::error_code, std::size_t)> CompletionToken> auto async_write_message(tcp::socket& socket, const char* message, bool allow_partial_write, CompletionToken&& token) // The return type of the initiating function is deduced from the combination // of: // // - the CompletionToken type, // - the completion handler signature, and // - the asynchronous operation's initiation function object. // // When the completion token is a simple callback, the return type is void. // However, when the completion token is boost::asio::yield_context (used for // stackful coroutines) the return type would be std::size_t, and when the // completion token is boost::asio::use_future it would be std::future<std::size_t>. // When the completion token is boost::asio::deferred, the return type differs for // each asynchronous operation. // // In C++20 we can omit the return type as it is automatically deduced from // the return type of boost::asio::async_initiate. { // In addition to determining the mechanism by which an asynchronous // operation delivers its result, a completion token also determines the time // when the operation commences. For example, when the completion token is a // simple callback the operation commences before the initiating function // returns. However, if the completion token's delivery mechanism uses a // future, we might instead want to defer initiation of the operation until // the returned future object is waited upon. // // To enable this, when implementing an asynchronous operation we must // package the initiation step as a function object. The initiation function // object's call operator is passed the concrete completion handler produced // by the completion token. This completion handler matches the asynchronous // operation's completion handler signature, which in this example is: // // void(boost::system::error_code error, std::size_t) // // The initiation function object also receives any additional arguments // required to start the operation. (Note: We could have instead passed these // arguments in the lambda capture set. However, we should prefer to // propagate them as function call arguments as this allows the completion // token to optimise how they are passed. For example, a lazy future which // defers initiation would need to make a decay-copy of the arguments, but // when using a simple callback the arguments can be trivially forwarded // straight through.) auto initiation = []( boost::asio::completion_handler_for<void(boost::system::error_code, std::size_t)> auto&& completion_handler, tcp::socket& socket, const char* message, bool allow_partial_write) { if (allow_partial_write) { // When delegating to an underlying operation we must take care to // perfectly forward the completion handler. This ensures that our // operation works correctly with move-only function objects as // callbacks. return socket.async_write_some( boost::asio::buffer(message, std::strlen(message)), std::forward<decltype(completion_handler)>(completion_handler)); } else { // As above, we must perfectly forward the completion handler when calling // the alternate underlying operation. return boost::asio::async_write(socket, boost::asio::buffer(message, std::strlen(message)), std::forward<decltype(completion_handler)>(completion_handler)); } }; // The boost::asio::async_initiate function takes: // // - our initiation function object, // - the completion token, // - the completion handler signature, and // - any additional arguments we need to initiate the operation. // // It then asks the completion token to create a completion handler (i.e. a // callback) with the specified signature, and invoke the initiation function // object with this completion handler as well as the additional arguments. // The return value of async_initiate is the result of our operation's // initiating function. // // Note that we wrap non-const reference arguments in std::reference_wrapper // to prevent incorrect decay-copies of these objects. return boost::asio::async_initiate< CompletionToken, void(boost::system::error_code, std::size_t)>( initiation, token, std::ref(socket), message, allow_partial_write); } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using a lambda as a callback. async_write_message(socket, "Testing callback\r\n", false, [](const boost::system::error_code& error, std::size_t n) { if (!error) { std::cout << n << " bytes transferred\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. boost::asio::async_operation auto op = async_write_message( socket, "Testing deferred\r\n", false, boost::asio::deferred); // Launch the operation using a lambda as a callback. std::move(op)( [](const boost::system::error_code& error, std::size_t n) { if (!error) { std::cout << n << " bytes transferred\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<std::size_t> f = async_write_message( socket, "Testing future\r\n", false, boost::asio::use_future); io_context.run(); try { // Get the result of the operation. std::size_t n = f.get(); std::cout << n << " bytes transferred\n"; } catch (const std::exception& e) { std::cout << "Error: " << e.what() << "\n"; } } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/composed_6.cpp
// // composed_6.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/deferred.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/steady_timer.hpp> #include <boost/asio/use_future.hpp> #include <boost/asio/write.hpp> #include <functional> #include <iostream> #include <memory> #include <sstream> #include <string> #include <type_traits> #include <utility> using boost::asio::ip::tcp; // NOTE: This example requires the new boost::asio::async_initiate function. For // an example that works with the Networking TS style of completion tokens, // please see an older version of asio. //------------------------------------------------------------------------------ // This composed operation shows composition of multiple underlying operations. // It automatically serialises a message, using its I/O streams insertion // operator, before sending it N times on the socket. To do this, it must // allocate a buffer for the encoded message and ensure this buffer's validity // until all underlying async_write operation complete. A one second delay is // inserted prior to each write operation, using a steady_timer. template <typename T, boost::asio::completion_token_for<void(boost::system::error_code)> CompletionToken> auto async_write_messages(tcp::socket& socket, const T& message, std::size_t repeat_count, CompletionToken&& token) // The return type of the initiating function is deduced from the combination // of: // // - the CompletionToken type, // - the completion handler signature, and // - the asynchronous operation's initiation function object. // // When the completion token is a simple callback, the return type is always // void. In this example, when the completion token is boost::asio::yield_context // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the // completion token is boost::asio::use_future it would be std::future<void>. When // the completion token is boost::asio::deferred, the return type differs for each // asynchronous operation. // // In C++20 we can omit the return type as it is automatically deduced from // the return type of boost::asio::async_initiate. { // In addition to determining the mechanism by which an asynchronous // operation delivers its result, a completion token also determines the time // when the operation commences. For example, when the completion token is a // simple callback the operation commences before the initiating function // returns. However, if the completion token's delivery mechanism uses a // future, we might instead want to defer initiation of the operation until // the returned future object is waited upon. // // To enable this, when implementing an asynchronous operation we must // package the initiation step as a function object. The initiation function // object's call operator is passed the concrete completion handler produced // by the completion token. This completion handler matches the asynchronous // operation's completion handler signature, which in this example is: // // void(boost::system::error_code error) // // The initiation function object also receives any additional arguments // required to start the operation. (Note: We could have instead passed these // arguments in the lambda capture set. However, we should prefer to // propagate them as function call arguments as this allows the completion // token to optimise how they are passed. For example, a lazy future which // defers initiation would need to make a decay-copy of the arguments, but // when using a simple callback the arguments can be trivially forwarded // straight through.) auto initiation = []( boost::asio::completion_handler_for<void(boost::system::error_code)> auto&& completion_handler, tcp::socket& socket, std::unique_ptr<std::string> encoded_message, std::size_t repeat_count, std::unique_ptr<boost::asio::steady_timer> delay_timer) { // In this example, the composed operation's intermediate completion // handler is implemented as a hand-crafted function object. struct intermediate_completion_handler { // The intermediate completion handler holds a reference to the socket as // it is used for multiple async_write operations, as well as for // obtaining the I/O executor (see get_executor below). tcp::socket& socket_; // The allocated buffer for the encoded message. The std::unique_ptr // smart pointer is move-only, and as a consequence our intermediate // completion handler is also move-only. std::unique_ptr<std::string> encoded_message_; // The repeat count remaining. std::size_t repeat_count_; // A steady timer used for introducing a delay. std::unique_ptr<boost::asio::steady_timer> delay_timer_; // To manage the cycle between the multiple underlying asychronous // operations, our intermediate completion handler is implemented as a // state machine. enum { starting, waiting, writing } state_; // As our composed operation performs multiple underlying I/O operations, // we should maintain a work object against the I/O executor. This tells // the I/O executor that there is still more work to come in the future. boost::asio::executor_work_guard<tcp::socket::executor_type> io_work_; // The user-supplied completion handler, called once only on completion // of the entire composed operation. typename std::decay<decltype(completion_handler)>::type handler_; // By having a default value for the second argument, this function call // operator matches the completion signature of both the async_write and // steady_timer::async_wait operations. void operator()(const boost::system::error_code& error, std::size_t = 0) { if (!error) { switch (state_) { case starting: case writing: if (repeat_count_ > 0) { --repeat_count_; state_ = waiting; delay_timer_->expires_after(std::chrono::seconds(1)); delay_timer_->async_wait(std::move(*this)); return; // Composed operation not yet complete. } break; // Composed operation complete, continue below. case waiting: state_ = writing; boost::asio::async_write(socket_, boost::asio::buffer(*encoded_message_), std::move(*this)); return; // Composed operation not yet complete. } } // This point is reached only on completion of the entire composed // operation. // We no longer have any future work coming for the I/O executor. io_work_.reset(); // Deallocate the encoded message before calling the user-supplied // completion handler. encoded_message_.reset(); // Call the user-supplied handler with the result of the operation. handler_(error); } // It is essential to the correctness of our composed operation that we // preserve the executor of the user-supplied completion handler. With a // hand-crafted function object we can do this by defining a nested type // executor_type and member function get_executor. These obtain the // completion handler's associated executor, and default to the I/O // executor - in this case the executor of the socket - if the completion // handler does not have its own. using executor_type = boost::asio::associated_executor_t< typename std::decay<decltype(completion_handler)>::type, tcp::socket::executor_type>; executor_type get_executor() const noexcept { return boost::asio::get_associated_executor( handler_, socket_.get_executor()); } // Although not necessary for correctness, we may also preserve the // allocator of the user-supplied completion handler. This is achieved by // defining a nested type allocator_type and member function // get_allocator. These obtain the completion handler's associated // allocator, and default to std::allocator<void> if the completion // handler does not have its own. using allocator_type = boost::asio::associated_allocator_t< typename std::decay<decltype(completion_handler)>::type, std::allocator<void>>; allocator_type get_allocator() const noexcept { return boost::asio::get_associated_allocator( handler_, std::allocator<void>{}); } }; // Initiate the underlying async_write operation using our intermediate // completion handler. auto encoded_message_buffer = boost::asio::buffer(*encoded_message); boost::asio::async_write(socket, encoded_message_buffer, intermediate_completion_handler{ socket, std::move(encoded_message), repeat_count, std::move(delay_timer), intermediate_completion_handler::starting, boost::asio::make_work_guard(socket.get_executor()), std::forward<decltype(completion_handler)>(completion_handler)}); }; // Encode the message and copy it into an allocated buffer. The buffer will // be maintained for the lifetime of the composed asynchronous operation. std::ostringstream os; os << message; std::unique_ptr<std::string> encoded_message(new std::string(os.str())); // Create a steady_timer to be used for the delay between messages. std::unique_ptr<boost::asio::steady_timer> delay_timer( new boost::asio::steady_timer(socket.get_executor())); // The boost::asio::async_initiate function takes: // // - our initiation function object, // - the completion token, // - the completion handler signature, and // - any additional arguments we need to initiate the operation. // // It then asks the completion token to create a completion handler (i.e. a // callback) with the specified signature, and invoke the initiation function // object with this completion handler as well as the additional arguments. // The return value of async_initiate is the result of our operation's // initiating function. // // Note that we wrap non-const reference arguments in std::reference_wrapper // to prevent incorrect decay-copies of these objects. return boost::asio::async_initiate< CompletionToken, void(boost::system::error_code)>( initiation, token, std::ref(socket), std::move(encoded_message), repeat_count, std::move(delay_timer)); } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using a lambda as a callback. async_write_messages(socket, "Testing callback\r\n", 5, [](const boost::system::error_code& error) { if (!error) { std::cout << "Messages sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. boost::asio::async_operation auto op = async_write_messages( socket, "Testing deferred\r\n", 5, boost::asio::deferred); // Launch the operation using a lambda as a callback. std::move(op)( [](const boost::system::error_code& error) { if (!error) { std::cout << "Messages sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<void> f = async_write_messages( socket, "Testing future\r\n", 5, boost::asio::use_future); io_context.run(); try { // Get the result of the operation. f.get(); std::cout << "Messages sent\n"; } catch (const std::exception& e) { std::cout << "Error: " << e.what() << "\n"; } } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/composed_3.cpp
// // composed_3.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/bind_executor.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/use_future.hpp> #include <boost/asio/write.hpp> #include <cstring> #include <functional> #include <iostream> #include <string> #include <type_traits> #include <utility> using boost::asio::ip::tcp; // NOTE: This example requires the new boost::asio::async_initiate function. For // an example that works with the Networking TS style of completion tokens, // please see an older version of asio. //------------------------------------------------------------------------------ // In this composed operation we repackage an existing operation, but with a // different completion handler signature. The asynchronous operation // requirements are met by delegating responsibility to the underlying // operation. template < boost::asio::completion_token_for<void(boost::system::error_code)> CompletionToken> auto async_write_message(tcp::socket& socket, const char* message, CompletionToken&& token) // The return type of the initiating function is deduced from the combination // of: // // - the CompletionToken type, // - the completion handler signature, and // - the asynchronous operation's initiation function object. // // When the completion token is a simple callback, the return type is always // void. In this example, when the completion token is boost::asio::yield_context // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the // completion token is boost::asio::use_future it would be std::future<void>. When // the completion token is boost::asio::deferred, the return type differs for each // asynchronous operation. // // In C++20 we can omit the return type as it is automatically deduced from // the return type of boost::asio::async_initiate. { // In addition to determining the mechanism by which an asynchronous // operation delivers its result, a completion token also determines the time // when the operation commences. For example, when the completion token is a // simple callback the operation commences before the initiating function // returns. However, if the completion token's delivery mechanism uses a // future, we might instead want to defer initiation of the operation until // the returned future object is waited upon. // // To enable this, when implementing an asynchronous operation we must // package the initiation step as a function object. The initiation function // object's call operator is passed the concrete completion handler produced // by the completion token. This completion handler matches the asynchronous // operation's completion handler signature, which in this example is: // // void(boost::system::error_code error) // // The initiation function object also receives any additional arguments // required to start the operation. (Note: We could have instead passed these // arguments in the lambda capture set. However, we should prefer to // propagate them as function call arguments as this allows the completion // token to optimise how they are passed. For example, a lazy future which // defers initiation would need to make a decay-copy of the arguments, but // when using a simple callback the arguments can be trivially forwarded // straight through.) auto initiation = []( boost::asio::completion_handler_for<void(boost::system::error_code)> auto&& completion_handler, tcp::socket& socket, const char* message) { // The async_write operation has a completion handler signature of: // // void(boost::system::error_code error, std::size n) // // This differs from our operation's signature in that it is also passed // the number of bytes transferred as an argument of type std::size_t. We // will adapt our completion handler to async_write's completion handler // signature by using std::bind, which drops the additional argument. // // However, it is essential to the correctness of our composed operation // that we preserve the executor of the user-supplied completion handler. // The std::bind function will not do this for us, so we must do this by // first obtaining the completion handler's associated executor (defaulting // to the I/O executor - in this case the executor of the socket - if the // completion handler does not have its own) ... auto executor = boost::asio::get_associated_executor( completion_handler, socket.get_executor()); // ... and then binding this executor to our adapted completion handler // using the boost::asio::bind_executor function. boost::asio::async_write(socket, boost::asio::buffer(message, std::strlen(message)), boost::asio::bind_executor(executor, std::bind(std::forward<decltype(completion_handler)>( completion_handler), std::placeholders::_1))); }; // The boost::asio::async_initiate function takes: // // - our initiation function object, // - the completion token, // - the completion handler signature, and // - any additional arguments we need to initiate the operation. // // It then asks the completion token to create a completion handler (i.e. a // callback) with the specified signature, and invoke the initiation function // object with this completion handler as well as the additional arguments. // The return value of async_initiate is the result of our operation's // initiating function. // // Note that we wrap non-const reference arguments in std::reference_wrapper // to prevent incorrect decay-copies of these objects. return boost::asio::async_initiate< CompletionToken, void(boost::system::error_code)>( initiation, token, std::ref(socket), message); } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using a lambda as a callback. async_write_message(socket, "Testing callback\r\n", [](const boost::system::error_code& error) { if (!error) { std::cout << "Message sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. boost::asio::async_operation auto op = async_write_message( socket, "Testing deferred\r\n", boost::asio::deferred); // Launch the operation using a lambda as a callback. std::move(op)( [](const boost::system::error_code& error) { if (!error) { std::cout << "Message sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<void> f = async_write_message( socket, "Testing future\r\n", boost::asio::use_future); io_context.run(); // Get the result of the operation. try { // Get the result of the operation. f.get(); std::cout << "Message sent\n"; } catch (const std::exception& e) { std::cout << "Error: " << e.what() << "\n"; } } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/composed_7.cpp
// // composed_7.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/compose.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/steady_timer.hpp> #include <boost/asio/use_future.hpp> #include <boost/asio/write.hpp> #include <functional> #include <iostream> #include <memory> #include <sstream> #include <string> #include <type_traits> #include <utility> using boost::asio::ip::tcp; // NOTE: This example requires the new boost::asio::async_compose function. For // an example that works with the Networking TS style of completion tokens, // please see an older version of asio. //------------------------------------------------------------------------------ // This composed operation shows composition of multiple underlying operations. // It automatically serialises a message, using its I/O streams insertion // operator, before sending it N times on the socket. To do this, it must // allocate a buffer for the encoded message and ensure this buffer's validity // until all underlying async_write operation complete. A one second delay is // inserted prior to each write operation, using a steady_timer. template <typename T, boost::asio::completion_token_for<void(boost::system::error_code)> CompletionToken> auto async_write_messages(tcp::socket& socket, const T& message, std::size_t repeat_count, CompletionToken&& token) // The return type of the initiating function is deduced from the combination // of: // // - the CompletionToken type, // - the completion handler signature, and // - the asynchronous operation's initiation function object. // // When the completion token is a simple callback, the return type is always // void. In this example, when the completion token is boost::asio::yield_context // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the // completion token is boost::asio::use_future it would be std::future<void>. When // the completion token is boost::asio::deferred, the return type differs for each // asynchronous operation. // // In C++20 we can omit the return type as it is automatically deduced from // the return type of boost::asio::async_compose. { // Encode the message and copy it into an allocated buffer. The buffer will // be maintained for the lifetime of the composed asynchronous operation. std::ostringstream os; os << message; std::unique_ptr<std::string> encoded_message(new std::string(os.str())); // Create a steady_timer to be used for the delay between messages. std::unique_ptr<boost::asio::steady_timer> delay_timer( new boost::asio::steady_timer(socket.get_executor())); // To manage the cycle between the multiple underlying asychronous // operations, our implementation is a state machine. enum { starting, waiting, writing }; // The boost::asio::async_compose function takes: // // - our asynchronous operation implementation, // - the completion token, // - the completion handler signature, and // - any I/O objects (or executors) used by the operation // // It then wraps our implementation, which is implemented here as a state // machine in a lambda, in an intermediate completion handler that meets the // requirements of a conforming asynchronous operation. This includes // tracking outstanding work against the I/O executors associated with the // operation (in this example, this is the socket's executor). // // The first argument to our lambda is a reference to the enclosing // intermediate completion handler. This intermediate completion handler is // provided for us by the boost::asio::async_compose function, and takes care // of all the details required to implement a conforming asynchronous // operation. When calling an underlying asynchronous operation, we pass it // this enclosing intermediate completion handler as the completion token. // // All arguments to our lambda after the first must be defaulted to allow the // state machine to be started, as well as to allow the completion handler to // match the completion signature of both the async_write and // steady_timer::async_wait operations. return boost::asio::async_compose< CompletionToken, void(boost::system::error_code)>( [ // The implementation holds a reference to the socket as it is used for // multiple async_write operations. &socket, // The allocated buffer for the encoded message. The std::unique_ptr // smart pointer is move-only, and as a consequence our lambda // implementation is also move-only. encoded_message = std::move(encoded_message), // The repeat count remaining. repeat_count, // A steady timer used for introducing a delay. delay_timer = std::move(delay_timer), // To manage the cycle between the multiple underlying asychronous // operations, our implementation is a state machine. state = starting ] ( auto& self, const boost::system::error_code& error = {}, std::size_t = 0 ) mutable { if (!error) { switch (state) { case starting: case writing: if (repeat_count > 0) { --repeat_count; state = waiting; delay_timer->expires_after(std::chrono::seconds(1)); delay_timer->async_wait(std::move(self)); return; // Composed operation not yet complete. } break; // Composed operation complete, continue below. case waiting: state = writing; boost::asio::async_write(socket, boost::asio::buffer(*encoded_message), std::move(self)); return; // Composed operation not yet complete. } } // This point is reached only on completion of the entire composed // operation. // Deallocate the encoded message and delay timer before calling the // user-supplied completion handler. encoded_message.reset(); delay_timer.reset(); // Call the user-supplied handler with the result of the operation. self.complete(error); }, token, socket); } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using a lambda as a callback. async_write_messages(socket, "Testing callback\r\n", 5, [](const boost::system::error_code& error) { if (!error) { std::cout << "Messages sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. boost::asio::async_operation auto op = async_write_messages( socket, "Testing deferred\r\n", 5, boost::asio::deferred); // Launch the operation using a lambda as a callback. std::move(op)( [](const boost::system::error_code& error) { if (!error) { std::cout << "Messages sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<void> f = async_write_messages( socket, "Testing future\r\n", 5, boost::asio::use_future); io_context.run(); try { // Get the result of the operation. f.get(); std::cout << "Messages sent\n"; } catch (const std::exception& e) { std::cout << "Error: " << e.what() << "\n"; } } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/callback_wrapper.cpp
// // callback_wrapper.cpp // ~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio.hpp> #include <iostream> //------------------------------------------------------------------------------ // This is a mock implementation of an API that uses a move-only function object // for exposing a callback. The callback has the signature void(std::string). template <typename Callback> void read_input(const std::string& prompt, Callback cb) { std::thread( [prompt, cb = std::move(cb)]() mutable { std::cout << prompt << ": "; std::cout.flush(); std::string line; std::getline(std::cin, line); std::move(cb)(std::move(line)); }).detach(); } //------------------------------------------------------------------------------ // This is an asynchronous operation that wraps the callback-based API. // The initiating function for the asynchronous operation. template <boost::asio::completion_token_for<void(std::string)> CompletionToken> auto async_read_input(const std::string& prompt, CompletionToken&& token) { // Define a function object that contains the code to launch the asynchronous // operation. This is passed the concrete completion handler, followed by any // additional arguments that were passed through the call to async_initiate. auto init = []( boost::asio::completion_handler_for<void(std::string)> auto handler, const std::string& prompt) { // According to the rules for asynchronous operations, we need to track // outstanding work against the handler's associated executor until the // asynchronous operation is complete. auto work = boost::asio::make_work_guard(handler); // Launch the operation with a callback that will receive the result and // pass it through to the asynchronous operation's completion handler. read_input(prompt, [ handler = std::move(handler), work = std::move(work) ](std::string result) mutable { // Get the handler's associated allocator. If the handler does not // specify an allocator, use the recycling allocator as the default. auto alloc = boost::asio::get_associated_allocator( handler, boost::asio::recycling_allocator<void>()); // Dispatch the completion handler through the handler's associated // executor, using the handler's associated allocator. boost::asio::dispatch(work.get_executor(), boost::asio::bind_allocator(alloc, [ handler = std::move(handler), result = std::string(result) ]() mutable { std::move(handler)(result); })); }); }; // The async_initiate function is used to transform the supplied completion // token to the completion handler. When calling this function we explicitly // specify the completion signature of the operation. We must also return the // result of the call since the completion token may produce a return value, // such as a future. return boost::asio::async_initiate<CompletionToken, void(std::string)>( init, // First, pass the function object that launches the operation, token, // then the completion token that will be transformed to a handler, prompt); // and, finally, any additional arguments to the function object. } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; // Test our asynchronous operation using a lambda as a callback. We will use // an io_context to specify an associated executor. async_read_input("Enter your name", boost::asio::bind_executor(io_context, [](const std::string& result) { std::cout << "Hello " << result << "\n"; })); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. auto op = async_read_input("Enter your name", boost::asio::deferred); // Launch our asynchronous operation using a lambda as a callback. We will use // an io_context to obtain an associated executor. std::move(op)( boost::asio::bind_executor(io_context, [](const std::string& result) { std::cout << "Hello " << result << "\n"; })); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<std::string> f = async_read_input("Enter your name", boost::asio::use_future); std::string result = f.get(); std::cout << "Hello " << result << "\n"; } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/composed_8.cpp
// // composed_8.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/compose.hpp> #include <boost/asio/coroutine.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/steady_timer.hpp> #include <boost/asio/use_future.hpp> #include <boost/asio/write.hpp> #include <functional> #include <iostream> #include <memory> #include <sstream> #include <string> #include <type_traits> #include <utility> using boost::asio::ip::tcp; // NOTE: This example requires the new boost::asio::async_compose function. For // an example that works with the Networking TS style of completion tokens, // please see an older version of asio. //------------------------------------------------------------------------------ // This composed operation shows composition of multiple underlying operations, // using asio's stackless coroutines support to express the flow of control. It // automatically serialises a message, using its I/O streams insertion // operator, before sending it N times on the socket. To do this, it must // allocate a buffer for the encoded message and ensure this buffer's validity // until all underlying async_write operation complete. A one second delay is // inserted prior to each write operation, using a steady_timer. #include <boost/asio/yield.hpp> template <typename T, boost::asio::completion_token_for<void(boost::system::error_code)> CompletionToken> auto async_write_messages(tcp::socket& socket, const T& message, std::size_t repeat_count, CompletionToken&& token) // The return type of the initiating function is deduced from the combination // of: // // - the CompletionToken type, // - the completion handler signature, and // - the asynchronous operation's initiation function object. // // When the completion token is a simple callback, the return type is always // void. In this example, when the completion token is boost::asio::yield_context // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the // completion token is boost::asio::use_future it would be std::future<void>. When // the completion token is boost::asio::deferred, the return type differs for each // asynchronous operation. // // In C++20 we can omit the return type as it is automatically deduced from // the return type of boost::asio::async_compose. { // Encode the message and copy it into an allocated buffer. The buffer will // be maintained for the lifetime of the composed asynchronous operation. std::ostringstream os; os << message; std::unique_ptr<std::string> encoded_message(new std::string(os.str())); // Create a steady_timer to be used for the delay between messages. std::unique_ptr<boost::asio::steady_timer> delay_timer( new boost::asio::steady_timer(socket.get_executor())); // The boost::asio::async_compose function takes: // // - our asynchronous operation implementation, // - the completion token, // - the completion handler signature, and // - any I/O objects (or executors) used by the operation // // It then wraps our implementation, which is implemented here as a stackless // coroutine in a lambda, in an intermediate completion handler that meets the // requirements of a conforming asynchronous operation. This includes // tracking outstanding work against the I/O executors associated with the // operation (in this example, this is the socket's executor). // // The first argument to our lambda is a reference to the enclosing // intermediate completion handler. This intermediate completion handler is // provided for us by the boost::asio::async_compose function, and takes care // of all the details required to implement a conforming asynchronous // operation. When calling an underlying asynchronous operation, we pass it // this enclosing intermediate completion handler as the completion token. // // All arguments to our lambda after the first must be defaulted to allow the // state machine to be started, as well as to allow the completion handler to // match the completion signature of both the async_write and // steady_timer::async_wait operations. return boost::asio::async_compose< CompletionToken, void(boost::system::error_code)>( [ // The implementation holds a reference to the socket as it is used for // multiple async_write operations. &socket, // The allocated buffer for the encoded message. The std::unique_ptr // smart pointer is move-only, and as a consequence our lambda // implementation is also move-only. encoded_message = std::move(encoded_message), // The repeat count remaining. repeat_count, // A steady timer used for introducing a delay. delay_timer = std::move(delay_timer), // The coroutine state. coro = boost::asio::coroutine() ] ( auto& self, const boost::system::error_code& error = {}, std::size_t = 0 ) mutable { reenter (coro) { while (repeat_count > 0) { --repeat_count; delay_timer->expires_after(std::chrono::seconds(1)); yield delay_timer->async_wait(std::move(self)); if (error) break; yield boost::asio::async_write(socket, boost::asio::buffer(*encoded_message), std::move(self)); if (error) break; } // Deallocate the encoded message and delay timer before calling the // user-supplied completion handler. encoded_message.reset(); delay_timer.reset(); // Call the user-supplied handler with the result of the operation. self.complete(error); } }, token, socket); } #include <boost/asio/unyield.hpp> //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using a lambda as a callback. async_write_messages(socket, "Testing callback\r\n", 5, [](const boost::system::error_code& error) { if (!error) { std::cout << "Messages sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. boost::asio::async_operation auto op = async_write_messages( socket, "Testing deferred\r\n", 5, boost::asio::deferred); // Launch the operation using a lambda as a callback. std::move(op)( [](const boost::system::error_code& error) { if (!error) { std::cout << "Messages sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<void> f = async_write_messages( socket, "Testing future\r\n", 5, boost::asio::use_future); io_context.run(); try { // Get the result of the operation. f.get(); std::cout << "Messages sent\n"; } catch (const std::exception& e) { std::cout << "Error: " << e.what() << "\n"; } } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/composed_5.cpp
// // composed_5.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/use_future.hpp> #include <boost/asio/write.hpp> #include <functional> #include <iostream> #include <memory> #include <sstream> #include <string> #include <type_traits> #include <utility> using boost::asio::ip::tcp; // NOTE: This example requires the new boost::asio::async_initiate function. For // an example that works with the Networking TS style of completion tokens, // please see an older version of asio. //------------------------------------------------------------------------------ // This composed operation automatically serialises a message, using its I/O // streams insertion operator, before sending it on the socket. To do this, it // must allocate a buffer for the encoded message and ensure this buffer's // validity until the underlying async_write operation completes. template <typename T, boost::asio::completion_token_for<void(boost::system::error_code)> CompletionToken> auto async_write_message(tcp::socket& socket, const T& message, CompletionToken&& token) // The return type of the initiating function is deduced from the combination // of: // // - the CompletionToken type, // - the completion handler signature, and // - the asynchronous operation's initiation function object. // // When the completion token is a simple callback, the return type is always // void. In this example, when the completion token is boost::asio::yield_context // (used for stackful coroutines) the return type would also be void, as // there is no non-error argument to the completion handler. When the // completion token is boost::asio::use_future it would be std::future<void>. When // the completion token is boost::asio::deferred, the return type differs for each // asynchronous operation. // // In C++20 we can omit the return type as it is automatically deduced from // the return type of boost::asio::async_initiate. { // In addition to determining the mechanism by which an asynchronous // operation delivers its result, a completion token also determines the time // when the operation commences. For example, when the completion token is a // simple callback the operation commences before the initiating function // returns. However, if the completion token's delivery mechanism uses a // future, we might instead want to defer initiation of the operation until // the returned future object is waited upon. // // To enable this, when implementing an asynchronous operation we must // package the initiation step as a function object. The initiation function // object's call operator is passed the concrete completion handler produced // by the completion token. This completion handler matches the asynchronous // operation's completion handler signature, which in this example is: // // void(boost::system::error_code error) // // The initiation function object also receives any additional arguments // required to start the operation. (Note: We could have instead passed these // arguments in the lambda capture set. However, we should prefer to // propagate them as function call arguments as this allows the completion // token to optimise how they are passed. For example, a lazy future which // defers initiation would need to make a decay-copy of the arguments, but // when using a simple callback the arguments can be trivially forwarded // straight through.) auto initiation = []( boost::asio::completion_handler_for<void(boost::system::error_code)> auto&& completion_handler, tcp::socket& socket, std::unique_ptr<std::string> encoded_message) { // In this example, the composed operation's intermediate completion // handler is implemented as a hand-crafted function object, rather than // using a lambda or std::bind. struct intermediate_completion_handler { // The intermediate completion handler holds a reference to the socket so // that it can obtain the I/O executor (see get_executor below). tcp::socket& socket_; // The allocated buffer for the encoded message. The std::unique_ptr // smart pointer is move-only, and as a consequence our intermediate // completion handler is also move-only. std::unique_ptr<std::string> encoded_message_; // The user-supplied completion handler. typename std::decay<decltype(completion_handler)>::type handler_; // The function call operator matches the completion signature of the // async_write operation. void operator()(const boost::system::error_code& error, std::size_t /*n*/) { // Deallocate the encoded message before calling the user-supplied // completion handler. encoded_message_.reset(); // Call the user-supplied handler with the result of the operation. // The arguments must match the completion signature of our composed // operation. handler_(error); } // It is essential to the correctness of our composed operation that we // preserve the executor of the user-supplied completion handler. With a // hand-crafted function object we can do this by defining a nested type // executor_type and member function get_executor. These obtain the // completion handler's associated executor, and default to the I/O // executor - in this case the executor of the socket - if the completion // handler does not have its own. using executor_type = boost::asio::associated_executor_t< typename std::decay<decltype(completion_handler)>::type, tcp::socket::executor_type>; executor_type get_executor() const noexcept { return boost::asio::get_associated_executor( handler_, socket_.get_executor()); } // Although not necessary for correctness, we may also preserve the // allocator of the user-supplied completion handler. This is achieved by // defining a nested type allocator_type and member function // get_allocator. These obtain the completion handler's associated // allocator, and default to std::allocator<void> if the completion // handler does not have its own. using allocator_type = boost::asio::associated_allocator_t< typename std::decay<decltype(completion_handler)>::type, std::allocator<void>>; allocator_type get_allocator() const noexcept { return boost::asio::get_associated_allocator( handler_, std::allocator<void>{}); } }; // Initiate the underlying async_write operation using our intermediate // completion handler. auto encoded_message_buffer = boost::asio::buffer(*encoded_message); boost::asio::async_write(socket, encoded_message_buffer, intermediate_completion_handler{socket, std::move(encoded_message), std::forward<decltype(completion_handler)>(completion_handler)}); }; // Encode the message and copy it into an allocated buffer. The buffer will // be maintained for the lifetime of the asynchronous operation. std::ostringstream os; os << message; std::unique_ptr<std::string> encoded_message(new std::string(os.str())); // The boost::asio::async_initiate function takes: // // - our initiation function object, // - the completion token, // - the completion handler signature, and // - any additional arguments we need to initiate the operation. // // It then asks the completion token to create a completion handler (i.e. a // callback) with the specified signature, and invoke the initiation function // object with this completion handler as well as the additional arguments. // The return value of async_initiate is the result of our operation's // initiating function. // // Note that we wrap non-const reference arguments in std::reference_wrapper // to prevent incorrect decay-copies of these objects. return boost::asio::async_initiate< CompletionToken, void(boost::system::error_code)>( initiation, token, std::ref(socket), std::move(encoded_message)); } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using a lambda as a callback. async_write_message(socket, 123456, [](const boost::system::error_code& error) { if (!error) { std::cout << "Message sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. boost::asio::async_operation auto op = async_write_message( socket, std::string("abcdef"), boost::asio::deferred); // Launch the operation using a lambda as a callback. std::move(op)( [](const boost::system::error_code& error) { if (!error) { std::cout << "Message sent\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<void> f = async_write_message( socket, 654.321, boost::asio::use_future); io_context.run(); try { // Get the result of the operation. f.get(); std::cout << "Message sent\n"; } catch (const std::exception& e) { std::cout << "Exception: " << e.what() << "\n"; } } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/operations/composed_1.cpp
// // composed_1.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/use_future.hpp> #include <boost/asio/write.hpp> #include <cstring> #include <iostream> #include <string> #include <type_traits> #include <utility> using boost::asio::ip::tcp; //------------------------------------------------------------------------------ // This is the simplest example of a composed asynchronous operation, where we // simply repackage an existing operation. The asynchronous operation // requirements are met by delegating responsibility to the underlying // operation. template < boost::asio::completion_token_for<void(boost::system::error_code, std::size_t)> CompletionToken> auto async_write_message(tcp::socket& socket, const char* message, CompletionToken&& token) // The return type of the initiating function is deduced from the combination // of: // // - the CompletionToken type, // - the completion handler signature, and // - the asynchronous operation's initiation function object. // // When the completion token is a simple callback, the return type is void. // However, when the completion token is boost::asio::yield_context (used for // stackful coroutines) the return type would be std::size_t, and when the // completion token is boost::asio::use_future it would be std::future<std::size_t>. // When the completion token is boost::asio::deferred, the return type differs for // each asynchronous operation. // // In C++20 we can omit the return type as it is automatically deduced from // the return type of our underlying asynchronous operation. { // When delegating to the underlying operation we must take care to perfectly // forward the completion token. This ensures that our operation works // correctly with move-only function objects as callbacks, as well as other // completion token types. return boost::asio::async_write(socket, boost::asio::buffer(message, std::strlen(message)), std::forward<CompletionToken>(token)); } //------------------------------------------------------------------------------ void test_callback() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using a lambda as a callback. async_write_message(socket, "Testing callback\r\n", [](const boost::system::error_code& error, std::size_t n) { if (!error) { std::cout << n << " bytes transferred\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_deferred() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the deferred completion token. This // token causes the operation's initiating function to package up the // operation with its arguments to return a function object, which may then be // used to launch the asynchronous operation. boost::asio::async_operation auto op = async_write_message( socket, "Testing deferred\r\n", boost::asio::deferred); // Launch the operation using a lambda as a callback. std::move(op)( [](const boost::system::error_code& error, std::size_t n) { if (!error) { std::cout << n << " bytes transferred\n"; } else { std::cout << "Error: " << error.message() << "\n"; } }); io_context.run(); } //------------------------------------------------------------------------------ void test_future() { boost::asio::io_context io_context; tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); tcp::socket socket = acceptor.accept(); // Test our asynchronous operation using the use_future completion token. // This token causes the operation's initiating function to return a future, // which may be used to synchronously wait for the result of the operation. std::future<std::size_t> f = async_write_message( socket, "Testing future\r\n", boost::asio::use_future); io_context.run(); try { // Get the result of the operation. std::size_t n = f.get(); std::cout << n << " bytes transferred\n"; } catch (const std::exception& e) { std::cout << "Error: " << e.what() << "\n"; } } //------------------------------------------------------------------------------ int main() { test_callback(); test_deferred(); test_future(); }
cpp
asio
data/projects/asio/example/cpp20/invocation/completion_executor.cpp
// // completion_executor.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio.hpp> #include <concepts> #include <iostream> using boost::asio::ip::tcp; //---------------------------------------------------------------------- // The logging_executor class implements a minimal executor that satisfies the // requirements for use as a completion executor. This means it may be bound to // a handler using bind_executor. class logging_executor { public: // All executors must be no-throw equality comparable. bool operator==(const logging_executor&) const noexcept = default; // All executors must provide a const member function execute(). void execute(std::invocable auto handler) const { try { std::cout << "handler invocation starting\n"; std::move(handler)(); std::cout << "handler invocation complete\n"; } catch (...) { std::cout << "handler invocation completed with exception\n"; throw; } } }; // Confirm that a logging_executor satisfies the executor requirements. static_assert(boost::asio::execution::executor<logging_executor>); // Confirm that a logging_executor can be used as a completion executor. static_assert(std::convertible_to< logging_executor, boost::asio::any_completion_executor>); //---------------------------------------------------------------------- int main() { boost::asio::io_context io_context(1); // Post a completion handler to be run immediately. boost::asio::post(io_context, boost::asio::bind_executor(logging_executor{}, []{ std::cout << "post complete\n"; })); // Start an asynchronous accept that will complete immediately. tcp::endpoint endpoint(boost::asio::ip::address_v4::loopback(), 0); tcp::acceptor acceptor(io_context, endpoint); tcp::socket server_socket(io_context); acceptor.async_accept( boost::asio::bind_executor(logging_executor{}, [](auto...){ std::cout << "async_accept complete\n"; })); tcp::socket client_socket(io_context); client_socket.connect(acceptor.local_endpoint()); // Set a timer to expire immediately. boost::asio::steady_timer timer(io_context); timer.expires_at(boost::asio::steady_timer::clock_type::time_point::min()); timer.async_wait( boost::asio::bind_executor(logging_executor{}, [](auto){ std::cout << "async_wait complete\n"; })); io_context.run(); return 0; }
cpp
asio
data/projects/asio/example/cpp20/coroutines/chat_server.cpp
// // chat_server.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <cstdlib> #include <deque> #include <iostream> #include <list> #include <memory> #include <set> #include <string> #include <utility> #include <boost/asio/awaitable.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/co_spawn.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/read_until.hpp> #include <boost/asio/redirect_error.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/steady_timer.hpp> #include <boost/asio/use_awaitable.hpp> #include <boost/asio/write.hpp> using boost::asio::ip::tcp; using boost::asio::awaitable; using boost::asio::co_spawn; using boost::asio::detached; using boost::asio::redirect_error; using boost::asio::use_awaitable; //---------------------------------------------------------------------- class chat_participant { public: virtual ~chat_participant() {} virtual void deliver(const std::string& msg) = 0; }; typedef std::shared_ptr<chat_participant> chat_participant_ptr; //---------------------------------------------------------------------- class chat_room { public: void join(chat_participant_ptr participant) { participants_.insert(participant); for (auto msg: recent_msgs_) participant->deliver(msg); } void leave(chat_participant_ptr participant) { participants_.erase(participant); } void deliver(const std::string& msg) { recent_msgs_.push_back(msg); while (recent_msgs_.size() > max_recent_msgs) recent_msgs_.pop_front(); for (auto participant: participants_) participant->deliver(msg); } private: std::set<chat_participant_ptr> participants_; enum { max_recent_msgs = 100 }; std::deque<std::string> recent_msgs_; }; //---------------------------------------------------------------------- class chat_session : public chat_participant, public std::enable_shared_from_this<chat_session> { public: chat_session(tcp::socket socket, chat_room& room) : socket_(std::move(socket)), timer_(socket_.get_executor()), room_(room) { timer_.expires_at(std::chrono::steady_clock::time_point::max()); } void start() { room_.join(shared_from_this()); co_spawn(socket_.get_executor(), [self = shared_from_this()]{ return self->reader(); }, detached); co_spawn(socket_.get_executor(), [self = shared_from_this()]{ return self->writer(); }, detached); } void deliver(const std::string& msg) { write_msgs_.push_back(msg); timer_.cancel_one(); } private: awaitable<void> reader() { try { for (std::string read_msg;;) { std::size_t n = co_await boost::asio::async_read_until(socket_, boost::asio::dynamic_buffer(read_msg, 1024), "\n", use_awaitable); room_.deliver(read_msg.substr(0, n)); read_msg.erase(0, n); } } catch (std::exception&) { stop(); } } awaitable<void> writer() { try { while (socket_.is_open()) { if (write_msgs_.empty()) { boost::system::error_code ec; co_await timer_.async_wait(redirect_error(use_awaitable, ec)); } else { co_await boost::asio::async_write(socket_, boost::asio::buffer(write_msgs_.front()), use_awaitable); write_msgs_.pop_front(); } } } catch (std::exception&) { stop(); } } void stop() { room_.leave(shared_from_this()); socket_.close(); timer_.cancel(); } tcp::socket socket_; boost::asio::steady_timer timer_; chat_room& room_; std::deque<std::string> write_msgs_; }; //---------------------------------------------------------------------- awaitable<void> listener(tcp::acceptor acceptor) { chat_room room; for (;;) { std::make_shared<chat_session>( co_await acceptor.async_accept(use_awaitable), room )->start(); } } //---------------------------------------------------------------------- int main(int argc, char* argv[]) { try { if (argc < 2) { std::cerr << "Usage: chat_server <port> [<port> ...]\n"; return 1; } boost::asio::io_context io_context(1); for (int i = 1; i < argc; ++i) { unsigned short port = std::atoi(argv[i]); co_spawn(io_context, listener(tcp::acceptor(io_context, {tcp::v4(), port})), detached); } boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); signals.async_wait([&](auto, auto){ io_context.stop(); }); io_context.run(); } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; } return 0; }
cpp
asio
data/projects/asio/example/cpp20/coroutines/echo_server_with_deferred_default.cpp
// // echo_server.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/co_spawn.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/write.hpp> #include <cstdio> using boost::asio::ip::tcp; using boost::asio::awaitable; using boost::asio::co_spawn; using boost::asio::detached; using default_token = boost::asio::deferred_t; using tcp_acceptor = default_token::as_default_on_t<tcp::acceptor>; using tcp_socket = default_token::as_default_on_t<tcp::socket>; namespace this_coro = boost::asio::this_coro; awaitable<void> echo(tcp_socket socket) { try { char data[1024]; for (;;) { std::size_t n = co_await socket.async_read_some(boost::asio::buffer(data)); co_await async_write(socket, boost::asio::buffer(data, n)); } } catch (std::exception& e) { std::printf("echo Exception: %s\n", e.what()); } } awaitable<void> listener() { auto executor = co_await this_coro::executor; tcp_acceptor acceptor(executor, {tcp::v4(), 55555}); for (;;) { tcp::socket socket = co_await acceptor.async_accept(); co_spawn(executor, echo(std::move(socket)), detached); } } int main() { try { boost::asio::io_context io_context(1); boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); signals.async_wait([&](auto, auto){ io_context.stop(); }); co_spawn(io_context, listener(), detached); io_context.run(); } catch (std::exception& e) { std::printf("Exception: %s\n", e.what()); } }
cpp
asio
data/projects/asio/example/cpp20/coroutines/refactored_echo_server.cpp
// // refactored_echo_server.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/co_spawn.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/write.hpp> #include <cstdio> using boost::asio::ip::tcp; using boost::asio::awaitable; using boost::asio::co_spawn; using boost::asio::detached; using boost::asio::use_awaitable; namespace this_coro = boost::asio::this_coro; awaitable<void> echo_once(tcp::socket& socket) { char data[128]; std::size_t n = co_await socket.async_read_some(boost::asio::buffer(data), use_awaitable); co_await async_write(socket, boost::asio::buffer(data, n), use_awaitable); } awaitable<void> echo(tcp::socket socket) { try { for (;;) { // The asynchronous operations to echo a single chunk of data have been // refactored into a separate function. When this function is called, the // operations are still performed in the context of the current // coroutine, and the behaviour is functionally equivalent. co_await echo_once(socket); } } catch (std::exception& e) { std::printf("echo Exception: %s\n", e.what()); } } awaitable<void> listener() { auto executor = co_await this_coro::executor; tcp::acceptor acceptor(executor, {tcp::v4(), 55555}); for (;;) { tcp::socket socket = co_await acceptor.async_accept(use_awaitable); co_spawn(executor, echo(std::move(socket)), detached); } } int main() { try { boost::asio::io_context io_context(1); boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); signals.async_wait([&](auto, auto){ io_context.stop(); }); co_spawn(io_context, listener(), detached); io_context.run(); } catch (std::exception& e) { std::printf("Exception: %s\n", e.what()); } }
cpp
asio
data/projects/asio/example/cpp20/coroutines/echo_server_with_deferred.cpp
// // echo_server.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/co_spawn.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/write.hpp> #include <cstdio> using boost::asio::ip::tcp; using boost::asio::awaitable; using boost::asio::co_spawn; using boost::asio::deferred; using boost::asio::detached; namespace this_coro = boost::asio::this_coro; awaitable<void> echo(tcp::socket socket) { try { char data[1024]; for (;;) { std::size_t n = co_await socket.async_read_some(boost::asio::buffer(data), deferred); co_await async_write(socket, boost::asio::buffer(data, n), deferred); } } catch (std::exception& e) { std::printf("echo Exception: %s\n", e.what()); } } awaitable<void> listener() { auto executor = co_await this_coro::executor; tcp::acceptor acceptor(executor, {tcp::v4(), 55555}); for (;;) { tcp::socket socket = co_await acceptor.async_accept(deferred); co_spawn(executor, echo(std::move(socket)), detached); } } int main() { try { boost::asio::io_context io_context(1); boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); signals.async_wait([&](auto, auto){ io_context.stop(); }); co_spawn(io_context, listener(), detached); io_context.run(); } catch (std::exception& e) { std::printf("Exception: %s\n", e.what()); } }
cpp
asio
data/projects/asio/example/cpp20/coroutines/timeout.cpp
// // timeout.cpp // ~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio.hpp> #include <boost/asio/experimental/awaitable_operators.hpp> using namespace boost::asio; using namespace boost::asio::experimental::awaitable_operators; using time_point = std::chrono::steady_clock::time_point; using ip::tcp; awaitable<void> echo(tcp::socket& sock, time_point& deadline) { char data[4196]; for (;;) { deadline = std::chrono::steady_clock::now() + std::chrono::seconds(10); auto n = co_await sock.async_read_some(buffer(data), use_awaitable); co_await async_write(sock, buffer(data, n), use_awaitable); } } awaitable<void> watchdog(time_point& deadline) { steady_timer timer(co_await this_coro::executor); auto now = std::chrono::steady_clock::now(); while (deadline > now) { timer.expires_at(deadline); co_await timer.async_wait(use_awaitable); now = std::chrono::steady_clock::now(); } throw boost::system::system_error(std::make_error_code(std::errc::timed_out)); } awaitable<void> handle_connection(tcp::socket sock) { time_point deadline{}; co_await (echo(sock, deadline) && watchdog(deadline)); } awaitable<void> listen(tcp::acceptor& acceptor) { for (;;) { co_spawn( acceptor.get_executor(), handle_connection(co_await acceptor.async_accept(use_awaitable)), detached); } } int main() { io_context ctx; tcp::acceptor acceptor(ctx, {tcp::v4(), 54321}); co_spawn(ctx, listen(acceptor), detached); ctx.run(); }
cpp
asio
data/projects/asio/example/cpp20/coroutines/echo_server_with_default.cpp
// // echo_server_with_default.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/co_spawn.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/write.hpp> #include <cstdio> using boost::asio::ip::tcp; using boost::asio::awaitable; using boost::asio::co_spawn; using boost::asio::detached; using boost::asio::use_awaitable_t; using tcp_acceptor = use_awaitable_t<>::as_default_on_t<tcp::acceptor>; using tcp_socket = use_awaitable_t<>::as_default_on_t<tcp::socket>; namespace this_coro = boost::asio::this_coro; awaitable<void> echo(tcp_socket socket) { try { char data[1024]; for (;;) { std::size_t n = co_await socket.async_read_some(boost::asio::buffer(data)); co_await async_write(socket, boost::asio::buffer(data, n)); } } catch (std::exception& e) { std::printf("echo Exception: %s\n", e.what()); } } awaitable<void> listener() { auto executor = co_await this_coro::executor; tcp_acceptor acceptor(executor, {tcp::v4(), 55555}); for (;;) { auto socket = co_await acceptor.async_accept(); co_spawn(executor, echo(std::move(socket)), detached); } } int main() { try { boost::asio::io_context io_context(1); boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); signals.async_wait([&](auto, auto){ io_context.stop(); }); co_spawn(io_context, listener(), detached); io_context.run(); } catch (std::exception& e) { std::printf("Exception: %s\n", e.what()); } }
cpp
asio
data/projects/asio/example/cpp20/coroutines/echo_server_with_as_tuple_default.cpp
// // echo_server_with_as_tuple_default.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/as_tuple.hpp> #include <boost/asio/co_spawn.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/write.hpp> #include <cstdio> using boost::asio::as_tuple_t; using boost::asio::ip::tcp; using boost::asio::awaitable; using boost::asio::co_spawn; using boost::asio::detached; using boost::asio::use_awaitable_t; using default_token = as_tuple_t<use_awaitable_t<>>; using tcp_acceptor = default_token::as_default_on_t<tcp::acceptor>; using tcp_socket = default_token::as_default_on_t<tcp::socket>; namespace this_coro = boost::asio::this_coro; awaitable<void> echo(tcp_socket socket) { char data[1024]; for (;;) { auto [e1, nread] = co_await socket.async_read_some(boost::asio::buffer(data)); if (nread == 0) break; auto [e2, nwritten] = co_await async_write(socket, boost::asio::buffer(data, nread)); if (nwritten != nread) break; } } awaitable<void> listener() { auto executor = co_await this_coro::executor; tcp_acceptor acceptor(executor, {tcp::v4(), 55555}); for (;;) { if (auto [e, socket] = co_await acceptor.async_accept(); socket.is_open()) co_spawn(executor, echo(std::move(socket)), detached); } } int main() { try { boost::asio::io_context io_context(1); boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); signals.async_wait([&](auto, auto){ io_context.stop(); }); co_spawn(io_context, listener(), detached); io_context.run(); } catch (std::exception& e) { std::printf("Exception: %s\n", e.what()); } }
cpp
asio
data/projects/asio/example/cpp20/coroutines/echo_server.cpp
// // echo_server.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/co_spawn.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/write.hpp> #include <cstdio> using boost::asio::ip::tcp; using boost::asio::awaitable; using boost::asio::co_spawn; using boost::asio::detached; using boost::asio::use_awaitable; namespace this_coro = boost::asio::this_coro; #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # define use_awaitable \ boost::asio::use_awaitable_t(__FILE__, __LINE__, __PRETTY_FUNCTION__) #endif awaitable<void> echo(tcp::socket socket) { try { char data[1024]; for (;;) { std::size_t n = co_await socket.async_read_some(boost::asio::buffer(data), use_awaitable); co_await async_write(socket, boost::asio::buffer(data, n), use_awaitable); } } catch (std::exception& e) { std::printf("echo Exception: %s\n", e.what()); } } awaitable<void> listener() { auto executor = co_await this_coro::executor; tcp::acceptor acceptor(executor, {tcp::v4(), 55555}); for (;;) { tcp::socket socket = co_await acceptor.async_accept(use_awaitable); co_spawn(executor, echo(std::move(socket)), detached); } } int main() { try { boost::asio::io_context io_context(1); boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); signals.async_wait([&](auto, auto){ io_context.stop(); }); co_spawn(io_context, listener(), detached); io_context.run(); } catch (std::exception& e) { std::printf("Exception: %s\n", e.what()); } }
cpp
asio
data/projects/asio/example/cpp20/coroutines/echo_server_with_as_single_default.cpp
// // echo_server_with_as_single_default.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio/experimental/as_single.hpp> #include <boost/asio/co_spawn.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/write.hpp> #include <cstdio> using boost::asio::experimental::as_single_t; using boost::asio::ip::tcp; using boost::asio::awaitable; using boost::asio::co_spawn; using boost::asio::detached; using boost::asio::use_awaitable_t; using default_token = as_single_t<use_awaitable_t<>>; using tcp_acceptor = default_token::as_default_on_t<tcp::acceptor>; using tcp_socket = default_token::as_default_on_t<tcp::socket>; namespace this_coro = boost::asio::this_coro; awaitable<void> echo(tcp_socket socket) { char data[1024]; for (;;) { auto [e1, nread] = co_await socket.async_read_some(boost::asio::buffer(data)); if (nread == 0) break; auto [e2, nwritten] = co_await async_write(socket, boost::asio::buffer(data, nread)); if (nwritten != nread) break; } } awaitable<void> listener() { auto executor = co_await this_coro::executor; tcp_acceptor acceptor(executor, {tcp::v4(), 55555}); for (;;) { if (auto [e, socket] = co_await acceptor.async_accept(); socket.is_open()) co_spawn(executor, echo(std::move(socket)), detached); } } int main() { try { boost::asio::io_context io_context(1); boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); signals.async_wait([&](auto, auto){ io_context.stop(); }); co_spawn(io_context, listener(), detached); io_context.run(); } catch (std::exception& e) { std::printf("Exception: %s\n", e.what()); } }
cpp
asio
data/projects/asio/example/cpp20/type_erasure/sleep.cpp
// // sleep.cpp // ~~~~~~~~~ // // Copyright (c) 2003-2024 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 "sleep.hpp" #include <boost/asio/consign.hpp> #include <boost/asio/steady_timer.hpp> #include <memory> void async_sleep_impl( boost::asio::any_completion_handler<void(boost::system::error_code)> handler, boost::asio::any_io_executor ex, std::chrono::nanoseconds duration) { auto timer = std::make_shared<boost::asio::steady_timer>(ex, duration); timer->async_wait(boost::asio::consign(std::move(handler), timer)); }
cpp
asio
data/projects/asio/example/cpp20/type_erasure/main.cpp
// // main.cpp // ~~~~~~~~ // // Copyright (c) 2003-2024 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 "line_reader.hpp" #include "sleep.hpp" #include "stdin_line_reader.hpp" #include <boost/asio/co_spawn.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/use_awaitable.hpp> #include <iostream> boost::asio::awaitable<void> do_read(line_reader& reader) { for (int i = 0; i < 10; ++i) { std::cout << co_await reader.async_read_line("Enter something: ", boost::asio::use_awaitable); co_await async_sleep(co_await boost::asio::this_coro::executor, std::chrono::seconds(1), boost::asio::use_awaitable); } } int main() { boost::asio::io_context ctx{1}; stdin_line_reader reader{ctx.get_executor()}; co_spawn(ctx, do_read(reader), boost::asio::detached); ctx.run(); }
cpp
asio
data/projects/asio/example/cpp20/type_erasure/stdin_line_reader.hpp
// // stdin_line_reader.hpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 STDIN_LINE_READER_HPP #define STDIN_LINE_READER_HPP #include "line_reader.hpp" #include <boost/asio/posix/stream_descriptor.hpp> class stdin_line_reader : public line_reader { public: explicit stdin_line_reader(boost::asio::any_io_executor ex); private: void async_read_line_impl(std::string prompt, boost::asio::any_completion_handler<void(boost::system::error_code, std::string)> handler) override; boost::asio::posix::stream_descriptor stdin_; std::string buffer_; }; #endif
hpp
asio
data/projects/asio/example/cpp20/type_erasure/sleep.hpp
// // sleep.hpp // ~~~~~~~~~ // // Copyright (c) 2003-2024 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 SLEEP_HPP #define SLEEP_HPP #include <boost/asio/any_completion_handler.hpp> #include <boost/asio/any_io_executor.hpp> #include <boost/asio/async_result.hpp> #include <boost/asio/error.hpp> #include <chrono> void async_sleep_impl( boost::asio::any_completion_handler<void(boost::system::error_code)> handler, boost::asio::any_io_executor ex, std::chrono::nanoseconds duration); template <typename CompletionToken> inline auto async_sleep(boost::asio::any_io_executor ex, std::chrono::nanoseconds duration, CompletionToken&& token) { return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code)>( async_sleep_impl, token, std::move(ex), duration); } #endif // SLEEP_HPP
hpp
asio
data/projects/asio/example/cpp20/type_erasure/line_reader.hpp
// // line_reader.hpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 LINE_READER_HPP #define LINE_READER_HPP #include <boost/asio/any_completion_handler.hpp> #include <boost/asio/async_result.hpp> #include <boost/asio/error.hpp> #include <string> class line_reader { public: virtual ~line_reader() {} template <typename CompletionToken> auto async_read_line(std::string prompt, CompletionToken&& token) { return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code, std::string)>( [](auto handler, line_reader* self, std::string prompt) { self->async_read_line_impl(std::move(prompt), std::move(handler)); }, token, this, prompt); } private: virtual void async_read_line_impl(std::string prompt, boost::asio::any_completion_handler<void(boost::system::error_code, std::string)> handler) = 0; }; #endif // LINE_READER_HPP
hpp
asio
data/projects/asio/example/cpp20/type_erasure/stdin_line_reader.cpp
// // stdin_line_reader.cpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 "stdin_line_reader.hpp" #include <boost/asio/deferred.hpp> #include <boost/asio/read_until.hpp> #include <iostream> stdin_line_reader::stdin_line_reader(boost::asio::any_io_executor ex) : stdin_(ex, ::dup(STDIN_FILENO)) { } void stdin_line_reader::async_read_line_impl(std::string prompt, boost::asio::any_completion_handler<void(boost::system::error_code, std::string)> handler) { std::cout << prompt; std::cout.flush(); boost::asio::async_read_until(stdin_, boost::asio::dynamic_buffer(buffer_), '\n', boost::asio::deferred( [this](boost::system::error_code ec, std::size_t n) { if (!ec) { std::string result = buffer_.substr(0, n); buffer_.erase(0, n); return boost::asio::deferred.values(ec, std::move(result)); } else { return boost::asio::deferred.values(ec, std::string{}); } } ) )(std::move(handler)); }
cpp
asio
data/projects/asio/example/cpp20/channels/mutual_exclusion_2.cpp
// // mutual_exclusion_2.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio.hpp> #include <boost/asio/experimental/channel.hpp> #include <iostream> #include <memory> using boost::asio::as_tuple; using boost::asio::awaitable; using boost::asio::dynamic_buffer; using boost::asio::co_spawn; using boost::asio::deferred; using boost::asio::detached; using boost::asio::experimental::channel; using boost::asio::io_context; using boost::asio::ip::tcp; using boost::asio::steady_timer; using namespace boost::asio::buffer_literals; using namespace std::literals::chrono_literals; // This class implements a simple line-based protocol: // // * For event line that is received from the client, the session sends a // message header followed by the content of the line as the message body. // // * The session generates heartbeat messages once a second. // // This protocol is implemented using two actors, handle_messages() and // send_heartbeats(), each written as a coroutine. class line_based_echo_session : public std::enable_shared_from_this<line_based_echo_session> { // The socket used to read from and write to the client. This socket is a // data member as it is shared between the two actors. tcp::socket socket_; // As both of the actors will write to the socket, we need a lock to prevent // these writes from overlapping. To achieve this, we use a channel with a // buffer size of one. The lock is claimed by sending a message to the // channel, and then released by receiving this message back again. If the // lock is not held then the channel's buffer is empty, and the send will // complete without delay. Otherwise, if the lock is held by the other actor, // then the send operation will not complete until the lock is released. channel<void()> write_lock_{socket_.get_executor(), 1}; public: line_based_echo_session(tcp::socket socket) : socket_{std::move(socket)} { socket_.set_option(tcp::no_delay(true)); } void start() { co_spawn(socket_.get_executor(), [self = shared_from_this()]{ return self->handle_messages(); }, detached); co_spawn(socket_.get_executor(), [self = shared_from_this()]{ return self->send_heartbeats(); }, detached); } private: void stop() { socket_.close(); write_lock_.cancel(); } awaitable<void> handle_messages() { try { constexpr std::size_t max_line_length = 1024; std::string data; for (;;) { // Read an entire line from the client. std::size_t length = co_await async_read_until(socket_, dynamic_buffer(data, max_line_length), '\n', deferred); // Claim the write lock by sending a message to the channel. Since the // channel signature is void(), there are no arguments to send in the // message itself. In this example we optimise for the common case, // where the lock is not held by the other actor, by first trying a // non-blocking send. if (!write_lock_.try_send()) { co_await write_lock_.async_send(deferred); } // Respond to the client with a message, echoing the line they sent. co_await async_write(socket_, "<line>"_buf, deferred); co_await async_write(socket_, dynamic_buffer(data, length), deferred); // Release the lock by receiving the message back again. write_lock_.try_receive([](auto...){}); } } catch (const std::exception&) { stop(); } } awaitable<void> send_heartbeats() { steady_timer timer{socket_.get_executor()}; try { for (;;) { // Wait one second before trying to send the next heartbeat. timer.expires_after(1s); co_await timer.async_wait(deferred); // Claim the write lock by sending a message to the channel. Since the // channel signature is void(), there are no arguments to send in the // message itself. In this example we optimise for the common case, // where the lock is not held by the other actor, by first trying a // non-blocking send. if (!write_lock_.try_send()) { co_await write_lock_.async_send(deferred); } // Send a heartbeat to the client. As the content of the heartbeat // message never varies, a buffer literal can be used to specify the // bytes of the message. The memory associated with a buffer literal is // valid for the lifetime of the program, which mean that the buffer // can be safely passed as-is to the asynchronous operation. co_await async_write(socket_, "<heartbeat>\n"_buf, deferred); // Release the lock by receiving the message back again. write_lock_.try_receive([](auto...){}); } } catch (const std::exception&) { stop(); } } }; awaitable<void> listen(tcp::acceptor& acceptor) { for (;;) { auto [e, socket] = co_await acceptor.async_accept(as_tuple(deferred)); if (!e) { std::make_shared<line_based_echo_session>(std::move(socket))->start(); } } } int main(int argc, char* argv[]) { try { if (argc != 3) { std::cerr << "Usage: mutual_exclusion_1"; std::cerr << " <listen_address> <listen_port>\n"; return 1; } io_context ctx; auto listen_endpoint = *tcp::resolver(ctx).resolve(argv[1], argv[2], tcp::resolver::passive).begin(); tcp::acceptor acceptor(ctx, listen_endpoint); co_spawn(ctx, listen(acceptor), detached); ctx.run(); } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; } }
cpp
asio
data/projects/asio/example/cpp20/channels/throttling_proxy.cpp
// // throttling_proxy.cpp // ~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio.hpp> #include <boost/asio/experimental/awaitable_operators.hpp> #include <boost/asio/experimental/channel.hpp> #include <iostream> using boost::asio::as_tuple; using boost::asio::awaitable; using boost::asio::buffer; using boost::asio::co_spawn; using boost::asio::detached; using boost::asio::experimental::channel; using boost::asio::io_context; using boost::asio::ip::tcp; using boost::asio::steady_timer; using boost::asio::use_awaitable; namespace this_coro = boost::asio::this_coro; using namespace boost::asio::experimental::awaitable_operators; using namespace std::literals::chrono_literals; using token_channel = channel<void(boost::system::error_code, std::size_t)>; awaitable<void> produce_tokens(std::size_t bytes_per_token, steady_timer::duration token_interval, token_channel& tokens) { steady_timer timer(co_await this_coro::executor); for (;;) { co_await tokens.async_send( boost::system::error_code{}, bytes_per_token, use_awaitable); timer.expires_after(token_interval); co_await timer.async_wait(use_awaitable); } } awaitable<void> transfer(tcp::socket& from, tcp::socket& to, token_channel& tokens) { std::array<unsigned char, 4096> data; for (;;) { std::size_t bytes_available = co_await tokens.async_receive(use_awaitable); while (bytes_available > 0) { std::size_t n = co_await from.async_read_some( buffer(data, bytes_available), use_awaitable); co_await async_write(to, buffer(data, n), use_awaitable); bytes_available -= n; } } } awaitable<void> proxy(tcp::socket client, tcp::endpoint target) { constexpr std::size_t number_of_tokens = 100; constexpr size_t bytes_per_token = 20 * 1024; constexpr steady_timer::duration token_interval = 100ms; auto ex = client.get_executor(); tcp::socket server(ex); token_channel client_tokens(ex, number_of_tokens); token_channel server_tokens(ex, number_of_tokens); co_await server.async_connect(target, use_awaitable); co_await ( produce_tokens(bytes_per_token, token_interval, client_tokens) && transfer(client, server, client_tokens) && produce_tokens(bytes_per_token, token_interval, server_tokens) && transfer(server, client, server_tokens) ); } awaitable<void> listen(tcp::acceptor& acceptor, tcp::endpoint target) { for (;;) { auto [e, client] = co_await acceptor.async_accept(as_tuple(use_awaitable)); if (!e) { auto ex = client.get_executor(); co_spawn(ex, proxy(std::move(client), target), detached); } else { std::cerr << "Accept failed: " << e.message() << "\n"; steady_timer timer(co_await this_coro::executor); timer.expires_after(100ms); co_await timer.async_wait(use_awaitable); } } } int main(int argc, char* argv[]) { try { if (argc != 5) { std::cerr << "Usage: throttling_proxy"; std::cerr << " <listen_address> <listen_port>"; std::cerr << " <target_address> <target_port>\n"; return 1; } io_context ctx; auto listen_endpoint = *tcp::resolver(ctx).resolve(argv[1], argv[2], tcp::resolver::passive).begin(); auto target_endpoint = *tcp::resolver(ctx).resolve(argv[3], argv[4]).begin(); tcp::acceptor acceptor(ctx, listen_endpoint); co_spawn(ctx, listen(acceptor, target_endpoint), detached); ctx.run(); } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; } }
cpp
asio
data/projects/asio/example/cpp20/channels/mutual_exclusion_1.cpp
// // mutual_exclusion_1.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 <boost/asio.hpp> #include <boost/asio/experimental/channel.hpp> #include <iostream> #include <memory> using boost::asio::as_tuple; using boost::asio::awaitable; using boost::asio::dynamic_buffer; using boost::asio::co_spawn; using boost::asio::deferred; using boost::asio::detached; using boost::asio::experimental::channel; using boost::asio::io_context; using boost::asio::ip::tcp; using boost::asio::steady_timer; using namespace boost::asio::buffer_literals; using namespace std::literals::chrono_literals; // This class implements a simple line-based protocol: // // * For event line that is received from the client, the session sends a // message header followed by the content of the line as the message body. // // * The session generates heartbeat messages once a second. // // This protocol is implemented using two actors, handle_messages() and // send_heartbeats(), each written as a coroutine. class line_based_echo_session : public std::enable_shared_from_this<line_based_echo_session> { // The socket used to read from and write to the client. This socket is a // data member as it is shared between the two actors. tcp::socket socket_; // As both of the actors will write to the socket, we need a lock to prevent // these writes from overlapping. To achieve this, we use a channel with a // buffer size of one. The lock is claimed by sending a message to the // channel, and then released by receiving this message back again. If the // lock is not held then the channel's buffer is empty, and the send will // complete without delay. Otherwise, if the lock is held by the other actor, // then the send operation will not complete until the lock is released. channel<void()> write_lock_{socket_.get_executor(), 1}; public: line_based_echo_session(tcp::socket socket) : socket_{std::move(socket)} { socket_.set_option(tcp::no_delay(true)); } void start() { co_spawn(socket_.get_executor(), [self = shared_from_this()]{ return self->handle_messages(); }, detached); co_spawn(socket_.get_executor(), [self = shared_from_this()]{ return self->send_heartbeats(); }, detached); } private: void stop() { socket_.close(); write_lock_.cancel(); } awaitable<void> handle_messages() { try { constexpr std::size_t max_line_length = 1024; std::string data; for (;;) { // Read an entire line from the client. std::size_t length = co_await async_read_until(socket_, dynamic_buffer(data, max_line_length), '\n', deferred); // Claim the write lock by sending a message to the channel. Since the // channel signature is void(), there are no arguments to send in the // message itself. co_await write_lock_.async_send(deferred); // Respond to the client with a message, echoing the line they sent. co_await async_write(socket_, "<line>"_buf, deferred); co_await async_write(socket_, dynamic_buffer(data, length), deferred); // Release the lock by receiving the message back again. write_lock_.try_receive([](auto...){}); } } catch (const std::exception&) { stop(); } } awaitable<void> send_heartbeats() { steady_timer timer{socket_.get_executor()}; try { for (;;) { // Wait one second before trying to send the next heartbeat. timer.expires_after(1s); co_await timer.async_wait(deferred); // Claim the write lock by sending a message to the channel. Since the // channel signature is void(), there are no arguments to send in the // message itself. co_await write_lock_.async_send(deferred); // Send a heartbeat to the client. As the content of the heartbeat // message never varies, a buffer literal can be used to specify the // bytes of the message. The memory associated with a buffer literal is // valid for the lifetime of the program, which mean that the buffer // can be safely passed as-is to the asynchronous operation. co_await async_write(socket_, "<heartbeat>\n"_buf, deferred); // Release the lock by receiving the message back again. write_lock_.try_receive([](auto...){}); } } catch (const std::exception&) { stop(); } } }; awaitable<void> listen(tcp::acceptor& acceptor) { for (;;) { auto [e, socket] = co_await acceptor.async_accept(as_tuple(deferred)); if (!e) { std::make_shared<line_based_echo_session>(std::move(socket))->start(); } } } int main(int argc, char* argv[]) { try { if (argc != 3) { std::cerr << "Usage: mutual_exclusion_1"; std::cerr << " <listen_address> <listen_port>\n"; return 1; } io_context ctx; auto listen_endpoint = *tcp::resolver(ctx).resolve(argv[1], argv[2], tcp::resolver::passive).begin(); tcp::acceptor acceptor(ctx, listen_endpoint); co_spawn(ctx, listen(acceptor), detached); ctx.run(); } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; } }
cpp
asio
data/projects/asio/test/placeholders.cpp
// // placeholders.cpp // ~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/placeholders.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "placeholders", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/socket_base.cpp
// // socket_base.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/socket_base.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/ip/udp.hpp> #include "unit_test.hpp" //------------------------------------------------------------------------------ // socket_base_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all nested classes, enums and constants in // socket_base compile and link correctly. Runtime failures are ignored. namespace socket_base_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; ip::tcp::socket sock(ioc); char buf[1024]; // shutdown_type enumeration. sock.shutdown(socket_base::shutdown_receive); sock.shutdown(socket_base::shutdown_send); sock.shutdown(socket_base::shutdown_both); // message_flags constants. sock.receive(buffer(buf), socket_base::message_peek); sock.receive(buffer(buf), socket_base::message_out_of_band); sock.send(buffer(buf), socket_base::message_do_not_route); // broadcast class. socket_base::broadcast broadcast1(true); sock.set_option(broadcast1); socket_base::broadcast broadcast2; sock.get_option(broadcast2); broadcast1 = true; (void)static_cast<bool>(broadcast1); (void)static_cast<bool>(!broadcast1); (void)static_cast<bool>(broadcast1.value()); // debug class. socket_base::debug debug1(true); sock.set_option(debug1); socket_base::debug debug2; sock.get_option(debug2); debug1 = true; (void)static_cast<bool>(debug1); (void)static_cast<bool>(!debug1); (void)static_cast<bool>(debug1.value()); // do_not_route class. socket_base::do_not_route do_not_route1(true); sock.set_option(do_not_route1); socket_base::do_not_route do_not_route2; sock.get_option(do_not_route2); do_not_route1 = true; (void)static_cast<bool>(do_not_route1); (void)static_cast<bool>(!do_not_route1); (void)static_cast<bool>(do_not_route1.value()); // keep_alive class. socket_base::keep_alive keep_alive1(true); sock.set_option(keep_alive1); socket_base::keep_alive keep_alive2; sock.get_option(keep_alive2); keep_alive1 = true; (void)static_cast<bool>(keep_alive1); (void)static_cast<bool>(!keep_alive1); (void)static_cast<bool>(keep_alive1.value()); // send_buffer_size class. socket_base::send_buffer_size send_buffer_size1(1024); sock.set_option(send_buffer_size1); socket_base::send_buffer_size send_buffer_size2; sock.get_option(send_buffer_size2); send_buffer_size1 = 1; (void)static_cast<int>(send_buffer_size1.value()); // send_low_watermark class. socket_base::send_low_watermark send_low_watermark1(128); sock.set_option(send_low_watermark1); socket_base::send_low_watermark send_low_watermark2; sock.get_option(send_low_watermark2); send_low_watermark1 = 1; (void)static_cast<int>(send_low_watermark1.value()); // receive_buffer_size class. socket_base::receive_buffer_size receive_buffer_size1(1024); sock.set_option(receive_buffer_size1); socket_base::receive_buffer_size receive_buffer_size2; sock.get_option(receive_buffer_size2); receive_buffer_size1 = 1; (void)static_cast<int>(receive_buffer_size1.value()); // receive_low_watermark class. socket_base::receive_low_watermark receive_low_watermark1(128); sock.set_option(receive_low_watermark1); socket_base::receive_low_watermark receive_low_watermark2; sock.get_option(receive_low_watermark2); receive_low_watermark1 = 1; (void)static_cast<int>(receive_low_watermark1.value()); // reuse_address class. socket_base::reuse_address reuse_address1(true); sock.set_option(reuse_address1); socket_base::reuse_address reuse_address2; sock.get_option(reuse_address2); reuse_address1 = true; (void)static_cast<bool>(reuse_address1); (void)static_cast<bool>(!reuse_address1); (void)static_cast<bool>(reuse_address1.value()); // linger class. socket_base::linger linger1(true, 30); sock.set_option(linger1); socket_base::linger linger2; sock.get_option(linger2); linger1.enabled(true); (void)static_cast<bool>(linger1.enabled()); linger1.timeout(1); (void)static_cast<int>(linger1.timeout()); // out_of_band_inline class. socket_base::out_of_band_inline out_of_band_inline1(true); sock.set_option(out_of_band_inline1); socket_base::out_of_band_inline out_of_band_inline2; sock.get_option(out_of_band_inline2); out_of_band_inline1 = true; (void)static_cast<bool>(out_of_band_inline1); (void)static_cast<bool>(!out_of_band_inline1); (void)static_cast<bool>(out_of_band_inline1.value()); // enable_connection_aborted class. socket_base::enable_connection_aborted enable_connection_aborted1(true); sock.set_option(enable_connection_aborted1); socket_base::enable_connection_aborted enable_connection_aborted2; sock.get_option(enable_connection_aborted2); enable_connection_aborted1 = true; (void)static_cast<bool>(enable_connection_aborted1); (void)static_cast<bool>(!enable_connection_aborted1); (void)static_cast<bool>(enable_connection_aborted1.value()); // bytes_readable class. socket_base::bytes_readable bytes_readable; sock.io_control(bytes_readable); std::size_t bytes = bytes_readable.get(); (void)bytes; } catch (std::exception&) { } } } // namespace socket_base_compile //------------------------------------------------------------------------------ // socket_base_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks the runtime operation of the socket options and I/O // control commands defined in socket_base. namespace socket_base_runtime { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; io_context ioc; ip::udp::socket udp_sock(ioc, ip::udp::v4()); ip::tcp::socket tcp_sock(ioc, ip::tcp::v4()); ip::tcp::acceptor tcp_acceptor(ioc, ip::tcp::v4()); boost::system::error_code ec; // broadcast class. socket_base::broadcast broadcast1(true); BOOST_ASIO_CHECK(broadcast1.value()); BOOST_ASIO_CHECK(static_cast<bool>(broadcast1)); BOOST_ASIO_CHECK(!!broadcast1); udp_sock.set_option(broadcast1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::broadcast broadcast2; udp_sock.get_option(broadcast2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(broadcast2.value()); BOOST_ASIO_CHECK(static_cast<bool>(broadcast2)); BOOST_ASIO_CHECK(!!broadcast2); socket_base::broadcast broadcast3(false); BOOST_ASIO_CHECK(!broadcast3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(broadcast3)); BOOST_ASIO_CHECK(!broadcast3); udp_sock.set_option(broadcast3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::broadcast broadcast4; udp_sock.get_option(broadcast4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(!broadcast4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(broadcast4)); BOOST_ASIO_CHECK(!broadcast4); // debug class. socket_base::debug debug1(true); BOOST_ASIO_CHECK(debug1.value()); BOOST_ASIO_CHECK(static_cast<bool>(debug1)); BOOST_ASIO_CHECK(!!debug1); udp_sock.set_option(debug1, ec); #if defined(__linux__) // On Linux, only root can set SO_DEBUG. bool not_root = (ec == boost::asio::error::access_denied); BOOST_ASIO_CHECK(!ec || not_root); BOOST_ASIO_WARN_MESSAGE(!ec, "Must be root to set debug socket option"); #else // defined(__linux__) # if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); # else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); # endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) #endif // defined(__linux__) socket_base::debug debug2; udp_sock.get_option(debug2, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); # if defined(__linux__) BOOST_ASIO_CHECK(debug2.value() || not_root); BOOST_ASIO_CHECK(static_cast<bool>(debug2) || not_root); BOOST_ASIO_CHECK(!!debug2 || not_root); # else // defined(__linux__) BOOST_ASIO_CHECK(debug2.value()); BOOST_ASIO_CHECK(static_cast<bool>(debug2)); BOOST_ASIO_CHECK(!!debug2); # endif // defined(__linux__) #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) socket_base::debug debug3(false); BOOST_ASIO_CHECK(!debug3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(debug3)); BOOST_ASIO_CHECK(!debug3); udp_sock.set_option(debug3, ec); #if defined(__linux__) BOOST_ASIO_CHECK(!ec || not_root); #else // defined(__linux__) # if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); # else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); # endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) #endif // defined(__linux__) socket_base::debug debug4; udp_sock.get_option(debug4, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); # if defined(__linux__) BOOST_ASIO_CHECK(!debug4.value() || not_root); BOOST_ASIO_CHECK(!static_cast<bool>(debug4) || not_root); BOOST_ASIO_CHECK(!debug4 || not_root); # else // defined(__linux__) BOOST_ASIO_CHECK(!debug4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(debug4)); BOOST_ASIO_CHECK(!debug4); # endif // defined(__linux__) #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // do_not_route class. socket_base::do_not_route do_not_route1(true); BOOST_ASIO_CHECK(do_not_route1.value()); BOOST_ASIO_CHECK(static_cast<bool>(do_not_route1)); BOOST_ASIO_CHECK(!!do_not_route1); udp_sock.set_option(do_not_route1, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) socket_base::do_not_route do_not_route2; udp_sock.get_option(do_not_route2, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(do_not_route2.value()); BOOST_ASIO_CHECK(static_cast<bool>(do_not_route2)); BOOST_ASIO_CHECK(!!do_not_route2); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) socket_base::do_not_route do_not_route3(false); BOOST_ASIO_CHECK(!do_not_route3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(do_not_route3)); BOOST_ASIO_CHECK(!do_not_route3); udp_sock.set_option(do_not_route3, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) socket_base::do_not_route do_not_route4; udp_sock.get_option(do_not_route4, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(!do_not_route4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(do_not_route4)); BOOST_ASIO_CHECK(!do_not_route4); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // keep_alive class. socket_base::keep_alive keep_alive1(true); BOOST_ASIO_CHECK(keep_alive1.value()); BOOST_ASIO_CHECK(static_cast<bool>(keep_alive1)); BOOST_ASIO_CHECK(!!keep_alive1); tcp_sock.set_option(keep_alive1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::keep_alive keep_alive2; tcp_sock.get_option(keep_alive2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(keep_alive2.value()); BOOST_ASIO_CHECK(static_cast<bool>(keep_alive2)); BOOST_ASIO_CHECK(!!keep_alive2); socket_base::keep_alive keep_alive3(false); BOOST_ASIO_CHECK(!keep_alive3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(keep_alive3)); BOOST_ASIO_CHECK(!keep_alive3); tcp_sock.set_option(keep_alive3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::keep_alive keep_alive4; tcp_sock.get_option(keep_alive4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(!keep_alive4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(keep_alive4)); BOOST_ASIO_CHECK(!keep_alive4); // send_buffer_size class. socket_base::send_buffer_size send_buffer_size1(4096); BOOST_ASIO_CHECK(send_buffer_size1.value() == 4096); tcp_sock.set_option(send_buffer_size1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::send_buffer_size send_buffer_size2; tcp_sock.get_option(send_buffer_size2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(send_buffer_size2.value() == 4096); socket_base::send_buffer_size send_buffer_size3(16384); BOOST_ASIO_CHECK(send_buffer_size3.value() == 16384); tcp_sock.set_option(send_buffer_size3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::send_buffer_size send_buffer_size4; tcp_sock.get_option(send_buffer_size4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(send_buffer_size4.value() == 16384); // send_low_watermark class. socket_base::send_low_watermark send_low_watermark1(4096); BOOST_ASIO_CHECK(send_low_watermark1.value() == 4096); tcp_sock.set_option(send_low_watermark1, ec); #if defined(WIN32) || defined(__linux__) || defined(__sun) BOOST_ASIO_CHECK(!!ec); // Not supported on Windows, Linux or Solaris. #else BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif socket_base::send_low_watermark send_low_watermark2; tcp_sock.get_option(send_low_watermark2, ec); #if defined(WIN32) || defined(__sun) BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris. #elif defined(__linux__) BOOST_ASIO_CHECK(!ec); // Not supported on Linux but can get value. #else BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(send_low_watermark2.value() == 4096); #endif socket_base::send_low_watermark send_low_watermark3(8192); BOOST_ASIO_CHECK(send_low_watermark3.value() == 8192); tcp_sock.set_option(send_low_watermark3, ec); #if defined(WIN32) || defined(__linux__) || defined(__sun) BOOST_ASIO_CHECK(!!ec); // Not supported on Windows, Linux or Solaris. #else BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif socket_base::send_low_watermark send_low_watermark4; tcp_sock.get_option(send_low_watermark4, ec); #if defined(WIN32) || defined(__sun) BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris. #elif defined(__linux__) BOOST_ASIO_CHECK(!ec); // Not supported on Linux but can get value. #else BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(send_low_watermark4.value() == 8192); #endif // receive_buffer_size class. socket_base::receive_buffer_size receive_buffer_size1(4096); BOOST_ASIO_CHECK(receive_buffer_size1.value() == 4096); tcp_sock.set_option(receive_buffer_size1, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) socket_base::receive_buffer_size receive_buffer_size2; tcp_sock.get_option(receive_buffer_size2, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK(!ec); // Not supported under Windows CE but can get value. #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(receive_buffer_size2.value() == 4096); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) socket_base::receive_buffer_size receive_buffer_size3(16384); BOOST_ASIO_CHECK(receive_buffer_size3.value() == 16384); tcp_sock.set_option(receive_buffer_size3, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) socket_base::receive_buffer_size receive_buffer_size4; tcp_sock.get_option(receive_buffer_size4, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK(!ec); // Not supported under Windows CE but can get value. #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(receive_buffer_size4.value() == 16384); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // receive_low_watermark class. socket_base::receive_low_watermark receive_low_watermark1(4096); BOOST_ASIO_CHECK(receive_low_watermark1.value() == 4096); tcp_sock.set_option(receive_low_watermark1, ec); #if defined(WIN32) || defined(__sun) BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris. #else BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif socket_base::receive_low_watermark receive_low_watermark2; tcp_sock.get_option(receive_low_watermark2, ec); #if defined(WIN32) || defined(__sun) BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris. #else BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(receive_low_watermark2.value() == 4096); #endif socket_base::receive_low_watermark receive_low_watermark3(8192); BOOST_ASIO_CHECK(receive_low_watermark3.value() == 8192); tcp_sock.set_option(receive_low_watermark3, ec); #if defined(WIN32) || defined(__sun) BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris. #else BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif socket_base::receive_low_watermark receive_low_watermark4; tcp_sock.get_option(receive_low_watermark4, ec); #if defined(WIN32) || defined(__sun) BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris. #else BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(receive_low_watermark4.value() == 8192); #endif // reuse_address class. socket_base::reuse_address reuse_address1(true); BOOST_ASIO_CHECK(reuse_address1.value()); BOOST_ASIO_CHECK(static_cast<bool>(reuse_address1)); BOOST_ASIO_CHECK(!!reuse_address1); udp_sock.set_option(reuse_address1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::reuse_address reuse_address2; udp_sock.get_option(reuse_address2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(reuse_address2.value()); BOOST_ASIO_CHECK(static_cast<bool>(reuse_address2)); BOOST_ASIO_CHECK(!!reuse_address2); socket_base::reuse_address reuse_address3(false); BOOST_ASIO_CHECK(!reuse_address3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(reuse_address3)); BOOST_ASIO_CHECK(!reuse_address3); udp_sock.set_option(reuse_address3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::reuse_address reuse_address4; udp_sock.get_option(reuse_address4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(!reuse_address4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(reuse_address4)); BOOST_ASIO_CHECK(!reuse_address4); // linger class. socket_base::linger linger1(true, 60); BOOST_ASIO_CHECK(linger1.enabled()); BOOST_ASIO_CHECK(linger1.timeout() == 60); tcp_sock.set_option(linger1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::linger linger2; tcp_sock.get_option(linger2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(linger2.enabled()); BOOST_ASIO_CHECK(linger2.timeout() == 60); socket_base::linger linger3(false, 0); BOOST_ASIO_CHECK(!linger3.enabled()); BOOST_ASIO_CHECK(linger3.timeout() == 0); tcp_sock.set_option(linger3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::linger linger4; tcp_sock.get_option(linger4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(!linger4.enabled()); // enable_connection_aborted class. socket_base::enable_connection_aborted enable_connection_aborted1(true); BOOST_ASIO_CHECK(enable_connection_aborted1.value()); BOOST_ASIO_CHECK(static_cast<bool>(enable_connection_aborted1)); BOOST_ASIO_CHECK(!!enable_connection_aborted1); tcp_acceptor.set_option(enable_connection_aborted1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::enable_connection_aborted enable_connection_aborted2; tcp_acceptor.get_option(enable_connection_aborted2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(enable_connection_aborted2.value()); BOOST_ASIO_CHECK(static_cast<bool>(enable_connection_aborted2)); BOOST_ASIO_CHECK(!!enable_connection_aborted2); socket_base::enable_connection_aborted enable_connection_aborted3(false); BOOST_ASIO_CHECK(!enable_connection_aborted3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(enable_connection_aborted3)); BOOST_ASIO_CHECK(!enable_connection_aborted3); tcp_acceptor.set_option(enable_connection_aborted3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); socket_base::enable_connection_aborted enable_connection_aborted4; tcp_acceptor.get_option(enable_connection_aborted4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(!enable_connection_aborted4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(enable_connection_aborted4)); BOOST_ASIO_CHECK(!enable_connection_aborted4); // bytes_readable class. socket_base::bytes_readable bytes_readable; udp_sock.io_control(bytes_readable, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); } } // namespace socket_base_runtime //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "socket_base", BOOST_ASIO_COMPILE_TEST_CASE(socket_base_compile::test) BOOST_ASIO_TEST_CASE(socket_base_runtime::test) )
cpp
asio
data/projects/asio/test/executor.cpp
// // executor.cpp // ~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/executor.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "executor", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/completion_condition.cpp
// // completion_condition.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/completion_condition.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "completion_condition", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/deferred.cpp
// // deferred.cpp // ~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/deferred.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "experimental/deferred", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/dispatch.cpp
// // dispatch.cpp // ~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/dispatch.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "dispatch", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/file_base.cpp
// // file_base.cpp // ~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/post.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "file_base", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/append.cpp
// // append.cpp // ~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/append.hpp> #include <boost/asio/bind_executor.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/system_timer.hpp> #include "unit_test.hpp" void append_test() { boost::asio::io_context io1; boost::asio::io_context io2; boost::asio::system_timer timer1(io1); int count = 0; timer1.expires_after(boost::asio::chrono::seconds(0)); timer1.async_wait( boost::asio::append( boost::asio::bind_executor(io2.get_executor(), [&count](boost::system::error_code, int a, int b) { ++count; BOOST_ASIO_CHECK(a == 123); BOOST_ASIO_CHECK(b == 321); }), 123, 321)); BOOST_ASIO_CHECK(count == 0); io1.run(); BOOST_ASIO_CHECK(count == 0); io2.run(); BOOST_ASIO_CHECK(count == 1); } BOOST_ASIO_TEST_SUITE ( "append", BOOST_ASIO_TEST_CASE(append_test) )
cpp
asio
data/projects/asio/test/associated_executor.cpp
// // associated_executor.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/associated_executor.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "associated_executor", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/thread_pool.cpp
// // thread_pool.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/thread_pool.hpp> #include <functional> #include <boost/asio/dispatch.hpp> #include <boost/asio/post.hpp> #include "unit_test.hpp" using namespace boost::asio; namespace bindns = std; void increment(int* count) { ++(*count); } void decrement_to_zero(thread_pool* pool, int* count) { if (*count > 0) { --(*count); int before_value = *count; boost::asio::post(*pool, bindns::bind(decrement_to_zero, pool, count)); // Handler execution cannot nest, so count value should remain unchanged. BOOST_ASIO_CHECK(*count == before_value); } } void nested_decrement_to_zero(thread_pool* pool, int* count) { if (*count > 0) { --(*count); boost::asio::dispatch(*pool, bindns::bind(nested_decrement_to_zero, pool, count)); // Handler execution is nested, so count value should now be zero. BOOST_ASIO_CHECK(*count == 0); } } void thread_pool_test() { thread_pool pool(1); int count1 = 0; boost::asio::post(pool, bindns::bind(increment, &count1)); int count2 = 10; boost::asio::post(pool, bindns::bind(decrement_to_zero, &pool, &count2)); int count3 = 10; boost::asio::post(pool, bindns::bind(nested_decrement_to_zero, &pool, &count3)); pool.wait(); BOOST_ASIO_CHECK(count1 == 1); BOOST_ASIO_CHECK(count2 == 0); BOOST_ASIO_CHECK(count3 == 0); } class test_service : public boost::asio::execution_context::service { public: #if defined(BOOST_ASIO_NO_TYPEID) static boost::asio::execution_context::id id; #endif // defined(BOOST_ASIO_NO_TYPEID) typedef test_service key_type; test_service(boost::asio::execution_context& ctx) : boost::asio::execution_context::service(ctx) { } private: virtual void shutdown() {} }; #if defined(BOOST_ASIO_NO_TYPEID) boost::asio::execution_context::id test_service::id; #endif // defined(BOOST_ASIO_NO_TYPEID) void thread_pool_service_test() { boost::asio::thread_pool pool1(1); boost::asio::thread_pool pool2(1); boost::asio::thread_pool pool3(1); // Implicit service registration. boost::asio::use_service<test_service>(pool1); BOOST_ASIO_CHECK(boost::asio::has_service<test_service>(pool1)); test_service* svc1 = new test_service(pool1); try { boost::asio::add_service(pool1, svc1); BOOST_ASIO_ERROR("add_service did not throw"); } catch (boost::asio::service_already_exists&) { } delete svc1; // Explicit service registration. test_service& svc2 = boost::asio::make_service<test_service>(pool2); BOOST_ASIO_CHECK(boost::asio::has_service<test_service>(pool2)); BOOST_ASIO_CHECK(&boost::asio::use_service<test_service>(pool2) == &svc2); test_service* svc3 = new test_service(pool2); try { boost::asio::add_service(pool2, svc3); BOOST_ASIO_ERROR("add_service did not throw"); } catch (boost::asio::service_already_exists&) { } delete svc3; // Explicit registration with invalid owner. test_service* svc4 = new test_service(pool2); try { boost::asio::add_service(pool3, svc4); BOOST_ASIO_ERROR("add_service did not throw"); } catch (boost::asio::invalid_service_owner&) { } delete svc4; BOOST_ASIO_CHECK(!boost::asio::has_service<test_service>(pool3)); } void thread_pool_executor_query_test() { thread_pool pool(1); BOOST_ASIO_CHECK( &boost::asio::query(pool.executor(), boost::asio::execution::context) == &pool); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::blocking) == boost::asio::execution::blocking.possibly); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::blocking.possibly) == boost::asio::execution::blocking.possibly); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::outstanding_work) == boost::asio::execution::outstanding_work.untracked); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::outstanding_work.untracked) == boost::asio::execution::outstanding_work.untracked); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::relationship) == boost::asio::execution::relationship.fork); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::relationship.fork) == boost::asio::execution::relationship.fork); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::mapping) == boost::asio::execution::mapping.thread); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::allocator) == std::allocator<void>()); BOOST_ASIO_CHECK( boost::asio::query(pool.executor(), boost::asio::execution::occupancy) == 1); } void thread_pool_executor_execute_test() { int count = 0; thread_pool pool(1); pool.executor().execute(bindns::bind(increment, &count)); boost::asio::require(pool.executor(), boost::asio::execution::blocking.possibly ).execute(bindns::bind(increment, &count)); boost::asio::require(pool.executor(), boost::asio::execution::blocking.always ).execute(bindns::bind(increment, &count)); boost::asio::require(pool.executor(), boost::asio::execution::blocking.never ).execute(bindns::bind(increment, &count)); boost::asio::require(pool.executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.tracked ).execute(bindns::bind(increment, &count)); boost::asio::require(pool.executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked ).execute(bindns::bind(increment, &count)); boost::asio::require(pool.executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked, boost::asio::execution::relationship.fork ).execute(bindns::bind(increment, &count)); boost::asio::require(pool.executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked, boost::asio::execution::relationship.continuation ).execute(bindns::bind(increment, &count)); boost::asio::prefer( boost::asio::require(pool.executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked, boost::asio::execution::relationship.continuation), boost::asio::execution::allocator(std::allocator<void>()) ).execute(bindns::bind(increment, &count)); boost::asio::prefer( boost::asio::require(pool.executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked, boost::asio::execution::relationship.continuation), boost::asio::execution::allocator ).execute(bindns::bind(increment, &count)); pool.wait(); BOOST_ASIO_CHECK(count == 10); } BOOST_ASIO_TEST_SUITE ( "thread_pool", BOOST_ASIO_TEST_CASE(thread_pool_test) BOOST_ASIO_TEST_CASE(thread_pool_service_test) BOOST_ASIO_TEST_CASE(thread_pool_executor_query_test) BOOST_ASIO_TEST_CASE(thread_pool_executor_execute_test) )
cpp
asio
data/projects/asio/test/buffered_stream.cpp
// // buffered_stream.cpp // ~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/buffered_stream.hpp> #include <cstring> #include <functional> #include "archetypes/async_result.hpp" #include <boost/asio/buffer.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/system/system_error.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <boost/array.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <array> #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) typedef boost::asio::buffered_stream< boost::asio::ip::tcp::socket> stream_type; void write_some_handler(const boost::system::error_code&, std::size_t) { } void flush_handler(const boost::system::error_code&, std::size_t) { } void fill_handler(const boost::system::error_code&, std::size_t) { } void read_some_handler(const boost::system::error_code&, std::size_t) { } void test_compile() { #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) using boost::array; #else // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using std::array; #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using namespace boost::asio; try { io_context ioc; char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; array<boost::asio::mutable_buffer, 2> mutable_buffers = {{ boost::asio::buffer(mutable_char_buffer, 10), boost::asio::buffer(mutable_char_buffer + 10, 10) }}; array<boost::asio::const_buffer, 2> const_buffers = {{ boost::asio::buffer(const_char_buffer, 10), boost::asio::buffer(const_char_buffer + 10, 10) }}; archetypes::lazy_handler lazy; boost::system::error_code ec; stream_type stream1(ioc); stream_type stream2(ioc, 1024, 1024); stream_type::executor_type ex = stream1.get_executor(); (void)ex; stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer(); (void)lowest_layer; stream1.write_some(buffer(mutable_char_buffer)); stream1.write_some(buffer(const_char_buffer)); stream1.write_some(mutable_buffers); stream1.write_some(const_buffers); stream1.write_some(null_buffers()); stream1.write_some(buffer(mutable_char_buffer), ec); stream1.write_some(buffer(const_char_buffer), ec); stream1.write_some(mutable_buffers, ec); stream1.write_some(const_buffers, ec); stream1.write_some(null_buffers(), ec); stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler); stream1.async_write_some(buffer(const_char_buffer), &write_some_handler); stream1.async_write_some(mutable_buffers, &write_some_handler); stream1.async_write_some(const_buffers, &write_some_handler); stream1.async_write_some(null_buffers(), &write_some_handler); int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy); (void)i1; int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy); (void)i2; int i3 = stream1.async_write_some(mutable_buffers, lazy); (void)i3; int i4 = stream1.async_write_some(const_buffers, lazy); (void)i4; int i5 = stream1.async_write_some(null_buffers(), lazy); (void)i5; stream1.flush(); stream1.flush(ec); stream1.async_flush(&flush_handler); int i6 = stream1.async_flush(lazy); (void)i6; stream1.fill(); stream1.fill(ec); stream1.async_fill(&fill_handler); int i7 = stream1.async_fill(lazy); (void)i7; stream1.read_some(buffer(mutable_char_buffer)); stream1.read_some(mutable_buffers); stream1.read_some(null_buffers()); stream1.read_some(buffer(mutable_char_buffer), ec); stream1.read_some(mutable_buffers, ec); stream1.read_some(null_buffers(), ec); stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler); stream1.async_read_some(mutable_buffers, &read_some_handler); stream1.async_read_some(null_buffers(), &read_some_handler); int i8 = stream1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i8; int i9 = stream1.async_read_some(mutable_buffers, lazy); (void)i9; int i10 = stream1.async_read_some(null_buffers(), lazy); (void)i10; } catch (std::exception&) { } } void test_sync_operations() { using namespace std; // For memcmp. boost::asio::io_context io_context; boost::asio::ip::tcp::acceptor acceptor(io_context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0)); boost::asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint(); server_endpoint.address(boost::asio::ip::address_v4::loopback()); stream_type client_socket(io_context); client_socket.lowest_layer().connect(server_endpoint); stream_type server_socket(io_context); acceptor.accept(server_socket.lowest_layer()); const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const boost::asio::const_buffer write_buf = boost::asio::buffer(write_data); std::size_t bytes_written = 0; while (bytes_written < sizeof(write_data)) { bytes_written += client_socket.write_some( boost::asio::buffer(write_buf + bytes_written)); client_socket.flush(); } char read_data[sizeof(write_data)]; const boost::asio::mutable_buffer read_buf = boost::asio::buffer(read_data); std::size_t bytes_read = 0; while (bytes_read < sizeof(read_data)) { bytes_read += server_socket.read_some( boost::asio::buffer(read_buf + bytes_read)); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); bytes_written = 0; while (bytes_written < sizeof(write_data)) { bytes_written += server_socket.write_some( boost::asio::buffer(write_buf + bytes_written)); server_socket.flush(); } bytes_read = 0; while (bytes_read < sizeof(read_data)) { bytes_read += client_socket.read_some( boost::asio::buffer(read_buf + bytes_read)); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); server_socket.close(); boost::system::error_code error; bytes_read = client_socket.read_some( boost::asio::buffer(read_buf), error); BOOST_ASIO_CHECK(bytes_read == 0); BOOST_ASIO_CHECK(error == boost::asio::error::eof); client_socket.close(error); } void handle_accept(const boost::system::error_code& e) { BOOST_ASIO_CHECK(!e); } void handle_write(const boost::system::error_code& e, std::size_t bytes_transferred, std::size_t* total_bytes_written) { BOOST_ASIO_CHECK(!e); if (e) throw boost::system::system_error(e); // Terminate test. *total_bytes_written += bytes_transferred; } void handle_flush(const boost::system::error_code& e) { BOOST_ASIO_CHECK(!e); } void handle_read(const boost::system::error_code& e, std::size_t bytes_transferred, std::size_t* total_bytes_read) { BOOST_ASIO_CHECK(!e); if (e) throw boost::system::system_error(e); // Terminate test. *total_bytes_read += bytes_transferred; } void handle_read_eof(const boost::system::error_code& e, std::size_t bytes_transferred) { BOOST_ASIO_CHECK(e == boost::asio::error::eof); BOOST_ASIO_CHECK(bytes_transferred == 0); } void test_async_operations() { using namespace std; // For memcmp. namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context io_context; boost::asio::ip::tcp::acceptor acceptor(io_context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0)); boost::asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint(); server_endpoint.address(boost::asio::ip::address_v4::loopback()); stream_type client_socket(io_context); client_socket.lowest_layer().connect(server_endpoint); stream_type server_socket(io_context); acceptor.async_accept(server_socket.lowest_layer(), &handle_accept); io_context.run(); io_context.restart(); const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const boost::asio::const_buffer write_buf = boost::asio::buffer(write_data); std::size_t bytes_written = 0; while (bytes_written < sizeof(write_data)) { client_socket.async_write_some( boost::asio::buffer(write_buf + bytes_written), bindns::bind(handle_write, _1, _2, &bytes_written)); io_context.run(); io_context.restart(); client_socket.async_flush( bindns::bind(handle_flush, _1)); io_context.run(); io_context.restart(); } char read_data[sizeof(write_data)]; const boost::asio::mutable_buffer read_buf = boost::asio::buffer(read_data); std::size_t bytes_read = 0; while (bytes_read < sizeof(read_data)) { server_socket.async_read_some( boost::asio::buffer(read_buf + bytes_read), bindns::bind(handle_read, _1, _2, &bytes_read)); io_context.run(); io_context.restart(); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); bytes_written = 0; while (bytes_written < sizeof(write_data)) { server_socket.async_write_some( boost::asio::buffer(write_buf + bytes_written), bindns::bind(handle_write, _1, _2, &bytes_written)); io_context.run(); io_context.restart(); server_socket.async_flush( bindns::bind(handle_flush, _1)); io_context.run(); io_context.restart(); } bytes_read = 0; while (bytes_read < sizeof(read_data)) { client_socket.async_read_some( boost::asio::buffer(read_buf + bytes_read), bindns::bind(handle_read, _1, _2, &bytes_read)); io_context.run(); io_context.restart(); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); server_socket.close(); client_socket.async_read_some(boost::asio::buffer(read_buf), handle_read_eof); } BOOST_ASIO_TEST_SUITE ( "buffered_stream", BOOST_ASIO_COMPILE_TEST_CASE(test_compile) BOOST_ASIO_TEST_CASE(test_sync_operations) BOOST_ASIO_TEST_CASE(test_async_operations) )
cpp
asio
data/projects/asio/test/basic_serial_port.cpp
// // basic_serial_port.cpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. ([email protected]) // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_serial_port.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_serial_port", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/compose.cpp
// // compose.cpp // ~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/compose.hpp> #include <functional> #include <boost/asio/bind_cancellation_slot.hpp> #include <boost/asio/cancellation_signal.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/system_timer.hpp> #include "unit_test.hpp" //------------------------------------------------------------------------------ class impl_0_completion_args { public: explicit impl_0_completion_args(boost::asio::io_context& ioc) : ioc_(ioc), state_(starting) { } template <typename Self> void operator()(Self& self) { switch (state_) { case starting: state_ = posting; boost::asio::post(ioc_, static_cast<Self&&>(self)); break; case posting: self.complete(); break; default: break; } } private: boost::asio::io_context& ioc_; enum { starting, posting } state_; }; template <typename CompletionToken> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) async_0_completion_args(boost::asio::io_context& ioc, CompletionToken&& token) { return boost::asio::async_compose<CompletionToken, void()>( impl_0_completion_args(ioc), token); } void compose_0_args_handler(int* count) { ++(*count); } struct compose_0_args_lvalue_handler { int* count_; void operator()() { ++(*count_); } }; void compose_0_completion_args_test() { namespace bindns = std; boost::asio::io_context ioc; int count = 0; async_0_completion_args(ioc, bindns::bind(&compose_0_args_handler, &count)); // No handlers can be called until run() is called. BOOST_ASIO_CHECK(!ioc.stopped()); BOOST_ASIO_CHECK(count == 0); ioc.run(); // The run() call will not return until all work has finished. BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); ioc.restart(); count = 0; compose_0_args_lvalue_handler lvalue_handler = { &count }; async_0_completion_args(ioc, lvalue_handler); // No handlers can be called until run() is called. BOOST_ASIO_CHECK(!ioc.stopped()); BOOST_ASIO_CHECK(count == 0); ioc.run(); // The run() call will not return until all work has finished. BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); } //------------------------------------------------------------------------------ class impl_1_completion_arg { public: explicit impl_1_completion_arg(boost::asio::io_context& ioc) : ioc_(ioc), state_(starting) { } template <typename Self> void operator()(Self& self) { switch (state_) { case starting: state_ = posting; boost::asio::post(ioc_, static_cast<Self&&>(self)); break; case posting: self.complete(42); break; default: break; } } private: boost::asio::io_context& ioc_; enum { starting, posting } state_; }; template <typename CompletionToken> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int)) async_1_completion_arg(boost::asio::io_context& ioc, CompletionToken&& token) { return boost::asio::async_compose<CompletionToken, void(int)>( impl_1_completion_arg(ioc), token); } void compose_1_arg_handler(int* count, int* result_out, int result) { ++(*count); *result_out = result; } struct compose_1_arg_lvalue_handler { int* count_; int* result_out_; void operator()(int result) { ++(*count_); *result_out_ = result; } }; void compose_1_completion_arg_test() { namespace bindns = std; using bindns::placeholders::_1; boost::asio::io_context ioc; int count = 0; int result = 0; async_1_completion_arg(ioc, bindns::bind(&compose_1_arg_handler, &count, &result, _1)); // No handlers can be called until run() is called. BOOST_ASIO_CHECK(!ioc.stopped()); BOOST_ASIO_CHECK(count == 0); BOOST_ASIO_CHECK(result == 0); ioc.run(); // The run() call will not return until all work has finished. BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == 42); ioc.restart(); count = 0; result = 0; compose_1_arg_lvalue_handler lvalue_handler = { &count, &result }; async_1_completion_arg(ioc, lvalue_handler); // No handlers can be called until run() is called. BOOST_ASIO_CHECK(!ioc.stopped()); BOOST_ASIO_CHECK(count == 0); BOOST_ASIO_CHECK(result == 0); ioc.run(); // The run() call will not return until all work has finished. BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == 42); } //------------------------------------------------------------------------------ typedef boost::asio::enable_terminal_cancellation default_filter; template <typename CancellationFilter> class impl_cancellable { public: explicit impl_cancellable(CancellationFilter cancellation_filter, boost::asio::system_timer& timer) : cancellation_filter_(cancellation_filter), timer_(timer), state_(starting) { } template <typename Self> void operator()(Self& self, const boost::system::error_code& ec = boost::system::error_code()) { switch (state_) { case starting: if (!boost::asio::is_same<CancellationFilter, default_filter>::value) self.reset_cancellation_state(cancellation_filter_); state_ = waiting; timer_.expires_after(boost::asio::chrono::milliseconds(100)); timer_.async_wait(static_cast<Self&&>(self)); break; case waiting: self.complete(!ec); break; default: break; } } private: CancellationFilter cancellation_filter_; boost::asio::system_timer& timer_; enum { starting, waiting } state_; }; template <typename CancellationFilter, typename CompletionToken> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(bool)) async_cancellable(CancellationFilter cancellation_filter, boost::asio::system_timer& timer, CompletionToken&& token) { return boost::asio::async_compose<CompletionToken, void(bool)>( impl_cancellable<CancellationFilter>(cancellation_filter, timer), token); } void compose_partial_cancellation_handler( int* count, bool* result_out, bool result) { ++(*count); *result_out = result; } void compose_default_cancellation_test() { namespace bindns = std; using bindns::placeholders::_1; boost::asio::io_context ioc; boost::asio::system_timer timer(ioc); boost::asio::cancellation_signal signal; int count = 0; bool result = false; async_cancellable(default_filter(), timer, bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1)); ioc.run(); // No cancellation, operation completes successfully. BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == true); ioc.restart(); count = 0; result = 0; async_cancellable(default_filter(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Total cancellation unsupported. Operation completes successfully. signal.emit(boost::asio::cancellation_type::total); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == true); ioc.restart(); count = 0; result = 0; async_cancellable(default_filter(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Partial cancellation unsupported. Operation completes successfully. signal.emit(boost::asio::cancellation_type::partial); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == true); ioc.restart(); count = 0; result = 0; async_cancellable(default_filter(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Terminal cancellation works. Operation completes with failure. signal.emit(boost::asio::cancellation_type::terminal); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == false); } void compose_partial_cancellation_test() { namespace bindns = std; using bindns::placeholders::_1; boost::asio::io_context ioc; boost::asio::system_timer timer(ioc); boost::asio::cancellation_signal signal; int count = 0; bool result = false; async_cancellable(boost::asio::enable_partial_cancellation(), timer, bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1)); ioc.run(); // No cancellation, operation completes successfully. BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == true); ioc.restart(); count = 0; result = 0; async_cancellable(boost::asio::enable_partial_cancellation(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Total cancellation unsupported. Operation completes successfully. signal.emit(boost::asio::cancellation_type::total); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == true); ioc.restart(); count = 0; result = 0; async_cancellable(boost::asio::enable_partial_cancellation(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Partial cancellation works. Operation completes with failure. signal.emit(boost::asio::cancellation_type::partial); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == false); ioc.restart(); count = 0; result = 0; async_cancellable(boost::asio::enable_partial_cancellation(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Terminal cancellation works. Operation completes with failure. signal.emit(boost::asio::cancellation_type::terminal); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == false); } void compose_total_cancellation_test() { namespace bindns = std; using bindns::placeholders::_1; boost::asio::io_context ioc; boost::asio::system_timer timer(ioc); boost::asio::cancellation_signal signal; int count = 0; bool result = false; async_cancellable(boost::asio::enable_total_cancellation(), timer, bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1)); ioc.run(); // No cancellation, operation completes successfully. BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == true); ioc.restart(); count = 0; result = 0; async_cancellable(boost::asio::enable_total_cancellation(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Total cancellation works. Operation completes with failure. signal.emit(boost::asio::cancellation_type::total); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == false); ioc.restart(); count = 0; result = 0; async_cancellable(boost::asio::enable_total_cancellation(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Partial cancellation works. Operation completes with failure. signal.emit(boost::asio::cancellation_type::partial); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == false); ioc.restart(); count = 0; result = 0; async_cancellable(boost::asio::enable_total_cancellation(), timer, boost::asio::bind_cancellation_slot(signal.slot(), bindns::bind(&compose_partial_cancellation_handler, &count, &result, _1))); // Terminal cancellation works. Operation completes with failure. signal.emit(boost::asio::cancellation_type::terminal); ioc.run(); BOOST_ASIO_CHECK(ioc.stopped()); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(result == false); } //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "compose", BOOST_ASIO_TEST_CASE(compose_0_completion_args_test) BOOST_ASIO_TEST_CASE(compose_1_completion_arg_test) BOOST_ASIO_TEST_CASE(compose_default_cancellation_test) BOOST_ASIO_TEST_CASE(compose_partial_cancellation_test) BOOST_ASIO_TEST_CASE(compose_total_cancellation_test) )
cpp
asio
data/projects/asio/test/registered_buffer.cpp
// // registered_buffer.cpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/registered_buffer.hpp> #include "unit_test.hpp" //------------------------------------------------------------------------------ // registered_buffer_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all the mutable_registered_buffer and // const_registered_buffer classes compile and link correctly. Runtime // failures are ignored. namespace registered_buffer_compile { using namespace boost::asio; void test() { try { // mutable_registered_buffer constructors. mutable_registered_buffer mb1; mutable_registered_buffer mb2(mb1); (void)mb2; // mutable_registered_buffer functions. mutable_buffer b1 = mb1.buffer(); (void)b1; void* ptr1 = mb1.data(); (void)ptr1; std::size_t n1 = mb1.size(); (void)n1; registered_buffer_id id1 = mb1.id(); (void)id1; // mutable_registered_buffer operators. mb1 += 128; mb1 = mb2 + 128; mb1 = 128 + mb2; // const_registered_buffer constructors. const_registered_buffer cb1; const_registered_buffer cb2(cb1); (void)cb2; const_registered_buffer cb3(mb1); (void)cb3; // const_registered_buffer functions. const_buffer b2 = cb1.buffer(); (void)b2; const void* ptr2 = cb1.data(); (void)ptr2; std::size_t n2 = cb1.size(); (void)n2; registered_buffer_id id2 = cb1.id(); (void)id2; // const_registered_buffer operators. cb1 += 128; cb1 = cb2 + 128; cb1 = 128 + cb2; // buffer function overloads. mb1 = buffer(mb2); mb1 = buffer(mb2, 128); cb1 = buffer(cb2); cb1 = buffer(cb2, 128); } catch (std::exception&) { } } } // namespace buffer_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "registered_buffer", BOOST_ASIO_COMPILE_TEST_CASE(registered_buffer_compile::test) )
cpp
asio
data/projects/asio/test/recycling_allocator.cpp
// // recycling_allocator.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/recycling_allocator.hpp> #include "unit_test.hpp" #include <vector> #include <boost/asio/detail/type_traits.hpp> void recycling_allocator_test() { BOOST_ASIO_CHECK(( boost::asio::is_same< boost::asio::recycling_allocator<int>::value_type, int >::value)); BOOST_ASIO_CHECK(( boost::asio::is_same< boost::asio::recycling_allocator<void>::value_type, void >::value)); BOOST_ASIO_CHECK(( boost::asio::is_same< boost::asio::recycling_allocator<int>::rebind<char>::other, boost::asio::recycling_allocator<char> >::value)); BOOST_ASIO_CHECK(( boost::asio::is_same< boost::asio::recycling_allocator<void>::rebind<char>::other, boost::asio::recycling_allocator<char> >::value)); boost::asio::recycling_allocator<int> a1; boost::asio::recycling_allocator<int> a2(a1); BOOST_ASIO_CHECK(a1 == a2); BOOST_ASIO_CHECK(!(a1 != a2)); boost::asio::recycling_allocator<void> a3; boost::asio::recycling_allocator<void> a4(a3); BOOST_ASIO_CHECK(a3 == a4); BOOST_ASIO_CHECK(!(a3 != a4)); boost::asio::recycling_allocator<int> a5(a4); (void)a5; boost::asio::recycling_allocator<void> a6(a5); (void)a6; int* p = a1.allocate(42); BOOST_ASIO_CHECK(p != 0); a1.deallocate(p, 42); std::vector<int, boost::asio::recycling_allocator<int> > v(42); BOOST_ASIO_CHECK(v.size() == 42); } BOOST_ASIO_TEST_SUITE ( "recycling_allocator", BOOST_ASIO_TEST_CASE(recycling_allocator_test) )
cpp
asio
data/projects/asio/test/signal_set.cpp
// // signal_set.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/signal_set.hpp> #include "archetypes/async_result.hpp" #include <boost/asio/io_context.hpp> #include "unit_test.hpp" //------------------------------------------------------------------------------ // signal_set_compile test // ~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // signal_set compile and link correctly. Runtime failures are ignored. namespace signal_set_compile { void signal_handler(const boost::system::error_code&, int) { } void test() { using namespace boost::asio; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); archetypes::lazy_handler lazy; boost::system::error_code ec; // basic_signal_set constructors. signal_set set1(ioc); signal_set set2(ioc, 1); signal_set set3(ioc, 1, 2); signal_set set4(ioc, 1, 2, 3); signal_set set5(ioc_ex); signal_set set6(ioc_ex, 1); signal_set set7(ioc_ex, 1, 2); signal_set set8(ioc_ex, 1, 2, 3); // basic_io_object functions. signal_set::executor_type ex = set1.get_executor(); (void)ex; // basic_signal_set functions. set1.add(1); set1.add(1, ec); set1.add(1, signal_set::flags::dont_care); set1.add(1, signal_set::flags::dont_care, ec); set1.remove(1); set1.remove(1, ec); set1.clear(); set1.clear(ec); set1.cancel(); set1.cancel(ec); set1.async_wait(&signal_handler); int i = set1.async_wait(lazy); (void)i; } catch (std::exception&) { } } } // namespace signal_set_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "signal_set", BOOST_ASIO_COMPILE_TEST_CASE(signal_set_compile::test) )
cpp
asio
data/projects/asio/test/serial_port_base.cpp
// // serial_port_base.cpp // ~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. ([email protected]) // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/serial_port_base.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/serial_port.hpp> #include "unit_test.hpp" //------------------------------------------------------------------------------ // serial_port_base_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Verify that all options and and their accessors compile. Runtime failures are // ignored. namespace serial_port_base_compile { void test() { #if defined(BOOST_ASIO_HAS_SERIAL_PORT) using namespace boost::asio; try { io_context ioc; serial_port port(ioc); // baud_rate class. serial_port_base::baud_rate baud_rate1(9600); port.set_option(baud_rate1); serial_port_base::baud_rate baud_rate2; port.get_option(baud_rate2); (void)static_cast<unsigned int>(baud_rate2.value()); // flow_control class. serial_port_base::flow_control flow_control1( serial_port_base::flow_control::none); port.set_option(flow_control1); serial_port_base::flow_control flow_control2; port.get_option(flow_control2); (void)static_cast<serial_port_base::flow_control::type>( flow_control2.value()); // parity class. serial_port_base::parity parity1(serial_port_base::parity::none); port.set_option(parity1); serial_port_base::parity parity2; port.get_option(parity2); (void)static_cast<serial_port_base::parity::type>(parity2.value()); // stop_bits class. serial_port_base::stop_bits stop_bits1(serial_port_base::stop_bits::one); port.set_option(stop_bits1); serial_port_base::stop_bits stop_bits2; port.get_option(stop_bits2); (void)static_cast<serial_port_base::stop_bits::type>(stop_bits2.value()); // character_size class. serial_port_base::character_size character_size1(8); port.set_option(character_size1); serial_port_base::character_size character_size2; port.get_option(character_size2); (void)static_cast<unsigned int>(character_size2.value()); } catch (std::exception&) { } #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT) } } // namespace serial_port_base_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "serial_port_base", BOOST_ASIO_COMPILE_TEST_CASE(serial_port_base_compile::test) )
cpp
asio
data/projects/asio/test/cancellation_state.cpp
// // cancellation_state.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/cancellation_state.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "cancellation_state", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/co_spawn.cpp
// // co_spawn.cpp // ~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/co_spawn.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_CO_AWAIT) #include <boost/asio/any_completion_handler.hpp> #include <boost/asio/io_context.hpp> boost::asio::awaitable<void> void_returning_coroutine() { co_return; } boost::asio::awaitable<int> int_returning_coroutine() { co_return 42; } void test_co_spawn_with_any_completion_handler() { boost::asio::io_context ctx; bool called = false; boost::asio::co_spawn(ctx, void_returning_coroutine(), boost::asio::any_completion_handler<void(std::exception_ptr)>( [&](std::exception_ptr) { called = true; })); BOOST_ASIO_CHECK(!called); ctx.run(); BOOST_ASIO_CHECK(called); int result = 0; boost::asio::co_spawn(ctx, int_returning_coroutine(), boost::asio::any_completion_handler<void(std::exception_ptr, int)>( [&](std::exception_ptr, int i) { result = i; })); BOOST_ASIO_CHECK(result == 0); ctx.restart(); ctx.run(); BOOST_ASIO_CHECK(result == 42); } BOOST_ASIO_TEST_SUITE ( "co_spawn", BOOST_ASIO_TEST_CASE(test_co_spawn_with_any_completion_handler) ) #else // defined(BOOST_ASIO_HAS_CO_AWAIT) BOOST_ASIO_TEST_SUITE ( "co_spawn", BOOST_ASIO_TEST_CASE(null_test) ) #endif // defined(BOOST_ASIO_HAS_CO_AWAIT)
cpp
asio
data/projects/asio/test/as_tuple.cpp
// // as_tuple.cpp // ~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/as_tuple.hpp> #include <boost/asio/bind_executor.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/system_timer.hpp> #include <boost/asio/use_future.hpp> #include "unit_test.hpp" void as_tuple_test() { boost::asio::io_context io1; boost::asio::io_context io2; boost::asio::system_timer timer1(io1); int count = 0; timer1.expires_after(boost::asio::chrono::seconds(0)); timer1.async_wait( boost::asio::as_tuple( boost::asio::bind_executor(io2.get_executor(), [&count](std::tuple<boost::system::error_code>) { ++count; }))); BOOST_ASIO_CHECK(count == 0); io1.run(); BOOST_ASIO_CHECK(count == 0); io2.run(); BOOST_ASIO_CHECK(count == 1); timer1.async_wait( boost::asio::as_tuple( boost::asio::bind_executor(io2.get_executor(), boost::asio::deferred)))( [&count](std::tuple<boost::system::error_code>) { ++count; }); BOOST_ASIO_CHECK(count == 1); io1.restart(); io1.run(); BOOST_ASIO_CHECK(count == 1); io2.restart(); io2.run(); BOOST_ASIO_CHECK(count == 2); # if defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) std::future<std::tuple<boost::system::error_code> > f = timer1.async_wait( boost::asio::as_tuple( boost::asio::bind_executor(io2.get_executor(), boost::asio::use_future))); BOOST_ASIO_CHECK(f.wait_for(std::chrono::seconds(0)) == std::future_status::timeout); io1.restart(); io1.run(); BOOST_ASIO_CHECK(f.wait_for(std::chrono::seconds(0)) == std::future_status::timeout); io2.restart(); io2.run(); BOOST_ASIO_CHECK(f.wait_for(std::chrono::seconds(0)) == std::future_status::ready); # endif // defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) } void as_tuple_constness_test() { # if defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) boost::asio::io_context io1; boost::asio::system_timer timer1(io1); auto tok1 = boost::asio::as_tuple(boost::asio::use_future); (void)timer1.async_wait(tok1); (void)timer1.async_wait(std::move(tok1)); const auto tok2 = boost::asio::as_tuple(boost::asio::use_future); (void)timer1.async_wait(tok2); (void)timer1.async_wait(std::move(tok2)); constexpr auto tok3 = boost::asio::as_tuple(boost::asio::use_future); (void)timer1.async_wait(tok3); (void)timer1.async_wait(std::move(tok3)); # endif // defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) } BOOST_ASIO_TEST_SUITE ( "as_tuple", BOOST_ASIO_TEST_CASE(as_tuple_test) BOOST_ASIO_COMPILE_TEST_CASE(as_tuple_constness_test) )
cpp
asio
data/projects/asio/test/use_awaitable.cpp
// // use_awaitable.cpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/use_awaitable.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "use_awaitable", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/bind_immediate_executor.cpp
// // bind_immediate_executor.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/bind_immediate_executor.hpp> #include <functional> #include <boost/asio/dispatch.hpp> #include <boost/asio/io_context.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) # include <boost/asio/deadline_timer.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) # include <boost/asio/steady_timer.hpp> #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) using namespace boost::asio; namespace bindns = std; struct initiate_immediate { template <typename Handler> void operator()(Handler&& handler, io_context* ctx) const { typename associated_immediate_executor< Handler, io_context::executor_type>::type ex = get_associated_immediate_executor(handler, ctx->get_executor()); dispatch(ex, static_cast<Handler&&>(handler)); } }; template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) Token> BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_PREFIX(Token, void()) async_immediate(io_context& ctx, Token&& token) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE_SUFFIX(( async_initiate<Token, void()>(declval<initiate_immediate>(), token))) { return async_initiate<Token, void()>(initiate_immediate(), token, &ctx); } void increment(int* count) { ++(*count); } void bind_immediate_executor_to_function_object_test() { io_context ioc1; io_context ioc2; int count = 0; async_immediate(ioc1, bind_immediate_executor( ioc2.get_executor(), bindns::bind(&increment, &count))); ioc1.run(); BOOST_ASIO_CHECK(count == 0); ioc2.run(); BOOST_ASIO_CHECK(count == 1); async_immediate(ioc1, bind_immediate_executor( ioc2.get_executor(), bind_immediate_executor( boost::asio::system_executor(), bindns::bind(&increment, &count)))); ioc1.restart(); ioc1.run(); BOOST_ASIO_CHECK(count == 1); ioc2.restart(); ioc2.run(); BOOST_ASIO_CHECK(count == 2); } struct incrementer_token_v1 { explicit incrementer_token_v1(int* c) : count(c) {} int* count; }; struct incrementer_handler_v1 { explicit incrementer_handler_v1(incrementer_token_v1 t) : count(t.count) {} void operator()(){ increment(count); } int* count; }; namespace boost { namespace asio { template <> class async_result<incrementer_token_v1, void()> { public: typedef incrementer_handler_v1 completion_handler_type; typedef void return_type; explicit async_result(completion_handler_type&) {} return_type get() {} }; } // namespace asio } // namespace boost void bind_immediate_executor_to_completion_token_v1_test() { io_context ioc1; io_context ioc2; int count = 0; async_immediate(ioc1, bind_immediate_executor( ioc2.get_executor(), incrementer_token_v1(&count))); ioc1.run(); BOOST_ASIO_CHECK(count == 0); ioc2.run(); BOOST_ASIO_CHECK(count == 1); } struct incrementer_token_v2 { explicit incrementer_token_v2(int* c) : count(c) {} int* count; }; namespace boost { namespace asio { template <> class async_result<incrementer_token_v2, void()> { public: #if !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION) typedef void return_type; #endif // !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION) template <typename Initiation, typename... Args> static void initiate(Initiation initiation, incrementer_token_v2 token, Args&&... args) { initiation(bindns::bind(&increment, token.count), static_cast<Args&&>(args)...); } }; } // namespace asio } // namespace boost void bind_immediate_executor_to_completion_token_v2_test() { io_context ioc1; io_context ioc2; int count = 0; async_immediate(ioc1, bind_immediate_executor( ioc2.get_executor(), incrementer_token_v2(&count))); ioc1.run(); BOOST_ASIO_CHECK(count == 0); ioc2.run(); BOOST_ASIO_CHECK(count == 1); } BOOST_ASIO_TEST_SUITE ( "bind_immediate_executor", BOOST_ASIO_TEST_CASE(bind_immediate_executor_to_function_object_test) BOOST_ASIO_TEST_CASE(bind_immediate_executor_to_completion_token_v1_test) BOOST_ASIO_TEST_CASE(bind_immediate_executor_to_completion_token_v2_test) )
cpp
asio
data/projects/asio/test/buffered_write_stream.cpp
// // buffered_write_stream.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/buffered_write_stream.hpp> #include <cstring> #include <functional> #include "archetypes/async_result.hpp" #include <boost/asio/buffer.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/system/system_error.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <boost/array.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <array> #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) typedef boost::asio::buffered_write_stream< boost::asio::ip::tcp::socket> stream_type; void write_some_handler(const boost::system::error_code&, std::size_t) { } void flush_handler(const boost::system::error_code&, std::size_t) { } void read_some_handler(const boost::system::error_code&, std::size_t) { } void test_compile() { #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) using boost::array; #else // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using std::array; #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using namespace boost::asio; try { io_context ioc; char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; array<boost::asio::mutable_buffer, 2> mutable_buffers = {{ boost::asio::buffer(mutable_char_buffer, 10), boost::asio::buffer(mutable_char_buffer + 10, 10) }}; array<boost::asio::const_buffer, 2> const_buffers = {{ boost::asio::buffer(const_char_buffer, 10), boost::asio::buffer(const_char_buffer + 10, 10) }}; archetypes::lazy_handler lazy; boost::system::error_code ec; stream_type stream1(ioc); stream_type stream2(ioc, 1024); stream_type::executor_type ex = stream1.get_executor(); (void)ex; stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer(); (void)lowest_layer; stream1.write_some(buffer(mutable_char_buffer)); stream1.write_some(buffer(const_char_buffer)); stream1.write_some(mutable_buffers); stream1.write_some(const_buffers); stream1.write_some(null_buffers()); stream1.write_some(buffer(mutable_char_buffer), ec); stream1.write_some(buffer(const_char_buffer), ec); stream1.write_some(mutable_buffers, ec); stream1.write_some(const_buffers, ec); stream1.write_some(null_buffers(), ec); stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler); stream1.async_write_some(buffer(const_char_buffer), &write_some_handler); stream1.async_write_some(mutable_buffers, &write_some_handler); stream1.async_write_some(const_buffers, &write_some_handler); stream1.async_write_some(null_buffers(), &write_some_handler); int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy); (void)i1; int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy); (void)i2; int i3 = stream1.async_write_some(mutable_buffers, lazy); (void)i3; int i4 = stream1.async_write_some(const_buffers, lazy); (void)i4; int i5 = stream1.async_write_some(null_buffers(), lazy); (void)i5; stream1.flush(); stream1.flush(ec); stream1.async_flush(&flush_handler); int i6 = stream1.async_flush(lazy); (void)i6; stream1.read_some(buffer(mutable_char_buffer)); stream1.read_some(mutable_buffers); stream1.read_some(null_buffers()); stream1.read_some(buffer(mutable_char_buffer), ec); stream1.read_some(mutable_buffers, ec); stream1.read_some(null_buffers(), ec); stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler); stream1.async_read_some(mutable_buffers, &read_some_handler); stream1.async_read_some(null_buffers(), &read_some_handler); int i7 = stream1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i7; int i8 = stream1.async_read_some(mutable_buffers, lazy); (void)i8; int i9 = stream1.async_read_some(null_buffers(), lazy); (void)i9; } catch (std::exception&) { } } void test_sync_operations() { using namespace std; // For memcmp. boost::asio::io_context io_context; boost::asio::ip::tcp::acceptor acceptor(io_context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0)); boost::asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint(); server_endpoint.address(boost::asio::ip::address_v4::loopback()); stream_type client_socket(io_context); client_socket.lowest_layer().connect(server_endpoint); stream_type server_socket(io_context); acceptor.accept(server_socket.lowest_layer()); const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const boost::asio::const_buffer write_buf = boost::asio::buffer(write_data); std::size_t bytes_written = 0; while (bytes_written < sizeof(write_data)) { bytes_written += client_socket.write_some( boost::asio::buffer(write_buf + bytes_written)); client_socket.flush(); } char read_data[sizeof(write_data)]; const boost::asio::mutable_buffer read_buf = boost::asio::buffer(read_data); std::size_t bytes_read = 0; while (bytes_read < sizeof(read_data)) { bytes_read += server_socket.read_some( boost::asio::buffer(read_buf + bytes_read)); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); bytes_written = 0; while (bytes_written < sizeof(write_data)) { bytes_written += server_socket.write_some( boost::asio::buffer(write_buf + bytes_written)); server_socket.flush(); } bytes_read = 0; while (bytes_read < sizeof(read_data)) { bytes_read += client_socket.read_some( boost::asio::buffer(read_buf + bytes_read)); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); server_socket.close(); boost::system::error_code error; bytes_read = client_socket.read_some( boost::asio::buffer(read_buf), error); BOOST_ASIO_CHECK(bytes_read == 0); BOOST_ASIO_CHECK(error == boost::asio::error::eof); client_socket.close(error); } void handle_accept(const boost::system::error_code& e) { BOOST_ASIO_CHECK(!e); } void handle_write(const boost::system::error_code& e, std::size_t bytes_transferred, std::size_t* total_bytes_written) { BOOST_ASIO_CHECK(!e); if (e) throw boost::system::system_error(e); // Terminate test. *total_bytes_written += bytes_transferred; } void handle_flush(const boost::system::error_code& e) { BOOST_ASIO_CHECK(!e); } void handle_read(const boost::system::error_code& e, std::size_t bytes_transferred, std::size_t* total_bytes_read) { BOOST_ASIO_CHECK(!e); if (e) throw boost::system::system_error(e); // Terminate test. *total_bytes_read += bytes_transferred; } void handle_read_eof(const boost::system::error_code& e, std::size_t bytes_transferred) { BOOST_ASIO_CHECK(e == boost::asio::error::eof); BOOST_ASIO_CHECK(bytes_transferred == 0); } void test_async_operations() { using namespace std; // For memcmp. namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context io_context; boost::asio::ip::tcp::acceptor acceptor(io_context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0)); boost::asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint(); server_endpoint.address(boost::asio::ip::address_v4::loopback()); stream_type client_socket(io_context); client_socket.lowest_layer().connect(server_endpoint); stream_type server_socket(io_context); acceptor.async_accept(server_socket.lowest_layer(), &handle_accept); io_context.run(); io_context.restart(); const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const boost::asio::const_buffer write_buf = boost::asio::buffer(write_data); std::size_t bytes_written = 0; while (bytes_written < sizeof(write_data)) { client_socket.async_write_some( boost::asio::buffer(write_buf + bytes_written), bindns::bind(handle_write, _1, _2, &bytes_written)); io_context.run(); io_context.restart(); client_socket.async_flush( bindns::bind(handle_flush, _1)); io_context.run(); io_context.restart(); } char read_data[sizeof(write_data)]; const boost::asio::mutable_buffer read_buf = boost::asio::buffer(read_data); std::size_t bytes_read = 0; while (bytes_read < sizeof(read_data)) { server_socket.async_read_some( boost::asio::buffer(read_buf + bytes_read), bindns::bind(handle_read, _1, _2, &bytes_read)); io_context.run(); io_context.restart(); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); bytes_written = 0; while (bytes_written < sizeof(write_data)) { server_socket.async_write_some( boost::asio::buffer(write_buf + bytes_written), bindns::bind(handle_write, _1, _2, &bytes_written)); io_context.run(); io_context.restart(); server_socket.async_flush( bindns::bind(handle_flush, _1)); io_context.run(); io_context.restart(); } bytes_read = 0; while (bytes_read < sizeof(read_data)) { client_socket.async_read_some( boost::asio::buffer(read_buf + bytes_read), bindns::bind(handle_read, _1, _2, &bytes_read)); io_context.run(); io_context.restart(); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); server_socket.close(); client_socket.async_read_some(boost::asio::buffer(read_buf), handle_read_eof); } BOOST_ASIO_TEST_SUITE ( "buffered_write_stream", BOOST_ASIO_COMPILE_TEST_CASE(test_compile) BOOST_ASIO_TEST_CASE(test_sync_operations) BOOST_ASIO_TEST_CASE(test_async_operations) )
cpp
asio
data/projects/asio/test/associated_allocator.cpp
// // associated_allocator.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/associated_allocator.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "associated_allocator", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/basic_datagram_socket.cpp
// // basic_datagram_socket.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_datagram_socket.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_datagram_socket", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/write_at.cpp
// // write_at.cpp // ~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/write_at.hpp> #include <array> #include <cstring> #include <functional> #include "archetypes/async_result.hpp" #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/streambuf.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) #include <boost/array.hpp> #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using namespace std; // For memcmp, memcpy and memset. class test_random_access_device { public: typedef boost::asio::io_context::executor_type executor_type; test_random_access_device(boost::asio::io_context& io_context) : io_context_(io_context), length_(max_length), next_write_length_(max_length) { memset(data_, 0, max_length); } executor_type get_executor() noexcept { return io_context_.get_executor(); } void reset() { memset(data_, 0, max_length); next_write_length_ = max_length; } void next_write_length(size_t length) { next_write_length_ = length; } template <typename Iterator> bool check_buffers(boost::asio::uint64_t offset, Iterator begin, Iterator end, size_t length) { if (offset + length > max_length) return false; Iterator iter = begin; size_t checked_length = 0; for (; iter != end && checked_length < length; ++iter) { size_t buffer_length = boost::asio::buffer_size(*iter); if (buffer_length > length - checked_length) buffer_length = length - checked_length; if (memcmp(data_ + offset + checked_length, iter->data(), buffer_length) != 0) return false; checked_length += buffer_length; } return true; } template <typename Const_Buffers> bool check_buffers(boost::asio::uint64_t offset, const Const_Buffers& buffers, size_t length) { return check_buffers(offset, boost::asio::buffer_sequence_begin(buffers), boost::asio::buffer_sequence_end(buffers), length); } template <typename Const_Buffers> size_t write_some_at(boost::asio::uint64_t offset, const Const_Buffers& buffers) { return boost::asio::buffer_copy( boost::asio::buffer(data_, length_) + offset, buffers, next_write_length_); } template <typename Const_Buffers> size_t write_some_at(boost::asio::uint64_t offset, const Const_Buffers& buffers, boost::system::error_code& ec) { ec = boost::system::error_code(); return write_some_at(offset, buffers); } template <typename Const_Buffers, typename Handler> void async_write_some_at(boost::asio::uint64_t offset, const Const_Buffers& buffers, Handler&& handler) { size_t bytes_transferred = write_some_at(offset, buffers); boost::asio::post(get_executor(), boost::asio::detail::bind_handler( static_cast<Handler&&>(handler), boost::system::error_code(), bytes_transferred)); } private: boost::asio::io_context& io_context_; enum { max_length = 8192 }; char data_[max_length]; size_t length_; size_t next_write_length_; }; static const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static char mutable_write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; void test_3_arg_const_buffer_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::const_buffer buffers = boost::asio::buffer(write_data, sizeof(write_data)); s.reset(); size_t bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); } void test_3_arg_mutable_buffer_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::mutable_buffer buffers = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data)); s.reset(); size_t bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); } void test_3_arg_vector_buffers_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); std::vector<boost::asio::const_buffer> buffers; buffers.push_back(boost::asio::buffer(write_data, 32)); buffers.push_back(boost::asio::buffer(write_data) + 32); s.reset(); size_t bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); } void test_4_arg_nothrow_const_buffer_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::const_buffer buffers = boost::asio::buffer(write_data, sizeof(write_data)); s.reset(); boost::system::error_code error; size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); } void test_4_arg_nothrow_mutable_buffer_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::mutable_buffer buffers = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data)); s.reset(); boost::system::error_code error; size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); } void test_4_arg_nothrow_vector_buffers_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); std::vector<boost::asio::const_buffer> buffers; buffers.push_back(boost::asio::buffer(write_data, 32)); buffers.push_back(boost::asio::buffer(write_data) + 32); s.reset(); boost::system::error_code error; size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); } bool old_style_transfer_all(const boost::system::error_code& ec, size_t /*bytes_transferred*/) { return !!ec; } struct short_transfer { short_transfer() {} short_transfer(short_transfer&&) {} size_t operator()(const boost::system::error_code& ec, size_t /*bytes_transferred*/) { return !!ec ? 0 : 3; } }; void test_4_arg_const_buffer_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::const_buffer buffers = boost::asio::buffer(write_data, sizeof(write_data)); s.reset(); size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); } void test_4_arg_mutable_buffer_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::mutable_buffer buffers = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data)); s.reset(); size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); } void test_4_arg_vector_buffers_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); std::vector<boost::asio::const_buffer> buffers; buffers.push_back(boost::asio::buffer(write_data, 32)); buffers.push_back(boost::asio::buffer(write_data) + 32); s.reset(); size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); } void test_5_arg_const_buffer_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::const_buffer buffers = boost::asio::buffer(write_data, sizeof(write_data)); s.reset(); boost::system::error_code error; size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); } void test_5_arg_mutable_buffer_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::mutable_buffer buffers = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data)); s.reset(); boost::system::error_code error; size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); BOOST_ASIO_CHECK(!error); } void test_5_arg_vector_buffers_write_at() { boost::asio::io_context ioc; test_random_access_device s(ioc); std::vector<boost::asio::const_buffer> buffers; buffers.push_back(boost::asio::buffer(write_data, 32)); buffers.push_back(boost::asio::buffer(write_data) + 32); s.reset(); boost::system::error_code error; size_t bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(1); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); s.reset(); s.next_write_length(10); error = boost::system::error_code(); bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); BOOST_ASIO_CHECK(!error); } void async_write_handler(const boost::system::error_code& e, size_t bytes_transferred, size_t expected_bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(!e); BOOST_ASIO_CHECK(bytes_transferred == expected_bytes_transferred); } void test_4_arg_const_buffer_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::const_buffer buffers = boost::asio::buffer(write_data, sizeof(write_data)); s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_4_arg_mutable_buffer_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::mutable_buffer buffers = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data)); s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_4_arg_boost_array_buffers_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) boost::asio::io_context ioc; test_random_access_device s(ioc); boost::array<boost::asio::const_buffer, 2> buffers = { { boost::asio::buffer(write_data, 32), boost::asio::buffer(write_data) + 32 } }; s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) } void test_4_arg_std_array_buffers_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); std::array<boost::asio::const_buffer, 2> buffers = { { boost::asio::buffer(write_data, 32), boost::asio::buffer(write_data) + 32 } }; s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_4_arg_vector_buffers_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); std::vector<boost::asio::const_buffer> buffers; buffers.push_back(boost::asio::buffer(write_data, 32)); buffers.push_back(boost::asio::buffer(write_data) + 32); s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_4_arg_streambuf_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::streambuf sb; boost::asio::const_buffer buffers = boost::asio::buffer(write_data, sizeof(write_data)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); bool called = false; boost::asio::async_write_at(s, 0, sb, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); int i = boost::asio::async_write_at(s, 0, sb, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_5_arg_const_buffer_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::const_buffer buffers = boost::asio::buffer(write_data, sizeof(write_data)); s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_5_arg_mutable_buffer_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::mutable_buffer buffers = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data)); s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(mutable_write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(mutable_write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(mutable_write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_5_arg_boost_array_buffers_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) boost::asio::io_context ioc; test_random_access_device s(ioc); boost::array<boost::asio::const_buffer, 2> buffers = { { boost::asio::buffer(write_data, 32), boost::asio::buffer(write_data) + 32 } }; s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) } void test_5_arg_std_array_buffers_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); std::array<boost::asio::const_buffer, 2> buffers = { { boost::asio::buffer(write_data, 32), boost::asio::buffer(write_data) + 32 } }; s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_5_arg_vector_buffers_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); std::vector<boost::asio::const_buffer> buffers; buffers.push_back(boost::asio::buffer(write_data, 32)); buffers.push_back(boost::asio::buffer(write_data) + 32); s.reset(); bool called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, buffers, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); int i = boost::asio::async_write_at(s, 0, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } void test_5_arg_streambuf_async_write_at() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_random_access_device s(ioc); boost::asio::streambuf sb; boost::asio::const_buffer buffers = boost::asio::buffer(write_data, sizeof(write_data)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); bool called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_all(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(1), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 50)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_at_least(42), bindns::bind(async_write_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 50)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 1)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(1), bindns::bind(async_write_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 1)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(10), bindns::bind(async_write_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 10)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, 42)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, boost::asio::transfer_exactly(42), bindns::bind(async_write_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, 42)); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 0, sb, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, old_style_transfer_all, bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 0, sb, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); called = false; boost::asio::async_write_at(s, 1234, sb, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 0, sb, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(1); called = false; boost::asio::async_write_at(s, 1234, sb, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 0, sb, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); s.next_write_length(10); called = false; boost::asio::async_write_at(s, 1234, sb, short_transfer(), bindns::bind(async_write_handler, _1, _2, sizeof(write_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(1234, buffers, sizeof(write_data))); s.reset(); sb.consume(sb.size()); sb.sputn(write_data, sizeof(write_data)); int i = boost::asio::async_write_at(s, 0, sb, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(0, buffers, sizeof(write_data))); } BOOST_ASIO_TEST_SUITE ( "write_at", BOOST_ASIO_TEST_CASE(test_3_arg_const_buffer_write_at) BOOST_ASIO_TEST_CASE(test_3_arg_mutable_buffer_write_at) BOOST_ASIO_TEST_CASE(test_3_arg_vector_buffers_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_nothrow_const_buffer_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_nothrow_mutable_buffer_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_nothrow_vector_buffers_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_const_buffer_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_mutable_buffer_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_vector_buffers_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_const_buffer_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_mutable_buffer_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_vector_buffers_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_const_buffer_async_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_mutable_buffer_async_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_boost_array_buffers_async_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_std_array_buffers_async_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_vector_buffers_async_write_at) BOOST_ASIO_TEST_CASE(test_4_arg_streambuf_async_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_const_buffer_async_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_mutable_buffer_async_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_boost_array_buffers_async_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_std_array_buffers_async_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_vector_buffers_async_write_at) BOOST_ASIO_TEST_CASE(test_5_arg_streambuf_async_write_at) )
cpp
asio
data/projects/asio/test/streambuf.cpp
// // streambuf.cpp // ~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/streambuf.hpp> #include <boost/asio/buffer.hpp> #include "unit_test.hpp" void streambuf_test() { boost::asio::streambuf sb; sb.sputn("abcd", 4); BOOST_ASIO_CHECK(sb.size() == 4); for (int i = 0; i < 100; ++i) { sb.consume(3); BOOST_ASIO_CHECK(sb.size() == 1); char buf[1]; sb.sgetn(buf, 1); BOOST_ASIO_CHECK(sb.size() == 0); sb.sputn("ab", 2); BOOST_ASIO_CHECK(sb.size() == 2); boost::asio::buffer_copy(sb.prepare(10), boost::asio::buffer("cd", 2)); sb.commit(2); BOOST_ASIO_CHECK(sb.size() == 4); } BOOST_ASIO_CHECK(sb.size() == 4); sb.consume(4); BOOST_ASIO_CHECK(sb.size() == 0); } BOOST_ASIO_TEST_SUITE ( "streambuf", BOOST_ASIO_TEST_CASE(streambuf_test) )
cpp
asio
data/projects/asio/test/system_executor.cpp
// // system_executor.cpp // ~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Prevent link dependency on the Boost.System library. #if !defined(BOOST_SYSTEM_NO_DEPRECATED) #define BOOST_SYSTEM_NO_DEPRECATED #endif // !defined(BOOST_SYSTEM_NO_DEPRECATED) // Test that header file is self-contained. #include <boost/asio/system_executor.hpp> #include <functional> #include <boost/asio/dispatch.hpp> #include <boost/asio/post.hpp> #include "unit_test.hpp" using namespace boost::asio; namespace bindns = std; void increment(boost::asio::detail::atomic_count* count) { ++(*count); } void system_executor_query_test() { BOOST_ASIO_CHECK( &boost::asio::query(system_executor(), boost::asio::execution::context) != static_cast<const system_context*>(0)); BOOST_ASIO_CHECK( boost::asio::query(system_executor(), boost::asio::execution::blocking) == boost::asio::execution::blocking.possibly); BOOST_ASIO_CHECK( boost::asio::query(system_executor(), boost::asio::execution::blocking.possibly) == boost::asio::execution::blocking.possibly); BOOST_ASIO_CHECK( boost::asio::query(system_executor(), boost::asio::execution::outstanding_work) == boost::asio::execution::outstanding_work.untracked); BOOST_ASIO_CHECK( boost::asio::query(system_executor(), boost::asio::execution::outstanding_work.untracked) == boost::asio::execution::outstanding_work.untracked); BOOST_ASIO_CHECK( boost::asio::query(system_executor(), boost::asio::execution::relationship) == boost::asio::execution::relationship.fork); BOOST_ASIO_CHECK( boost::asio::query(system_executor(), boost::asio::execution::relationship.fork) == boost::asio::execution::relationship.fork); BOOST_ASIO_CHECK( boost::asio::query(system_executor(), boost::asio::execution::mapping) == boost::asio::execution::mapping.thread); BOOST_ASIO_CHECK( boost::asio::query(system_executor(), boost::asio::execution::allocator) == std::allocator<void>()); } void system_executor_execute_test() { boost::asio::detail::atomic_count count(0); system_executor().execute(bindns::bind(increment, &count)); boost::asio::require(system_executor(), boost::asio::execution::blocking.possibly ).execute(bindns::bind(increment, &count)); boost::asio::require(system_executor(), boost::asio::execution::blocking.always ).execute(bindns::bind(increment, &count)); boost::asio::require(system_executor(), boost::asio::execution::blocking.never ).execute(bindns::bind(increment, &count)); boost::asio::require(system_executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked ).execute(bindns::bind(increment, &count)); boost::asio::require(system_executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked, boost::asio::execution::relationship.fork ).execute(bindns::bind(increment, &count)); boost::asio::require(system_executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked, boost::asio::execution::relationship.continuation ).execute(bindns::bind(increment, &count)); boost::asio::prefer( boost::asio::require(system_executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked, boost::asio::execution::relationship.continuation), boost::asio::execution::allocator(std::allocator<void>()) ).execute(bindns::bind(increment, &count)); boost::asio::prefer( boost::asio::require(system_executor(), boost::asio::execution::blocking.never, boost::asio::execution::outstanding_work.untracked, boost::asio::execution::relationship.continuation), boost::asio::execution::allocator ).execute(bindns::bind(increment, &count)); boost::asio::query(system_executor(), execution::context).join(); BOOST_ASIO_CHECK(count == 9); } BOOST_ASIO_TEST_SUITE ( "system_executor", BOOST_ASIO_TEST_CASE(system_executor_query_test) BOOST_ASIO_TEST_CASE(system_executor_execute_test) )
cpp
asio
data/projects/asio/test/basic_stream_socket.cpp
// // basic_stream_socket.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_stream_socket.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_stream_socket", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/basic_random_access_file.cpp
// // basic_random_access_file.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_random_access_file.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_random_access_file", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/buffer.cpp
// // buffer.cpp // ~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/buffer.hpp> #include <array> #include <cstring> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <boost/array.hpp> #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) //------------------------------------------------------------------------------ // buffer_compile test // ~~~~~~~~~~~~~~~~~~~ // The following test checks that all overloads of the buffer function compile // and link correctly. Runtime failures are ignored. namespace buffer_compile { using namespace boost::asio; template <typename T> class mutable_contiguous_container { public: typedef T value_type; typedef T* iterator; typedef const T* const_iterator; typedef T& reference; typedef const T& const_reference; mutable_contiguous_container() {} std::size_t size() const { return 0; } iterator begin() { return 0; } const_iterator begin() const { return 0; } iterator end() { return 0; } const_iterator end() const { return 0; } }; template <typename T> class const_contiguous_container { public: typedef const T value_type; typedef const T* iterator; typedef const T* const_iterator; typedef const T& reference; typedef const T& const_reference; const_contiguous_container() {} std::size_t size() const { return 0; } iterator begin() { return 0; } const_iterator begin() const { return 0; } iterator end() { return 0; } const_iterator end() const { return 0; } }; void test() { try { char raw_data[1024]; const char const_raw_data[1024] = ""; void* void_ptr_data = raw_data; const void* const_void_ptr_data = const_raw_data; #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) boost::array<char, 1024> array_data; const boost::array<char, 1024>& const_array_data_1 = array_data; boost::array<const char, 1024> const_array_data_2 = { { 0 } }; #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) std::array<char, 1024> std_array_data; const std::array<char, 1024>& const_std_array_data_1 = std_array_data; std::array<const char, 1024> const_std_array_data_2 = { { 0 } }; std::vector<char> vector_data(1024); const std::vector<char>& const_vector_data = vector_data; std::string string_data(1024, ' '); const std::string const_string_data(1024, ' '); std::vector<mutable_buffer> mutable_buffer_sequence; std::vector<const_buffer> const_buffer_sequence; #if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) std::string_view string_view_data(string_data); #elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) std::experimental::string_view string_view_data(string_data); #endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) mutable_contiguous_container<char> mutable_contiguous_data; const mutable_contiguous_container<char> const_mutable_contiguous_data; const_contiguous_container<char> const_contiguous_data; const const_contiguous_container<char> const_const_contiguous_data; // mutable_buffer constructors. mutable_buffer mb1; mutable_buffer mb2(void_ptr_data, 1024); mutable_buffer mb3(mb1); (void)mb3; // mutable_buffer functions. void* ptr1 = mb1.data(); (void)ptr1; std::size_t n1 = mb1.size(); (void)n1; // mutable_buffer operators. mb1 += 128; mb1 = mb2 + 128; mb1 = 128 + mb2; #if !defined(BOOST_ASIO_NO_DEPRECATED) // mutable_buffers_1 constructors. mutable_buffers_1 mbc1(mb1); mutable_buffers_1 mbc2(mbc1); // mutable_buffers_1 functions. mutable_buffers_1::const_iterator iter1 = mbc1.begin(); (void)iter1; mutable_buffers_1::const_iterator iter2 = mbc1.end(); (void)iter2; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // const_buffer constructors. const_buffer cb1; const_buffer cb2(const_void_ptr_data, 1024); const_buffer cb3(cb1); (void)cb3; const_buffer cb4(mb1); (void)cb4; // const_buffer functions. const void* ptr2 = cb1.data(); (void)ptr2; std::size_t n2 = cb1.size(); (void)n2; // const_buffer operators. cb1 += 128; cb1 = cb2 + 128; cb1 = 128 + cb2; #if !defined(BOOST_ASIO_NO_DEPRECATED) // const_buffers_1 constructors. const_buffers_1 cbc1(cb1); const_buffers_1 cbc2(cbc1); // const_buffers_1 functions. const_buffers_1::const_iterator iter3 = cbc1.begin(); (void)iter3; const_buffers_1::const_iterator iter4 = cbc1.end(); (void)iter4; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // buffer_size function overloads. std::size_t size1 = buffer_size(mb1); (void)size1; std::size_t size2 = buffer_size(cb1); (void)size2; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size3 = buffer_size(mbc1); (void)size3; std::size_t size4 = buffer_size(cbc1); (void)size4; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size5 = buffer_size(mutable_buffer_sequence); (void)size5; std::size_t size6 = buffer_size(const_buffer_sequence); (void)size6; // buffer_cast function overloads. #if !defined(BOOST_ASIO_NO_DEPRECATED) void* ptr3 = buffer_cast<void*>(mb1); (void)ptr3; const void* ptr4 = buffer_cast<const void*>(cb1); (void)ptr4; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // buffer function overloads. mb1 = buffer(mb2); mb1 = buffer(mb2, 128); cb1 = buffer(cb2); cb1 = buffer(cb2, 128); mb1 = buffer(void_ptr_data, 1024); cb1 = buffer(const_void_ptr_data, 1024); mb1 = buffer(raw_data); mb1 = buffer(raw_data, 1024); cb1 = buffer(const_raw_data); cb1 = buffer(const_raw_data, 1024); #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) mb1 = buffer(array_data); mb1 = buffer(array_data, 1024); cb1 = buffer(const_array_data_1); cb1 = buffer(const_array_data_1, 1024); cb1 = buffer(const_array_data_2); cb1 = buffer(const_array_data_2, 1024); #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) mb1 = buffer(std_array_data); mb1 = buffer(std_array_data, 1024); cb1 = buffer(const_std_array_data_1); cb1 = buffer(const_std_array_data_1, 1024); cb1 = buffer(const_std_array_data_2); cb1 = buffer(const_std_array_data_2, 1024); mb1 = buffer(vector_data); mb1 = buffer(vector_data, 1024); cb1 = buffer(const_vector_data); cb1 = buffer(const_vector_data, 1024); mb1 = buffer(string_data); mb1 = buffer(string_data, 1024); cb1 = buffer(const_string_data); cb1 = buffer(const_string_data, 1024); #if defined(BOOST_ASIO_HAS_STRING_VIEW) cb1 = buffer(string_view_data); cb1 = buffer(string_view_data, 1024); #endif // defined(BOOST_ASIO_HAS_STRING_VIEW) mb1 = buffer(mutable_contiguous_data); mb1 = buffer(mutable_contiguous_data, 1024); cb1 = buffer(const_mutable_contiguous_data); cb1 = buffer(const_mutable_contiguous_data, 1024); cb1 = buffer(const_contiguous_data); cb1 = buffer(const_contiguous_data, 1024); cb1 = buffer(const_const_contiguous_data); cb1 = buffer(const_const_contiguous_data, 1024); // buffer_copy function overloads. std::size_t size7 = buffer_copy(mb1, cb2); (void)size7; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size8 = buffer_copy(mb1, cbc2); (void)size8; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size9 = buffer_copy(mb1, mb2); (void)size9; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size10 = buffer_copy(mb1, mbc2); (void)size10; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size11 = buffer_copy(mb1, const_buffer_sequence); (void)size11; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size12 = buffer_copy(mbc1, cb2); (void)size12; std::size_t size13 = buffer_copy(mbc1, cbc2); (void)size13; std::size_t size14 = buffer_copy(mbc1, mb2); (void)size14; std::size_t size15 = buffer_copy(mbc1, mbc2); (void)size15; std::size_t size16 = buffer_copy(mbc1, const_buffer_sequence); (void)size16; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size17 = buffer_copy(mutable_buffer_sequence, cb2); (void)size17; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size18 = buffer_copy(mutable_buffer_sequence, cbc2); (void)size18; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size19 = buffer_copy(mutable_buffer_sequence, mb2); (void)size19; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size20 = buffer_copy(mutable_buffer_sequence, mbc2); (void)size20; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size21 = buffer_copy( mutable_buffer_sequence, const_buffer_sequence); (void)size21; std::size_t size22 = buffer_copy(mb1, cb2, 128); (void)size22; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size23 = buffer_copy(mb1, cbc2, 128); (void)size23; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size24 = buffer_copy(mb1, mb2, 128); (void)size24; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size25 = buffer_copy(mb1, mbc2, 128); (void)size25; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size26 = buffer_copy(mb1, const_buffer_sequence, 128); (void)size26; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size27 = buffer_copy(mbc1, cb2, 128); (void)size27; std::size_t size28 = buffer_copy(mbc1, cbc2, 128); (void)size28; std::size_t size29 = buffer_copy(mbc1, mb2, 128); (void)size29; std::size_t size30 = buffer_copy(mbc1, mbc2, 128); (void)size30; std::size_t size31 = buffer_copy(mbc1, const_buffer_sequence, 128); (void)size31; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size32 = buffer_copy(mutable_buffer_sequence, cb2, 128); (void)size32; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size33 = buffer_copy(mutable_buffer_sequence, cbc2, 128); (void)size33; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size34 = buffer_copy(mutable_buffer_sequence, mb2, 128); (void)size34; #if !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size35 = buffer_copy(mutable_buffer_sequence, mbc2, 128); (void)size35; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::size_t size36 = buffer_copy( mutable_buffer_sequence, const_buffer_sequence, 128); (void)size36; // dynamic_buffer function overloads. dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type> db1 = dynamic_buffer(string_data); (void)db1; dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type> db2 = dynamic_buffer(string_data, 1024); (void)db2; dynamic_vector_buffer<char, std::allocator<char> > db3 = dynamic_buffer(vector_data); (void)db3; dynamic_vector_buffer<char, std::allocator<char> > db4 = dynamic_buffer(vector_data, 1024); (void)db4; // dynamic_buffer member functions. std::size_t size37 = db1.size(); (void)size37; std::size_t size38 = db3.size(); (void)size38; std::size_t size39 = db1.max_size(); (void)size39; std::size_t size40 = db3.max_size(); (void)size40; #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type>::const_buffers_type cb5 = db1.data(); (void)cb5; dynamic_vector_buffer<char, std::allocator<char> >::const_buffers_type cb6 = db3.data(); (void)cb6; dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type>::mutable_buffers_type mb5 = db1.prepare(1024); (void)mb5; dynamic_vector_buffer<char, std::allocator<char> >::mutable_buffers_type mb6 = db3.prepare(1024); (void)mb6; db1.commit(1024); db3.commit(1024); #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type>::mutable_buffers_type mb7 = db1.data(0, 1); (void)mb7; dynamic_vector_buffer<char, std::allocator<char> >::mutable_buffers_type mb8 = db3.data(0, 1); (void)mb8; dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type>::const_buffers_type cb7 = static_cast<const dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type>&>(db1).data(0, 1); (void)cb7; dynamic_vector_buffer<char, std::allocator<char> >::const_buffers_type cb8 = static_cast<const dynamic_vector_buffer<char, std::allocator<char> >&>(db3).data(0, 1); (void)cb8; db1.grow(1024); db3.grow(1024); db1.shrink(1024); db3.shrink(1024); db1.consume(0); db3.consume(0); } catch (std::exception&) { } } } // namespace buffer_compile //------------------------------------------------------------------------------ namespace buffer_copy_runtime { using namespace boost::asio; using namespace std; void test() { char dest_data[256]; char source_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; memset(dest_data, 0, sizeof(dest_data)); mutable_buffer mb1 = boost::asio::buffer(dest_data); mutable_buffer mb2 = boost::asio::buffer(source_data); std::size_t n = buffer_copy(mb1, mb2); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); const_buffer cb1 = boost::asio::buffer(source_data); n = buffer_copy(mb1, cb1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); #if !defined(BOOST_ASIO_NO_DEPRECATED) memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); mutable_buffers_1 mbc1 = boost::asio::buffer(source_data); n = buffer_copy(mb1, mbc1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); const_buffers_1 cbc1 = const_buffers_1(boost::asio::buffer(source_data)); n = buffer_copy(mb1, cbc1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mbc1 = boost::asio::buffer(dest_data); mb1 = boost::asio::buffer(source_data); n = buffer_copy(mbc1, mb1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mbc1 = boost::asio::buffer(dest_data); cb1 = boost::asio::buffer(source_data); n = buffer_copy(mbc1, cb1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mbc1 = boost::asio::buffer(dest_data); mutable_buffers_1 mbc2 = boost::asio::buffer(source_data); n = buffer_copy(mbc1, mbc2); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mbc1 = boost::asio::buffer(dest_data); cbc1 = const_buffers_1(boost::asio::buffer(source_data)); n = buffer_copy(mbc1, cbc1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); std::vector<mutable_buffer> mv1; mv1.push_back(boost::asio::buffer(source_data, 5)); mv1.push_back(boost::asio::buffer(source_data) + 5); n = buffer_copy(mb1, mv1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); std::vector<const_buffer> cv1; cv1.push_back(boost::asio::buffer(source_data, 6)); cv1.push_back(boost::asio::buffer(source_data) + 6); n = buffer_copy(mb1, cv1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mv1.clear(); mv1.push_back(boost::asio::buffer(dest_data, 7)); mv1.push_back(boost::asio::buffer(dest_data) + 7); cb1 = boost::asio::buffer(source_data); n = buffer_copy(mv1, cb1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mv1.clear(); mv1.push_back(boost::asio::buffer(dest_data, 7)); mv1.push_back(boost::asio::buffer(dest_data) + 7); cv1.clear(); cv1.push_back(boost::asio::buffer(source_data, 8)); cv1.push_back(boost::asio::buffer(source_data) + 8); n = buffer_copy(mv1, cv1); BOOST_ASIO_CHECK(n == sizeof(source_data)); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); mb2 = boost::asio::buffer(source_data); n = buffer_copy(mb1, mb2, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); cb1 = boost::asio::buffer(source_data); n = buffer_copy(mb1, cb1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); #if !defined(BOOST_ASIO_NO_DEPRECATED) memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); mbc1 = boost::asio::buffer(source_data); n = buffer_copy(mb1, mbc1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); cbc1 = const_buffers_1(boost::asio::buffer(source_data)); n = buffer_copy(mb1, cbc1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mbc1 = boost::asio::buffer(dest_data); mb1 = boost::asio::buffer(source_data); n = buffer_copy(mbc1, mb1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mbc1 = boost::asio::buffer(dest_data); cb1 = boost::asio::buffer(source_data); n = buffer_copy(mbc1, cb1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mbc1 = boost::asio::buffer(dest_data); mbc2 = boost::asio::buffer(source_data); n = buffer_copy(mbc1, mbc2, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mbc1 = boost::asio::buffer(dest_data); cbc1 = const_buffers_1(boost::asio::buffer(source_data)); n = buffer_copy(mbc1, cbc1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); mv1.clear(); mv1.push_back(boost::asio::buffer(source_data, 5)); mv1.push_back(boost::asio::buffer(source_data) + 5); n = buffer_copy(mb1, mv1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mb1 = boost::asio::buffer(dest_data); cv1.clear(); cv1.push_back(boost::asio::buffer(source_data, 6)); cv1.push_back(boost::asio::buffer(source_data) + 6); n = buffer_copy(mb1, cv1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mv1.clear(); mv1.push_back(boost::asio::buffer(dest_data, 7)); mv1.push_back(boost::asio::buffer(dest_data) + 7); cb1 = boost::asio::buffer(source_data); n = buffer_copy(mv1, cb1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); memset(dest_data, 0, sizeof(dest_data)); mv1.clear(); mv1.push_back(boost::asio::buffer(dest_data, 7)); mv1.push_back(boost::asio::buffer(dest_data) + 7); cv1.clear(); cv1.push_back(boost::asio::buffer(source_data, 8)); cv1.push_back(boost::asio::buffer(source_data) + 8); n = buffer_copy(mv1, cv1, 10); BOOST_ASIO_CHECK(n == 10); BOOST_ASIO_CHECK(memcmp(dest_data, source_data, n) == 0); } } // namespace buffer_copy_runtime //------------------------------------------------------------------------------ namespace buffer_sequence { using namespace boost::asio; using namespace std; struct valid_const_a { typedef const_buffer* const_iterator; typedef const_buffer value_type; const_buffer* begin() const { return 0; } const_buffer* end() const { return 0; } }; struct valid_const_b { const_buffer* begin() const { return 0; } const_buffer* end() const { return 0; } }; struct valid_mutable_a { typedef mutable_buffer* const_iterator; typedef mutable_buffer value_type; mutable_buffer* begin() const { return 0; } mutable_buffer* end() const { return 0; } }; struct valid_mutable_b { mutable_buffer* begin() const { return 0; } mutable_buffer* end() const { return 0; } }; struct invalid_const_a { typedef int value_type; int* begin() const { return 0; } const_buffer* end() const { return 0; } }; struct invalid_const_b { typedef const_buffer value_type; const_buffer* begin() const { return 0; } }; struct invalid_const_c { typedef const_buffer value_type; const_buffer* end() const { return 0; } }; struct invalid_const_d { int* begin() const { return 0; } const_buffer* end() const { return 0; } }; struct invalid_const_e { const_buffer* begin() const { return 0; } }; struct invalid_const_f { const_buffer* end() const { return 0; } }; struct invalid_mutable_a { typedef int value_type; int* begin() const { return 0; } mutable_buffer* end() const { return 0; } }; struct invalid_mutable_b { typedef mutable_buffer value_type; mutable_buffer* begin() const { return 0; } }; struct invalid_mutable_c { typedef mutable_buffer value_type; mutable_buffer* end() const { return 0; } }; struct invalid_mutable_d { int* begin() const { return 0; } mutable_buffer* end() const { return 0; } }; struct invalid_mutable_e { mutable_buffer* begin() const { return 0; } }; struct invalid_mutable_f { mutable_buffer* end() const { return 0; } }; void test() { BOOST_ASIO_CHECK(is_const_buffer_sequence<const_buffer>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<const_buffer>::value); const_buffer b1; BOOST_ASIO_CHECK(buffer_sequence_begin(b1) == &b1); BOOST_ASIO_CHECK(buffer_sequence_end(b1) == &b1 + 1); BOOST_ASIO_CHECK(is_const_buffer_sequence<mutable_buffer>::value); BOOST_ASIO_CHECK(is_mutable_buffer_sequence<mutable_buffer>::value); mutable_buffer b2; BOOST_ASIO_CHECK(buffer_sequence_begin(b2) == &b2); BOOST_ASIO_CHECK(buffer_sequence_end(b2) == &b2 + 1); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(is_const_buffer_sequence<const_buffers_1>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<const_buffers_1>::value); const_buffers_1 b3(0, 0); BOOST_ASIO_CHECK(buffer_sequence_begin(b3) == &b3); BOOST_ASIO_CHECK(buffer_sequence_end(b3) == &b3 + 1); BOOST_ASIO_CHECK(is_const_buffer_sequence<mutable_buffers_1>::value); BOOST_ASIO_CHECK(is_mutable_buffer_sequence<mutable_buffers_1>::value); mutable_buffers_1 b4(0, 0); BOOST_ASIO_CHECK(buffer_sequence_begin(b4) == &b4); BOOST_ASIO_CHECK(buffer_sequence_end(b4) == &b4 + 1); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(is_const_buffer_sequence<vector<const_buffer> >::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<vector<const_buffer> >::value); vector<const_buffer> b5; BOOST_ASIO_CHECK(buffer_sequence_begin(b5) == b5.begin()); BOOST_ASIO_CHECK(buffer_sequence_end(b5) == b5.end()); BOOST_ASIO_CHECK(is_const_buffer_sequence<vector<mutable_buffer> >::value); BOOST_ASIO_CHECK(is_mutable_buffer_sequence<vector<mutable_buffer> >::value); vector<mutable_buffer> b6; BOOST_ASIO_CHECK(buffer_sequence_begin(b6) == b6.begin()); BOOST_ASIO_CHECK(buffer_sequence_end(b6) == b6.end()); BOOST_ASIO_CHECK(is_const_buffer_sequence<valid_const_a>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<valid_const_a>::value); valid_const_a b7; BOOST_ASIO_CHECK(buffer_sequence_begin(b7) == b7.begin()); BOOST_ASIO_CHECK(buffer_sequence_end(b7) == b7.end()); BOOST_ASIO_CHECK(is_const_buffer_sequence<valid_const_b>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<valid_const_b>::value); valid_const_b b8; BOOST_ASIO_CHECK(buffer_sequence_begin(b8) == b8.begin()); BOOST_ASIO_CHECK(buffer_sequence_end(b8) == b8.end()); BOOST_ASIO_CHECK(is_const_buffer_sequence<valid_mutable_a>::value); BOOST_ASIO_CHECK(is_mutable_buffer_sequence<valid_mutable_a>::value); valid_mutable_a b9; BOOST_ASIO_CHECK(buffer_sequence_begin(b9) == b9.begin()); BOOST_ASIO_CHECK(buffer_sequence_end(b9) == b9.end()); BOOST_ASIO_CHECK(is_const_buffer_sequence<valid_mutable_b>::value); BOOST_ASIO_CHECK(is_mutable_buffer_sequence<valid_mutable_b>::value); valid_mutable_b b10; BOOST_ASIO_CHECK(buffer_sequence_begin(b10) == b10.begin()); BOOST_ASIO_CHECK(buffer_sequence_end(b10) == b10.end()); BOOST_ASIO_CHECK(!is_const_buffer_sequence<invalid_const_a>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_a>::value); BOOST_ASIO_CHECK(!is_const_buffer_sequence<invalid_const_b>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_b>::value); BOOST_ASIO_CHECK(!is_const_buffer_sequence<invalid_const_c>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_c>::value); BOOST_ASIO_CHECK(!is_const_buffer_sequence<invalid_const_d>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_d>::value); BOOST_ASIO_CHECK(!is_const_buffer_sequence<invalid_const_e>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_e>::value); BOOST_ASIO_CHECK(!is_const_buffer_sequence<invalid_const_f>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_f>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_a>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_a>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_b>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_b>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_c>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_c>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_d>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_d>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_e>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_e>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_f>::value); BOOST_ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_f>::value); } } // namespace buffer_sequence namespace buffer_literals { void test() { #if defined(BOOST_ASIO_HAS_USER_DEFINED_LITERALS) using namespace boost::asio::buffer_literals; using namespace std; // For memcmp. boost::asio::const_buffer b1 = ""_buf; BOOST_ASIO_CHECK(b1.size() == 0); boost::asio::const_buffer b2 = "hello"_buf; BOOST_ASIO_CHECK(b2.size() == 5); BOOST_ASIO_CHECK(memcmp(b2.data(), "hello", 5) == 0); boost::asio::const_buffer b3 = 0x00_buf; BOOST_ASIO_CHECK(b3.size() == 1); BOOST_ASIO_CHECK(memcmp(b3.data(), "\x00", 1) == 0); boost::asio::const_buffer b4 = 0X01_buf; BOOST_ASIO_CHECK(b4.size() == 1); BOOST_ASIO_CHECK(memcmp(b4.data(), "\x01", 1) == 0); boost::asio::const_buffer b5 = 0xaB_buf; BOOST_ASIO_CHECK(b5.size() == 1); BOOST_ASIO_CHECK(memcmp(b5.data(), "\xab", 1) == 0); boost::asio::const_buffer b6 = 0xABcd_buf; BOOST_ASIO_CHECK(b6.size() == 2); BOOST_ASIO_CHECK(memcmp(b6.data(), "\xab\xcd", 2) == 0); boost::asio::const_buffer b7 = 0x01ab01cd01ef01ba01dc01fe_buf; BOOST_ASIO_CHECK(b7.size() == 12); BOOST_ASIO_CHECK(memcmp(b7.data(), "\x01\xab\x01\xcd\x01\xef\x01\xba\x01\xdc\x01\xfe", 12) == 0); boost::asio::const_buffer b8 = 0b00000000_buf; BOOST_ASIO_CHECK(b8.size() == 1); BOOST_ASIO_CHECK(memcmp(b8.data(), "\x00", 1) == 0); boost::asio::const_buffer b9 = 0B00000001_buf; BOOST_ASIO_CHECK(b9.size() == 1); BOOST_ASIO_CHECK(memcmp(b9.data(), "\x01", 1) == 0); boost::asio::const_buffer b10 = 0B11111111_buf; BOOST_ASIO_CHECK(b10.size() == 1); BOOST_ASIO_CHECK(memcmp(b10.data(), "\xFF", 1) == 0); boost::asio::const_buffer b11 = 0b1111000000001111_buf; BOOST_ASIO_CHECK(b11.size() == 2); BOOST_ASIO_CHECK(memcmp(b11.data(), "\xF0\x0F", 2) == 0); #endif // (defined(BOOST_ASIO_HAS_USER_DEFINED_LITERALS) } } // namespace buffer_literals //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "buffer", BOOST_ASIO_COMPILE_TEST_CASE(buffer_compile::test) BOOST_ASIO_TEST_CASE(buffer_copy_runtime::test) BOOST_ASIO_TEST_CASE(buffer_sequence::test) BOOST_ASIO_TEST_CASE(buffer_literals::test) )
cpp
asio
data/projects/asio/test/basic_stream_file.cpp
// // basic_stream_file.cpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_stream_file.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_stream_file", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/static_thread_pool.cpp
// // static_thread_pool.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Prevent link dependency on the Boost.System library. #if !defined(BOOST_SYSTEM_NO_DEPRECATED) #define BOOST_SYSTEM_NO_DEPRECATED #endif // !defined(BOOST_SYSTEM_NO_DEPRECATED) // Test that header file is self-contained. #include <boost/asio/static_thread_pool.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "static_thread_pool", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/is_write_buffered.cpp
// // is_write_buffered.cpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/is_write_buffered.hpp> #include <boost/asio/buffered_read_stream.hpp> #include <boost/asio/buffered_write_stream.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include "unit_test.hpp" using namespace std; // For memcmp, memcpy and memset. class test_stream { public: typedef boost::asio::io_context io_context_type; typedef test_stream lowest_layer_type; typedef io_context_type::executor_type executor_type; test_stream(boost::asio::io_context& io_context) : io_context_(io_context) { } io_context_type& io_context() { return io_context_; } lowest_layer_type& lowest_layer() { return *this; } template <typename Const_Buffers> size_t write(const Const_Buffers&) { return 0; } template <typename Const_Buffers> size_t write(const Const_Buffers&, boost::system::error_code& ec) { ec = boost::system::error_code(); return 0; } template <typename Const_Buffers, typename Handler> void async_write(const Const_Buffers&, Handler handler) { boost::system::error_code error; boost::asio::post(io_context_, boost::asio::detail::bind_handler(handler, error, 0)); } template <typename Mutable_Buffers> size_t read(const Mutable_Buffers&) { return 0; } template <typename Mutable_Buffers> size_t read(const Mutable_Buffers&, boost::system::error_code& ec) { ec = boost::system::error_code(); return 0; } template <typename Mutable_Buffers, typename Handler> void async_read(const Mutable_Buffers&, Handler handler) { boost::system::error_code error; boost::asio::post(io_context_, boost::asio::detail::bind_handler(handler, error, 0)); } private: io_context_type& io_context_; }; void is_write_buffered_test() { BOOST_ASIO_CHECK(!boost::asio::is_write_buffered< boost::asio::ip::tcp::socket>::value); BOOST_ASIO_CHECK(!boost::asio::is_write_buffered< boost::asio::buffered_read_stream< boost::asio::ip::tcp::socket> >::value); BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered< boost::asio::buffered_write_stream< boost::asio::ip::tcp::socket> >::value); BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered< boost::asio::buffered_stream<boost::asio::ip::tcp::socket> >::value); BOOST_ASIO_CHECK(!boost::asio::is_write_buffered<test_stream>::value); BOOST_ASIO_CHECK(!boost::asio::is_write_buffered< boost::asio::buffered_read_stream<test_stream> >::value); BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered< boost::asio::buffered_write_stream<test_stream> >::value); BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered< boost::asio::buffered_stream<test_stream> >::value); } BOOST_ASIO_TEST_SUITE ( "is_write_buffered", BOOST_ASIO_TEST_CASE(is_write_buffered_test) )
cpp
asio
data/projects/asio/test/associator.cpp
// // associator.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/associator.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "associator", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/basic_socket.cpp
// // basic_socket.cpp // ~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_socket.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_socket", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/connect_pipe.cpp
// // connect_pipe.cpp // ~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/connect_pipe.hpp> #include <functional> #include <string> #include <boost/asio/io_context.hpp> #include <boost/asio/read.hpp> #include <boost/asio/readable_pipe.hpp> #include <boost/asio/writable_pipe.hpp> #include <boost/asio/write.hpp> #include "unit_test.hpp" //------------------------------------------------------------------------------ // connect_pipe_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all connect_pipe functions compile and link // correctly. Runtime failures are ignored. namespace connect_pipe_compile { void test() { #if defined(BOOST_ASIO_HAS_PIPE) using namespace boost::asio; try { boost::asio::io_context io_context; boost::system::error_code ec1; readable_pipe p1(io_context); writable_pipe p2(io_context); connect_pipe(p1, p2); readable_pipe p3(io_context); writable_pipe p4(io_context); connect_pipe(p3, p4, ec1); } catch (std::exception&) { } #endif // defined(BOOST_ASIO_HAS_PIPE) } } // namespace connect_pipe_compile //------------------------------------------------------------------------------ // connect_pipe_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that connect_pipe operates correctly at runtime. namespace connect_pipe_runtime { static const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; void handle_read(const boost::system::error_code& err, size_t bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(!err); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); } void handle_write(const boost::system::error_code& err, size_t bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(!err); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); } void test() { #if defined(BOOST_ASIO_HAS_PIPE) using namespace std; // For memcmp. using namespace boost::asio; namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; try { boost::asio::io_context io_context; boost::system::error_code ec1; boost::system::error_code ec2; readable_pipe p1(io_context); writable_pipe p2(io_context); connect_pipe(p1, p2); std::string data1 = write_data; boost::asio::write(p2, boost::asio::buffer(data1)); std::string data2; data2.resize(data1.size()); boost::asio::read(p1, boost::asio::buffer(data2)); BOOST_ASIO_CHECK(data1 == data2); char read_buffer[sizeof(write_data)]; bool read_completed = false; boost::asio::async_read(p1, boost::asio::buffer(read_buffer), bindns::bind(handle_read, _1, _2, &read_completed)); bool write_completed = false; boost::asio::async_write(p2, boost::asio::buffer(write_data), bindns::bind(handle_write, _1, _2, &write_completed)); io_context.run(); BOOST_ASIO_CHECK(read_completed); BOOST_ASIO_CHECK(write_completed); BOOST_ASIO_CHECK(memcmp(read_buffer, write_data, sizeof(write_data)) == 0); } catch (std::exception&) { BOOST_ASIO_CHECK(false); } #endif // defined(BOOST_ASIO_HAS_PIPE) } } // namespace connect_pipe_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "connect_pipe", BOOST_ASIO_COMPILE_TEST_CASE(connect_pipe_compile::test) BOOST_ASIO_TEST_CASE(connect_pipe_runtime::test) )
cpp
asio
data/projects/asio/test/detached.cpp
// // detached.cpp // ~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/detached.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "detached", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/prepend.cpp
// // prepend.cpp // ~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/prepend.hpp> #include <boost/asio/bind_executor.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/system_timer.hpp> #include "unit_test.hpp" void prepend_test() { boost::asio::io_context io1; boost::asio::io_context io2; boost::asio::system_timer timer1(io1); int count = 0; timer1.expires_after(boost::asio::chrono::seconds(0)); timer1.async_wait( boost::asio::prepend( boost::asio::bind_executor(io2.get_executor(), [&count](int a, int b, boost::system::error_code) { ++count; BOOST_ASIO_CHECK(a == 123); BOOST_ASIO_CHECK(b == 321); }), 123, 321)); BOOST_ASIO_CHECK(count == 0); io1.run(); BOOST_ASIO_CHECK(count == 0); io2.run(); BOOST_ASIO_CHECK(count == 1); } BOOST_ASIO_TEST_SUITE ( "prepend", BOOST_ASIO_TEST_CASE(prepend_test) )
cpp
asio
data/projects/asio/test/system_context.cpp
// // system_context.cpp // ~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Prevent link dependency on the Boost.System library. #if !defined(BOOST_SYSTEM_NO_DEPRECATED) #define BOOST_SYSTEM_NO_DEPRECATED #endif // !defined(BOOST_SYSTEM_NO_DEPRECATED) // Test that header file is self-contained. #include <boost/asio/system_context.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "system_context", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/redirect_error.cpp
// // redirect_error.cpp // ~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/redirect_error.hpp> #include <boost/asio/bind_executor.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/system_timer.hpp> #include <boost/asio/use_future.hpp> #include "unit_test.hpp" struct redirect_error_handler { int* count_; explicit redirect_error_handler(int* c) : count_(c) { } void operator()() { ++(*count_); } }; void redirect_error_test() { boost::asio::io_context io1; boost::asio::io_context io2; boost::asio::system_timer timer1(io1); boost::system::error_code ec = boost::asio::error::would_block; int count = 0; timer1.expires_after(boost::asio::chrono::seconds(0)); timer1.async_wait( boost::asio::redirect_error( boost::asio::bind_executor(io2.get_executor(), redirect_error_handler(&count)), ec)); BOOST_ASIO_CHECK(ec == boost::asio::error::would_block); BOOST_ASIO_CHECK(count == 0); io1.run(); BOOST_ASIO_CHECK(ec == boost::asio::error::would_block); BOOST_ASIO_CHECK(count == 0); io2.run(); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(count == 1); ec = boost::asio::error::would_block; timer1.async_wait( boost::asio::redirect_error( boost::asio::bind_executor(io2.get_executor(), boost::asio::deferred), ec))(redirect_error_handler(&count)); BOOST_ASIO_CHECK(ec == boost::asio::error::would_block); BOOST_ASIO_CHECK(count == 1); io1.restart(); io1.run(); BOOST_ASIO_CHECK(ec == boost::asio::error::would_block); BOOST_ASIO_CHECK(count == 1); io2.restart(); io2.run(); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(count == 2); #if defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) ec = boost::asio::error::would_block; std::future<void> f = timer1.async_wait( boost::asio::redirect_error( boost::asio::bind_executor(io2.get_executor(), boost::asio::use_future), ec)); BOOST_ASIO_CHECK(ec == boost::asio::error::would_block); BOOST_ASIO_CHECK(f.wait_for(std::chrono::seconds(0)) == std::future_status::timeout); io1.restart(); io1.run(); BOOST_ASIO_CHECK(ec == boost::asio::error::would_block); BOOST_ASIO_CHECK(f.wait_for(std::chrono::seconds(0)) == std::future_status::timeout); io2.restart(); io2.run(); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(f.wait_for(std::chrono::seconds(0)) == std::future_status::ready); #endif // defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) } BOOST_ASIO_TEST_SUITE ( "redirect_error", BOOST_ASIO_TEST_CASE(redirect_error_test) )
cpp
asio
data/projects/asio/test/random_access_file.cpp
// // random_access_file.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/random_access_file.hpp> #include "archetypes/async_result.hpp" #include <boost/asio/io_context.hpp> #include "unit_test.hpp" // random_access_file_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // random_access_file compile and link correctly. Runtime failures are ignored. namespace random_access_file_compile { struct write_some_at_handler { write_some_at_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} write_some_at_handler(write_some_at_handler&&) {} private: write_some_at_handler(const write_some_at_handler&); }; struct read_some_at_handler { read_some_at_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} read_some_at_handler(read_some_at_handler&&) {} private: read_some_at_handler(const read_some_at_handler&); }; void test() { #if defined(BOOST_ASIO_HAS_FILE) using namespace boost::asio; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; archetypes::lazy_handler lazy; boost::system::error_code ec; const std::string path; // basic_random_access_file constructors. random_access_file file1(ioc); random_access_file file2(ioc, "", random_access_file::read_only); random_access_file file3(ioc, path, random_access_file::read_only); random_access_file::native_handle_type native_file1 = file1.native_handle(); random_access_file file4(ioc, native_file1); random_access_file file5(ioc_ex); random_access_file file6(ioc_ex, "", random_access_file::read_only); random_access_file file7(ioc_ex, path, random_access_file::read_only); random_access_file::native_handle_type native_file2 = file1.native_handle(); random_access_file file8(ioc_ex, native_file2); random_access_file file9(std::move(file8)); basic_random_access_file<io_context::executor_type> file10(ioc); random_access_file file11(std::move(file10)); // basic_random_access_file operators. file1 = random_access_file(ioc); file1 = std::move(file2); file1 = std::move(file10); // basic_io_object functions. random_access_file::executor_type ex = file1.get_executor(); (void)ex; // basic_random_access_file functions. file1.open("", random_access_file::read_only); file1.open("", random_access_file::read_only, ec); file1.open(path, random_access_file::read_only); file1.open(path, random_access_file::read_only, ec); random_access_file::native_handle_type native_file3 = file1.native_handle(); file1.assign(native_file3); random_access_file::native_handle_type native_file4 = file1.native_handle(); file1.assign(native_file4, ec); bool is_open = file1.is_open(); (void)is_open; file1.close(); file1.close(ec); random_access_file::native_handle_type native_file5 = file1.native_handle(); (void)native_file5; random_access_file::native_handle_type native_file6 = file1.release(); (void)native_file6; random_access_file::native_handle_type native_file7 = file1.release(ec); (void)native_file7; file1.cancel(); file1.cancel(ec); boost::asio::uint64_t s1 = file1.size(); (void)s1; boost::asio::uint64_t s2 = file1.size(ec); (void)s2; file1.resize(boost::asio::uint64_t(0)); file1.resize(boost::asio::uint64_t(0), ec); file1.sync_all(); file1.sync_all(ec); file1.sync_data(); file1.sync_data(ec); file1.write_some_at(0, buffer(mutable_char_buffer)); file1.write_some_at(0, buffer(const_char_buffer)); file1.write_some_at(0, buffer(mutable_char_buffer), ec); file1.write_some_at(0, buffer(const_char_buffer), ec); file1.async_write_some_at(0, buffer(mutable_char_buffer), write_some_at_handler()); file1.async_write_some_at(0, buffer(const_char_buffer), write_some_at_handler()); int i1 = file1.async_write_some_at(0, buffer(mutable_char_buffer), lazy); (void)i1; int i2 = file1.async_write_some_at(0, buffer(const_char_buffer), lazy); (void)i2; file1.read_some_at(0, buffer(mutable_char_buffer)); file1.read_some_at(0, buffer(mutable_char_buffer), ec); file1.async_read_some_at(0, buffer(mutable_char_buffer), read_some_at_handler()); int i3 = file1.async_read_some_at(0, buffer(mutable_char_buffer), lazy); (void)i3; } catch (std::exception&) { } #endif // defined(BOOST_ASIO_HAS_FILE) } } // namespace random_access_file_compile BOOST_ASIO_TEST_SUITE ( "random_access_file", BOOST_ASIO_COMPILE_TEST_CASE(random_access_file_compile::test) )
cpp
asio
data/projects/asio/test/unit_test.hpp
// // unit_test.hpp // ~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 UNIT_TEST_HPP #define UNIT_TEST_HPP #include <boost/asio/detail/config.hpp> #include <iostream> #include <boost/asio/detail/atomic_count.hpp> #if defined(__sun) # include <stdlib.h> // Needed for lrand48. #endif // defined(__sun) #if defined(__BORLANDC__) && !defined(__clang__) // Prevent use of intrinsic for strcmp. # include <cstring> # undef strcmp // Suppress error about condition always being true. # pragma option -w-ccc #endif // defined(__BORLANDC__) && !defined(__clang__) #if defined(BOOST_ASIO_MSVC) # pragma warning (disable:4127) # pragma warning (push) # pragma warning (disable:4244) # pragma warning (disable:4702) #endif // defined(BOOST_ASIO_MSVC) #if !defined(BOOST_ASIO_TEST_IOSTREAM) # define BOOST_ASIO_TEST_IOSTREAM std::cerr #endif // !defined(BOOST_ASIO_TEST_IOSTREAM) namespace boost { namespace asio { namespace detail { inline const char*& test_name() { static const char* name = 0; return name; } inline atomic_count& test_errors() { static atomic_count errors(0); return errors; } inline void begin_test_suite(const char* name) { boost::asio::detail::test_name(); boost::asio::detail::test_errors(); BOOST_ASIO_TEST_IOSTREAM << name << " test suite begins" << std::endl; } inline int end_test_suite(const char* name) { BOOST_ASIO_TEST_IOSTREAM << name << " test suite ends" << std::endl; BOOST_ASIO_TEST_IOSTREAM << "\n*** "; long errors = boost::asio::detail::test_errors(); if (errors == 0) BOOST_ASIO_TEST_IOSTREAM << "No errors detected."; else if (errors == 1) BOOST_ASIO_TEST_IOSTREAM << "1 error detected."; else BOOST_ASIO_TEST_IOSTREAM << errors << " errors detected." << std::endl; BOOST_ASIO_TEST_IOSTREAM << std::endl; return errors == 0 ? 0 : 1; } template <void (*Test)()> inline void run_test(const char* name) { test_name() = name; long errors_before = boost::asio::detail::test_errors(); Test(); if (test_errors() == errors_before) BOOST_ASIO_TEST_IOSTREAM << name << " passed" << std::endl; else BOOST_ASIO_TEST_IOSTREAM << name << " failed" << std::endl; } template <void (*)()> inline void compile_test(const char* name) { BOOST_ASIO_TEST_IOSTREAM << name << " passed" << std::endl; } #if defined(BOOST_ASIO_NO_EXCEPTIONS) template <typename T> void throw_exception(const T& t) { BOOST_ASIO_TEST_IOSTREAM << "Exception: " << t.what() << std::endl; std::abort(); } #endif // defined(BOOST_ASIO_NO_EXCEPTIONS) } // namespace detail } // namespace asio } // namespace boost #define BOOST_ASIO_CHECK(expr) \ do { if (!(expr)) { \ BOOST_ASIO_TEST_IOSTREAM << __FILE__ << "(" << __LINE__ << "): " \ << boost::asio::detail::test_name() << ": " \ << "check '" << #expr << "' failed" << std::endl; \ ++boost::asio::detail::test_errors(); \ } } while (0) #define BOOST_ASIO_CHECK_MESSAGE(expr, msg) \ do { if (!(expr)) { \ BOOST_ASIO_TEST_IOSTREAM << __FILE__ << "(" << __LINE__ << "): " \ << boost::asio::detail::test_name() << ": " \ << msg << std::endl; \ ++boost::asio::detail::test_errors(); \ } } while (0) #define BOOST_ASIO_WARN_MESSAGE(expr, msg) \ do { if (!(expr)) { \ BOOST_ASIO_TEST_IOSTREAM << __FILE__ << "(" << __LINE__ << "): " \ << boost::asio::detail::test_name() << ": " \ << msg << std::endl; \ } } while (0) #define BOOST_ASIO_ERROR(msg) \ do { \ BOOST_ASIO_TEST_IOSTREAM << __FILE__ << "(" << __LINE__ << "): " \ << boost::asio::detail::test_name() << ": " \ << msg << std::endl; \ ++boost::asio::detail::test_errors(); \ } while (0) #define BOOST_ASIO_TEST_SUITE(name, tests) \ int main() \ { \ boost::asio::detail::begin_test_suite(name); \ tests \ return boost::asio::detail::end_test_suite(name); \ } #define BOOST_ASIO_TEST_CASE(test) \ boost::asio::detail::run_test<&test>(#test); #define BOOST_ASIO_TEST_CASE2(test1, test2) \ boost::asio::detail::run_test<&test1, test2>(#test1 "," #test2); #define BOOST_ASIO_TEST_CASE3(test1, test2, test3) \ boost::asio::detail::run_test<&test1, test2, test3>( \ #test1 "," #test2 "," #test3); #define BOOST_ASIO_TEST_CASE4(test1, test2, test3, test4) \ boost::asio::detail::run_test<&test1, test2, test3, test4>( \ #test1 "," #test2 "," #test3 "," #test4); #define BOOST_ASIO_TEST_CASE5(test1, test2, test3, test4, test5) \ boost::asio::detail::run_test<&test1, test2, test3, test4, test5>( \ #test1 "," #test2 "," #test3 "," #test4 "," #test5); #define BOOST_ASIO_COMPILE_TEST_CASE(test) \ boost::asio::detail::compile_test<&test>(#test); inline void null_test() { } #if defined(__GNUC__) && defined(_AIX) // AIX needs this symbol defined in asio, even if it doesn't do anything. int test_main(int, char**) { } #endif // defined(__GNUC__) && defined(_AIX) #if defined(BOOST_ASIO_MSVC) # pragma warning (pop) #endif // defined(BOOST_ASIO_MSVC) #endif // UNIT_TEST_HPP
hpp
asio
data/projects/asio/test/associated_cancellation_slot.cpp
// // associated_cancellation_slot.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/associated_cancellation_slot.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "associated_cancellation_slot", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/bind_cancellation_slot.cpp
// // bind_cancellation_slot.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/bind_cancellation_slot.hpp> #include <functional> #include <boost/asio/cancellation_signal.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/steady_timer.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) # include <boost/asio/deadline_timer.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) # include <boost/asio/steady_timer.hpp> #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) using namespace boost::asio; namespace bindns = std; #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) typedef deadline_timer timer; namespace chronons = boost::posix_time; #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) typedef steady_timer timer; namespace chronons = boost::asio::chrono; #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) void increment_on_cancel(int* count, const boost::system::error_code& error) { if (error == boost::asio::error::operation_aborted) ++(*count); } void bind_cancellation_slot_to_function_object_test() { io_context ioc; cancellation_signal sig; int count = 0; timer t(ioc, chronons::seconds(5)); t.async_wait( bind_cancellation_slot(sig.slot(), bindns::bind(&increment_on_cancel, &count, bindns::placeholders::_1))); ioc.poll(); BOOST_ASIO_CHECK(count == 0); sig.emit(boost::asio::cancellation_type::all); ioc.run(); BOOST_ASIO_CHECK(count == 1); t.async_wait( bind_cancellation_slot(sig.slot(), bind_cancellation_slot(sig.slot(), bindns::bind(&increment_on_cancel, &count, bindns::placeholders::_1)))); ioc.restart(); ioc.poll(); BOOST_ASIO_CHECK(count == 1); sig.emit(boost::asio::cancellation_type::all); ioc.run(); BOOST_ASIO_CHECK(count == 2); } struct incrementer_token_v1 { explicit incrementer_token_v1(int* c) : count(c) {} int* count; }; struct incrementer_handler_v1 { explicit incrementer_handler_v1(incrementer_token_v1 t) : count(t.count) {} void operator()(boost::system::error_code error) { increment_on_cancel(count, error); } int* count; }; namespace boost { namespace asio { template <> class async_result<incrementer_token_v1, void(boost::system::error_code)> { public: typedef incrementer_handler_v1 completion_handler_type; typedef void return_type; explicit async_result(completion_handler_type&) {} return_type get() {} }; } // namespace asio } // namespace boost void bind_cancellation_slot_to_completion_token_v1_test() { io_context ioc; cancellation_signal sig; int count = 0; timer t(ioc, chronons::seconds(5)); t.async_wait( bind_cancellation_slot(sig.slot(), incrementer_token_v1(&count))); ioc.poll(); BOOST_ASIO_CHECK(count == 0); sig.emit(boost::asio::cancellation_type::all); ioc.run(); BOOST_ASIO_CHECK(count == 1); } struct incrementer_token_v2 { explicit incrementer_token_v2(int* c) : count(c) {} int* count; }; namespace boost { namespace asio { template <> class async_result<incrementer_token_v2, void(boost::system::error_code)> { public: #if !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION) typedef void return_type; #endif // !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION) template <typename Initiation, typename... Args> static void initiate(Initiation initiation, incrementer_token_v2 token, Args&&... args) { initiation( bindns::bind(&increment_on_cancel, token.count, bindns::placeholders::_1), static_cast<Args&&>(args)...); } }; } // namespace asio } // namespace boost void bind_cancellation_slot_to_completion_token_v2_test() { io_context ioc; cancellation_signal sig; int count = 0; timer t(ioc, chronons::seconds(5)); t.async_wait( bind_cancellation_slot(sig.slot(), incrementer_token_v2(&count))); ioc.poll(); BOOST_ASIO_CHECK(count == 0); sig.emit(boost::asio::cancellation_type::all); ioc.run(); BOOST_ASIO_CHECK(count == 1); } BOOST_ASIO_TEST_SUITE ( "bind_cancellation_slot", BOOST_ASIO_TEST_CASE(bind_cancellation_slot_to_function_object_test) BOOST_ASIO_TEST_CASE(bind_cancellation_slot_to_completion_token_v1_test) BOOST_ASIO_TEST_CASE(bind_cancellation_slot_to_completion_token_v2_test) )
cpp
asio
data/projects/asio/test/wait_traits.cpp
// // wait_traits.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/wait_traits.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "wait_traits", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/cancellation_signal.cpp
// // cancellation_signal.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/cancellation_signal.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "cancellation_signal", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/readable_pipe.cpp
// // readable_pipe.cpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header pipe is self-contained. #include <boost/asio/readable_pipe.hpp> #include "archetypes/async_result.hpp" #include <boost/asio/io_context.hpp> #include "unit_test.hpp" // readable_pipe_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // readable_pipe compile and link correctly. Runtime failures are ignored. namespace readable_pipe_compile { struct write_some_handler { write_some_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} write_some_handler(write_some_handler&&) {} private: write_some_handler(const write_some_handler&); }; struct read_some_handler { read_some_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} read_some_handler(read_some_handler&&) {} private: read_some_handler(const read_some_handler&); }; void test() { #if defined(BOOST_ASIO_HAS_PIPE) using namespace boost::asio; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); char mutable_char_buffer[128] = ""; archetypes::lazy_handler lazy; boost::system::error_code ec; const std::string path; // basic_readable_pipe constructors. readable_pipe pipe1(ioc); readable_pipe::native_handle_type native_pipe1 = pipe1.native_handle(); readable_pipe pipe2(ioc, native_pipe1); readable_pipe pipe3(ioc_ex); readable_pipe::native_handle_type native_pipe2 = pipe1.native_handle(); readable_pipe pipe4(ioc_ex, native_pipe2); readable_pipe pipe5(std::move(pipe4)); basic_readable_pipe<io_context::executor_type> pipe6(ioc); readable_pipe pipe7(std::move(pipe6)); // basic_readable_pipe operators. pipe1 = readable_pipe(ioc); pipe1 = std::move(pipe2); pipe1 = std::move(pipe6); // basic_io_object functions. readable_pipe::executor_type ex = pipe1.get_executor(); (void)ex; // basic_readable_pipe functions. readable_pipe::native_handle_type native_pipe3 = pipe1.native_handle(); pipe1.assign(native_pipe3); readable_pipe::native_handle_type native_pipe4 = pipe1.native_handle(); pipe1.assign(native_pipe4, ec); bool is_open = pipe1.is_open(); (void)is_open; pipe1.close(); pipe1.close(ec); readable_pipe::native_handle_type native_pipe5 = pipe1.release(); (void)native_pipe5; readable_pipe::native_handle_type native_pipe6 = pipe1.release(ec); (void)native_pipe6; readable_pipe::native_handle_type native_pipe7 = pipe1.native_handle(); (void)native_pipe7; pipe1.cancel(); pipe1.cancel(ec); pipe1.read_some(buffer(mutable_char_buffer)); pipe1.read_some(buffer(mutable_char_buffer), ec); pipe1.async_read_some(buffer(mutable_char_buffer), read_some_handler()); int i3 = pipe1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i3; } catch (std::exception&) { } #endif // defined(BOOST_ASIO_HAS_PIPE) } } // namespace readable_pipe_compile BOOST_ASIO_TEST_SUITE ( "readable_pipe", BOOST_ASIO_COMPILE_TEST_CASE(readable_pipe_compile::test) )
cpp
asio
data/projects/asio/test/use_future.cpp
// // use_future.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/use_future.hpp> #include <string> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) #include "archetypes/async_ops.hpp" void use_future_0_test() { using boost::asio::use_future; using namespace archetypes; std::future<void> f; f = async_op_0(use_future); try { f.get(); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_0(true, use_future); try { f.get(); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_0(false, use_future); try { f.get(); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_0(true, use_future); try { f.get(); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_0(false, use_future); try { f.get(); BOOST_ASIO_CHECK(false); } catch (std::exception& e) { BOOST_ASIO_CHECK(e.what() == std::string("blah")); } catch (...) { BOOST_ASIO_CHECK(false); } } void use_future_1_test() { using boost::asio::use_future; using namespace archetypes; std::future<int> f; f = async_op_1(use_future); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_1(true, use_future); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_1(false, use_future); try { int i = f.get(); BOOST_ASIO_CHECK(false); (void)i; } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_1(true, use_future); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_1(false, use_future); try { int i = f.get(); BOOST_ASIO_CHECK(false); (void)i; } catch (std::exception& e) { BOOST_ASIO_CHECK(e.what() == std::string("blah")); } catch (...) { BOOST_ASIO_CHECK(false); } } void use_future_2_test() { using boost::asio::use_future; using namespace archetypes; std::future<std::tuple<int, double>> f; f = async_op_2(use_future); try { int i; double d; std::tie(i, d) = f.get(); BOOST_ASIO_CHECK(i == 42); BOOST_ASIO_CHECK(d == 2.0); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_2(true, use_future); try { int i; double d; std::tie(i, d) = f.get(); BOOST_ASIO_CHECK(i == 42); BOOST_ASIO_CHECK(d == 2.0); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_2(false, use_future); try { std::tuple<int, double> t = f.get(); BOOST_ASIO_CHECK(false); (void)t; } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_2(true, use_future); try { int i; double d; std::tie(i, d) = f.get(); BOOST_ASIO_CHECK(i == 42); BOOST_ASIO_CHECK(d == 2.0); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_2(false, use_future); try { std::tuple<int, double> t = f.get(); BOOST_ASIO_CHECK(false); (void)t; } catch (std::exception& e) { BOOST_ASIO_CHECK(e.what() == std::string("blah")); } catch (...) { BOOST_ASIO_CHECK(false); } } void use_future_3_test() { using boost::asio::use_future; using namespace archetypes; std::future<std::tuple<int, double, char>> f; f = async_op_3(use_future); try { int i; double d; char c; std::tie(i, d, c) = f.get(); BOOST_ASIO_CHECK(i == 42); BOOST_ASIO_CHECK(d == 2.0); BOOST_ASIO_CHECK(c == 'a'); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_3(true, use_future); try { int i; double d; char c; std::tie(i, d, c) = f.get(); BOOST_ASIO_CHECK(i == 42); BOOST_ASIO_CHECK(d == 2.0); BOOST_ASIO_CHECK(c == 'a'); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_3(false, use_future); try { std::tuple<int, double, char> t = f.get(); BOOST_ASIO_CHECK(false); (void)t; } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_3(true, use_future); try { int i; double d; char c; std::tie(i, d, c) = f.get(); BOOST_ASIO_CHECK(i == 42); BOOST_ASIO_CHECK(d == 2.0); BOOST_ASIO_CHECK(c == 'a'); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_3(false, use_future); try { std::tuple<int, double, char> t = f.get(); BOOST_ASIO_CHECK(false); (void)t; } catch (std::exception& e) { BOOST_ASIO_CHECK(e.what() == std::string("blah")); } catch (...) { BOOST_ASIO_CHECK(false); } } int package_0() { return 42; } int package_ec_0(boost::system::error_code ec) { return ec ? 0 : 42; } int package_ex_0(std::exception_ptr ex) { return ex ? 0 : 42; } void use_future_package_0_test() { using boost::asio::use_future; using namespace archetypes; std::future<int> f; f = async_op_0(use_future(package_0)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_0(true, use_future(&package_ec_0)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_0(false, use_future(package_ec_0)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 0); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_0(true, use_future(package_ex_0)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_0(false, use_future(package_ex_0)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 0); } catch (...) { BOOST_ASIO_CHECK(false); } } int package_1(int i) { return i; } int package_ec_1(boost::system::error_code ec, int i) { return ec ? 0 : i; } int package_ex_1(std::exception_ptr ex, int i) { return ex ? 0 : i; } void use_future_package_1_test() { using boost::asio::use_future; using namespace archetypes; std::future<int> f; f = async_op_1(use_future(package_1)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_1(true, use_future(package_ec_1)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_1(false, use_future(package_ec_1)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 0); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_1(true, use_future(package_ex_1)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_1(false, use_future(package_ex_1)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 0); } catch (...) { BOOST_ASIO_CHECK(false); } } int package_2(int i, double) { return i; } int package_ec_2(boost::system::error_code ec, int i, double) { return ec ? 0 : i; } int package_ex_2(std::exception_ptr ex, int i, double) { return ex ? 0 : i; } void use_future_package_2_test() { using boost::asio::use_future; using namespace archetypes; std::future<int> f; f = async_op_2(use_future(package_2)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_2(true, use_future(package_ec_2)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_2(false, use_future(package_ec_2)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 0); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_2(true, use_future(package_ex_2)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_2(false, use_future(package_ex_2)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 0); } catch (...) { BOOST_ASIO_CHECK(false); } } int package_3(int i, double, char) { return i; } int package_ec_3(boost::system::error_code ec, int i, double, char) { return ec ? 0 : i; } int package_ex_3(std::exception_ptr ex, int i, double, char) { return ex ? 0 : i; } void use_future_package_3_test() { using boost::asio::use_future; using namespace archetypes; std::future<int> f; f = async_op_3(use_future(package_3)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_3(true, use_future(package_ec_3)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ec_3(false, use_future(package_ec_3)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 0); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_3(true, use_future(package_ex_3)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 42); } catch (...) { BOOST_ASIO_CHECK(false); } f = async_op_ex_3(false, use_future(package_ex_3)); try { int i = f.get(); BOOST_ASIO_CHECK(i == 0); } catch (...) { BOOST_ASIO_CHECK(false); } } BOOST_ASIO_TEST_SUITE ( "use_future", BOOST_ASIO_TEST_CASE(use_future_0_test) BOOST_ASIO_TEST_CASE(use_future_1_test) BOOST_ASIO_TEST_CASE(use_future_2_test) BOOST_ASIO_TEST_CASE(use_future_3_test) BOOST_ASIO_TEST_CASE(use_future_package_0_test) BOOST_ASIO_TEST_CASE(use_future_package_1_test) BOOST_ASIO_TEST_CASE(use_future_package_2_test) BOOST_ASIO_TEST_CASE(use_future_package_3_test) ) #else // defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) BOOST_ASIO_TEST_SUITE ( "use_future", BOOST_ASIO_TEST_CASE(null_test) ) #endif // defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS)
cpp
asio
data/projects/asio/test/this_coro.cpp
// // this_coro.cpp // ~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/this_coro.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "this_coro", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/buffer_registration.cpp
// // buffer_registration.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/buffer_registration.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "buffer_registration", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/basic_readable_pipe.cpp
// // basic_readable_pipe.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_readable_pipe.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_readable_pipe", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/system_timer.cpp
// // system_timer.cpp // ~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Prevent link dependency on the Boost.System library. #if !defined(BOOST_SYSTEM_NO_DEPRECATED) #define BOOST_SYSTEM_NO_DEPRECATED #endif // !defined(BOOST_SYSTEM_NO_DEPRECATED) // Test that header file is self-contained. #include <boost/asio/system_timer.hpp> #include <functional> #include <boost/asio/bind_cancellation_slot.hpp> #include <boost/asio/cancellation_signal.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/detail/thread.hpp> #include "unit_test.hpp" namespace bindns = std; void increment(int* count) { ++(*count); } void decrement_to_zero(boost::asio::system_timer* t, int* count) { if (*count > 0) { --(*count); int before_value = *count; t->expires_at(t->expiry() + boost::asio::chrono::seconds(1)); t->async_wait(bindns::bind(decrement_to_zero, t, count)); // Completion cannot nest, so count value should remain unchanged. BOOST_ASIO_CHECK(*count == before_value); } } void increment_if_not_cancelled(int* count, const boost::system::error_code& ec) { if (!ec) ++(*count); } void cancel_timer(boost::asio::system_timer* t) { std::size_t num_cancelled = t->cancel(); BOOST_ASIO_CHECK(num_cancelled == 1); } void cancel_one_timer(boost::asio::system_timer* t) { std::size_t num_cancelled = t->cancel_one(); BOOST_ASIO_CHECK(num_cancelled == 1); } boost::asio::system_timer::time_point now() { return boost::asio::system_timer::clock_type::now(); } void system_timer_test() { using boost::asio::chrono::seconds; using boost::asio::chrono::microseconds; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; const boost::asio::io_context::executor_type ioc_ex = ioc.get_executor(); int count = 0; boost::asio::system_timer::time_point start = now(); boost::asio::system_timer t1(ioc, seconds(1)); t1.wait(); // The timer must block until after its expiry time. boost::asio::system_timer::time_point end = now(); boost::asio::system_timer::time_point expected_end = start + seconds(1); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); start = now(); boost::asio::system_timer t2(ioc_ex, seconds(1) + microseconds(500000)); t2.wait(); // The timer must block until after its expiry time. end = now(); expected_end = start + seconds(1) + microseconds(500000); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); t2.expires_at(t2.expiry() + seconds(1)); t2.wait(); // The timer must block until after its expiry time. end = now(); expected_end += seconds(1); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); start = now(); t2.expires_after(seconds(1) + microseconds(200000)); t2.wait(); // The timer must block until after its expiry time. end = now(); expected_end = start + seconds(1) + microseconds(200000); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); start = now(); boost::asio::system_timer t3(ioc, seconds(5)); t3.async_wait(bindns::bind(increment, &count)); // No completions can be delivered until run() is called. BOOST_ASIO_CHECK(count == 0); ioc.run(); // The run() call will not return until all operations have finished, and // this should not be until after the timer's expiry time. BOOST_ASIO_CHECK(count == 1); end = now(); expected_end = start + seconds(1); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); count = 3; start = now(); boost::asio::system_timer t4(ioc, seconds(1)); t4.async_wait(bindns::bind(decrement_to_zero, &t4, &count)); // No completions can be delivered until run() is called. BOOST_ASIO_CHECK(count == 3); ioc.restart(); ioc.run(); // The run() call will not return until all operations have finished, and // this should not be until after the timer's final expiry time. BOOST_ASIO_CHECK(count == 0); end = now(); expected_end = start + seconds(3); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); count = 0; start = now(); boost::asio::system_timer t5(ioc, seconds(10)); t5.async_wait(bindns::bind(increment_if_not_cancelled, &count, _1)); boost::asio::system_timer t6(ioc, seconds(1)); t6.async_wait(bindns::bind(cancel_timer, &t5)); // No completions can be delivered until run() is called. BOOST_ASIO_CHECK(count == 0); ioc.restart(); ioc.run(); // The timer should have been cancelled, so count should not have changed. // The total run time should not have been much more than 1 second (and // certainly far less than 10 seconds). BOOST_ASIO_CHECK(count == 0); end = now(); expected_end = start + seconds(2); BOOST_ASIO_CHECK(end < expected_end); // Wait on the timer again without cancelling it. This time the asynchronous // wait should run to completion and increment the counter. t5.async_wait(bindns::bind(increment_if_not_cancelled, &count, _1)); ioc.restart(); ioc.run(); // The timer should not have been cancelled, so count should have changed. // The total time since the timer was created should be more than 10 seconds. BOOST_ASIO_CHECK(count == 1); end = now(); expected_end = start + seconds(10); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); count = 0; start = now(); // Start two waits on a timer, one of which will be cancelled. The one // which is not cancelled should still run to completion and increment the // counter. boost::asio::system_timer t7(ioc, seconds(3)); t7.async_wait(bindns::bind(increment_if_not_cancelled, &count, _1)); t7.async_wait(bindns::bind(increment_if_not_cancelled, &count, _1)); boost::asio::system_timer t8(ioc, seconds(1)); t8.async_wait(bindns::bind(cancel_one_timer, &t7)); ioc.restart(); ioc.run(); // One of the waits should not have been cancelled, so count should have // changed. The total time since the timer was created should be more than 3 // seconds. BOOST_ASIO_CHECK(count == 1); end = now(); expected_end = start + seconds(3); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); } struct timer_handler { timer_handler() {} void operator()(const boost::system::error_code&) {} timer_handler(timer_handler&&) {} private: timer_handler(const timer_handler&); }; void system_timer_cancel_test() { static boost::asio::io_context io_context; struct timer { boost::asio::system_timer t; timer() : t(io_context) { t.expires_at((boost::asio::system_timer::time_point::max)()); } } timers[50]; timers[2].t.async_wait(timer_handler()); timers[41].t.async_wait(timer_handler()); for (int i = 10; i < 20; ++i) timers[i].t.async_wait(timer_handler()); BOOST_ASIO_CHECK(timers[2].t.cancel() == 1); BOOST_ASIO_CHECK(timers[41].t.cancel() == 1); for (int i = 10; i < 20; ++i) BOOST_ASIO_CHECK(timers[i].t.cancel() == 1); } struct custom_allocation_timer_handler { custom_allocation_timer_handler(int* count) : count_(count) {} void operator()(const boost::system::error_code&) {} int* count_; template <typename T> struct allocator { typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; typedef T value_type; template <typename U> struct rebind { typedef allocator<U> other; }; explicit allocator(int* count) noexcept : count_(count) { } allocator(const allocator& other) noexcept : count_(other.count_) { } template <typename U> allocator(const allocator<U>& other) noexcept : count_(other.count_) { } pointer allocate(size_type n, const void* = 0) { ++(*count_); return static_cast<T*>(::operator new(sizeof(T) * n)); } void deallocate(pointer p, size_type) { --(*count_); ::operator delete(p); } size_type max_size() const { return ~size_type(0); } void construct(pointer p, const T& v) { new (p) T(v); } void destroy(pointer p) { p->~T(); } int* count_; }; typedef allocator<int> allocator_type; allocator_type get_allocator() const noexcept { return allocator_type(count_); } }; void system_timer_custom_allocation_test() { static boost::asio::io_context io_context; struct timer { boost::asio::system_timer t; timer() : t(io_context) {} } timers[100]; int allocation_count = 0; for (int i = 0; i < 50; ++i) { timers[i].t.expires_at((boost::asio::system_timer::time_point::max)()); timers[i].t.async_wait(custom_allocation_timer_handler(&allocation_count)); } for (int i = 50; i < 100; ++i) { timers[i].t.expires_at((boost::asio::system_timer::time_point::min)()); timers[i].t.async_wait(custom_allocation_timer_handler(&allocation_count)); } for (int i = 0; i < 50; ++i) timers[i].t.cancel(); io_context.run(); BOOST_ASIO_CHECK(allocation_count == 0); } void io_context_run(boost::asio::io_context* ioc) { ioc->run(); } void system_timer_thread_test() { boost::asio::io_context ioc; boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work = boost::asio::make_work_guard(ioc); boost::asio::system_timer t1(ioc); boost::asio::system_timer t2(ioc); int count = 0; boost::asio::detail::thread th(bindns::bind(io_context_run, &ioc)); t2.expires_after(boost::asio::chrono::seconds(2)); t2.wait(); t1.expires_after(boost::asio::chrono::seconds(2)); t1.async_wait(bindns::bind(increment, &count)); t2.expires_after(boost::asio::chrono::seconds(4)); t2.wait(); ioc.stop(); th.join(); BOOST_ASIO_CHECK(count == 1); } boost::asio::system_timer make_timer(boost::asio::io_context& ioc, int* count) { boost::asio::system_timer t(ioc); t.expires_after(boost::asio::chrono::seconds(1)); t.async_wait(bindns::bind(increment, count)); return t; } typedef boost::asio::basic_waitable_timer< boost::asio::system_timer::clock_type, boost::asio::system_timer::traits_type, boost::asio::io_context::executor_type> io_context_system_timer; io_context_system_timer make_convertible_timer(boost::asio::io_context& ioc, int* count) { io_context_system_timer t(ioc); t.expires_after(boost::asio::chrono::seconds(1)); t.async_wait(bindns::bind(increment, count)); return t; } void system_timer_move_test() { boost::asio::io_context io_context1; boost::asio::io_context io_context2; int count = 0; boost::asio::system_timer t1 = make_timer(io_context1, &count); boost::asio::system_timer t2 = make_timer(io_context2, &count); boost::asio::system_timer t3 = std::move(t1); t2 = std::move(t1); io_context2.run(); BOOST_ASIO_CHECK(count == 1); io_context1.run(); BOOST_ASIO_CHECK(count == 2); boost::asio::system_timer t4 = make_convertible_timer(io_context1, &count); boost::asio::system_timer t5 = make_convertible_timer(io_context2, &count); boost::asio::system_timer t6 = std::move(t4); t2 = std::move(t4); io_context2.restart(); io_context2.run(); BOOST_ASIO_CHECK(count == 3); io_context1.restart(); io_context1.run(); BOOST_ASIO_CHECK(count == 4); } void system_timer_op_cancel_test() { boost::asio::cancellation_signal cancel_signal; boost::asio::io_context ioc; int count = 0; boost::asio::system_timer timer(ioc, boost::asio::chrono::seconds(10)); timer.async_wait(bindns::bind(increment, &count)); timer.async_wait( boost::asio::bind_cancellation_slot( cancel_signal.slot(), bindns::bind(increment, &count))); timer.async_wait(bindns::bind(increment, &count)); ioc.poll(); BOOST_ASIO_CHECK(count == 0); BOOST_ASIO_CHECK(!ioc.stopped()); cancel_signal.emit(boost::asio::cancellation_type::all); ioc.run_one(); ioc.poll(); BOOST_ASIO_CHECK(count == 1); BOOST_ASIO_CHECK(!ioc.stopped()); timer.cancel(); ioc.run(); BOOST_ASIO_CHECK(count == 3); BOOST_ASIO_CHECK(ioc.stopped()); } BOOST_ASIO_TEST_SUITE ( "system_timer", BOOST_ASIO_TEST_CASE(system_timer_test) BOOST_ASIO_TEST_CASE(system_timer_cancel_test) BOOST_ASIO_TEST_CASE(system_timer_custom_allocation_test) BOOST_ASIO_TEST_CASE(system_timer_thread_test) BOOST_ASIO_TEST_CASE(system_timer_move_test) BOOST_ASIO_TEST_CASE(system_timer_op_cancel_test) )
cpp
asio
data/projects/asio/test/basic_writable_pipe.cpp
// // basic_writable_pipe.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_writable_pipe.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_writable_pipe", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/stream_file.cpp
// // stream_file.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/stream_file.hpp> #include "archetypes/async_result.hpp" #include <boost/asio/io_context.hpp> #include "unit_test.hpp" // stream_file_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // stream_file compile and link correctly. Runtime failures are ignored. namespace stream_file_compile { struct write_some_handler { write_some_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} write_some_handler(write_some_handler&&) {} private: write_some_handler(const write_some_handler&); }; struct read_some_handler { read_some_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} read_some_handler(read_some_handler&&) {} private: read_some_handler(const read_some_handler&); }; void test() { #if defined(BOOST_ASIO_HAS_FILE) using namespace boost::asio; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; archetypes::lazy_handler lazy; boost::system::error_code ec; const std::string path; // basic_stream_file constructors. stream_file file1(ioc); stream_file file2(ioc, "", stream_file::read_only); stream_file file3(ioc, path, stream_file::read_only); stream_file::native_handle_type native_file1 = file1.native_handle(); stream_file file4(ioc, native_file1); stream_file file5(ioc_ex); stream_file file6(ioc_ex, "", stream_file::read_only); stream_file file7(ioc_ex, path, stream_file::read_only); stream_file::native_handle_type native_file2 = file1.native_handle(); stream_file file8(ioc_ex, native_file2); stream_file file9(std::move(file8)); basic_stream_file<io_context::executor_type> file10(ioc); stream_file file11(std::move(file10)); // basic_stream_file operators. file1 = stream_file(ioc); file1 = std::move(file2); file1 = std::move(file10); // basic_io_object functions. stream_file::executor_type ex = file1.get_executor(); (void)ex; // basic_stream_file functions. file1.open("", stream_file::read_only); file1.open("", stream_file::read_only, ec); file1.open(path, stream_file::read_only); file1.open(path, stream_file::read_only, ec); stream_file::native_handle_type native_file3 = file1.native_handle(); file1.assign(native_file3); stream_file::native_handle_type native_file4 = file1.native_handle(); file1.assign(native_file4, ec); bool is_open = file1.is_open(); (void)is_open; file1.close(); file1.close(ec); stream_file::native_handle_type native_file5 = file1.native_handle(); (void)native_file5; stream_file::native_handle_type native_file6 = file1.release(); (void)native_file6; stream_file::native_handle_type native_file7 = file1.release(ec); (void)native_file7; file1.cancel(); file1.cancel(ec); boost::asio::uint64_t s1 = file1.size(); (void)s1; boost::asio::uint64_t s2 = file1.size(ec); (void)s2; file1.resize(boost::asio::uint64_t(0)); file1.resize(boost::asio::uint64_t(0), ec); file1.sync_all(); file1.sync_all(ec); file1.sync_data(); file1.sync_data(ec); boost::asio::uint64_t s3 = file1.seek(0, stream_file::seek_set); (void)s3; boost::asio::uint64_t s4 = file1.seek(0, stream_file::seek_set, ec); (void)s4; file1.write_some(buffer(mutable_char_buffer)); file1.write_some(buffer(const_char_buffer)); file1.write_some(buffer(mutable_char_buffer), ec); file1.write_some(buffer(const_char_buffer), ec); file1.async_write_some(buffer(mutable_char_buffer), write_some_handler()); file1.async_write_some(buffer(const_char_buffer), write_some_handler()); int i1 = file1.async_write_some(buffer(mutable_char_buffer), lazy); (void)i1; int i2 = file1.async_write_some(buffer(const_char_buffer), lazy); (void)i2; file1.read_some(buffer(mutable_char_buffer)); file1.read_some(buffer(mutable_char_buffer), ec); file1.async_read_some(buffer(mutable_char_buffer), read_some_handler()); int i3 = file1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i3; } catch (std::exception&) { } #endif // defined(BOOST_ASIO_HAS_FILE) } } // namespace stream_file_compile BOOST_ASIO_TEST_SUITE ( "stream_file", BOOST_ASIO_COMPILE_TEST_CASE(stream_file_compile::test) )
cpp
asio
data/projects/asio/test/uses_executor.cpp
// // uses_executor.cpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/uses_executor.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "uses_executor", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/coroutine.cpp
// // coroutine.cpp // ~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/coroutine.hpp> #include "unit_test.hpp" // Must come after all other headers. #include <boost/asio/yield.hpp> //------------------------------------------------------------------------------ // Coroutine completes via yield break. void yield_break_coro(boost::asio::coroutine& coro) { reenter (coro) { yield return; yield break; } } void yield_break_test() { boost::asio::coroutine coro; BOOST_ASIO_CHECK(!coro.is_complete()); yield_break_coro(coro); BOOST_ASIO_CHECK(!coro.is_complete()); yield_break_coro(coro); BOOST_ASIO_CHECK(coro.is_complete()); } //------------------------------------------------------------------------------ // Coroutine completes via return. void return_coro(boost::asio::coroutine& coro) { reenter (coro) { return; } } void return_test() { boost::asio::coroutine coro; return_coro(coro); BOOST_ASIO_CHECK(coro.is_complete()); } //------------------------------------------------------------------------------ // Coroutine completes via exception. void exception_coro(boost::asio::coroutine& coro) { reenter (coro) { throw 1; } } void exception_test() { boost::asio::coroutine coro; try { exception_coro(coro); } catch (int) {} BOOST_ASIO_CHECK(coro.is_complete()); } //------------------------------------------------------------------------------ // Coroutine completes by falling off the end. void fall_off_end_coro(boost::asio::coroutine& coro) { reenter (coro) { } } void fall_off_end_test() { boost::asio::coroutine coro; fall_off_end_coro(coro); BOOST_ASIO_CHECK(coro.is_complete()); } //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "coroutine", BOOST_ASIO_TEST_CASE(yield_break_test) BOOST_ASIO_TEST_CASE(return_test) BOOST_ASIO_TEST_CASE(exception_test) BOOST_ASIO_TEST_CASE(fall_off_end_test) )
cpp
asio
data/projects/asio/test/read.cpp
// // read.cpp // ~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/read.hpp> #include <array> #include <cstring> #include <functional> #include <vector> #include "archetypes/async_result.hpp" #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/streambuf.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) #include <boost/array.hpp> #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using namespace std; // For memcmp, memcpy and memset. class test_stream { public: typedef boost::asio::io_context::executor_type executor_type; test_stream(boost::asio::io_context& io_context) : io_context_(io_context), length_(0), position_(0), next_read_length_(0) { } executor_type get_executor() noexcept { return io_context_.get_executor(); } void reset(const void* data, size_t length) { BOOST_ASIO_CHECK(length <= max_length); memcpy(data_, data, length); length_ = length; position_ = 0; next_read_length_ = length; } void next_read_length(size_t length) { next_read_length_ = length; } template <typename Iterator> bool check_buffers(Iterator begin, Iterator end, size_t length) { if (length != position_) return false; Iterator iter = begin; size_t checked_length = 0; for (; iter != end && checked_length < length; ++iter) { size_t buffer_length = boost::asio::buffer_size(*iter); if (buffer_length > length - checked_length) buffer_length = length - checked_length; if (memcmp(data_ + checked_length, iter->data(), buffer_length) != 0) return false; checked_length += buffer_length; } return true; } template <typename Const_Buffers> bool check_buffers(const Const_Buffers& buffers, size_t length) { return check_buffers(boost::asio::buffer_sequence_begin(buffers), boost::asio::buffer_sequence_end(buffers), length); } template <typename Mutable_Buffers> size_t read_some(const Mutable_Buffers& buffers) { size_t n = boost::asio::buffer_copy(buffers, boost::asio::buffer(data_, length_) + position_, next_read_length_); position_ += n; return n; } template <typename Mutable_Buffers> size_t read_some(const Mutable_Buffers& buffers, boost::system::error_code& ec) { ec = boost::system::error_code(); return read_some(buffers); } template <typename Mutable_Buffers, typename Handler> void async_read_some(const Mutable_Buffers& buffers, Handler&& handler) { size_t bytes_transferred = read_some(buffers); boost::asio::post(get_executor(), boost::asio::detail::bind_handler( static_cast<Handler&&>(handler), boost::system::error_code(), bytes_transferred)); } private: boost::asio::io_context& io_context_; enum { max_length = 8192 }; char data_[max_length]; size_t length_; size_t position_; size_t next_read_length_; }; static const char read_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; void test_2_arg_zero_buffers_read() { boost::asio::io_context ioc; test_stream s(ioc); std::vector<boost::asio::mutable_buffer> buffers; size_t bytes_transferred = boost::asio::read(s, buffers); BOOST_ASIO_CHECK(bytes_transferred == 0); } void test_2_arg_mutable_buffer_read() { boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; boost::asio::mutable_buffer buffers = boost::asio::buffer(read_buf, sizeof(read_buf)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); size_t bytes_transferred = boost::asio::read(s, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_2_arg_vector_buffers_read() { boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; std::vector<boost::asio::mutable_buffer> buffers; buffers.push_back(boost::asio::buffer(read_buf, 32)); buffers.push_back(boost::asio::buffer(read_buf, 39) + 32); buffers.push_back(boost::asio::buffer(read_buf) + 39); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); size_t bytes_transferred = boost::asio::read(s, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_2_arg_dynamic_string_read() { boost::asio::io_context ioc; test_stream s(ioc); std::string data; boost::asio::dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type> sb = boost::asio::dynamic_buffer(data, sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); size_t bytes_transferred = boost::asio::read(s, sb); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); } void test_2_arg_streambuf_read() { #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) boost::asio::io_context ioc; test_stream s(ioc); boost::asio::streambuf sb(sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); size_t bytes_transferred = boost::asio::read(s, sb); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) } void test_3_arg_nothrow_zero_buffers_read() { boost::asio::io_context ioc; test_stream s(ioc); std::vector<boost::asio::mutable_buffer> buffers; boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == 0); BOOST_ASIO_CHECK(!error); } void test_3_arg_nothrow_mutable_buffer_read() { boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; boost::asio::mutable_buffer buffers = boost::asio::buffer(read_buf, sizeof(read_buf)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); } void test_3_arg_nothrow_vector_buffers_read() { boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; std::vector<boost::asio::mutable_buffer> buffers; buffers.push_back(boost::asio::buffer(read_buf, 32)); buffers.push_back(boost::asio::buffer(read_buf, 39) + 32); buffers.push_back(boost::asio::buffer(read_buf) + 39); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); } void test_3_arg_nothrow_dynamic_string_read() { boost::asio::io_context ioc; test_stream s(ioc); std::string data; boost::asio::dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type> sb = boost::asio::dynamic_buffer(data, sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, sb, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); } void test_3_arg_nothrow_streambuf_read() { #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) boost::asio::io_context ioc; test_stream s(ioc); boost::asio::streambuf sb(sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, sb, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) } bool old_style_transfer_all(const boost::system::error_code& ec, size_t /*bytes_transferred*/) { return !!ec; } struct short_transfer { short_transfer() {} short_transfer(short_transfer&&) {} size_t operator()(const boost::system::error_code& ec, size_t /*bytes_transferred*/) { return !!ec ? 0 : 3; } }; void test_3_arg_mutable_buffer_read() { boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; boost::asio::mutable_buffer buffers = boost::asio::buffer(read_buf, sizeof(read_buf)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); size_t bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(buffers, 50)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_3_arg_vector_buffers_read() { boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; std::vector<boost::asio::mutable_buffer> buffers; buffers.push_back(boost::asio::buffer(read_buf, 32)); buffers.push_back(boost::asio::buffer(read_buf, 39) + 32); buffers.push_back(boost::asio::buffer(read_buf) + 39); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); size_t bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(buffers, 50)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_3_arg_dynamic_string_read() { boost::asio::io_context ioc; test_stream s(ioc); std::string data; boost::asio::dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type> sb = boost::asio::dynamic_buffer(data, sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); size_t bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(sb.size() == 50); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 50)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); } void test_3_arg_streambuf_read() { #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) boost::asio::io_context ioc; test_stream s(ioc); boost::asio::streambuf sb(sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); size_t bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42)); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(sb.size() == 50); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 50)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1)); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10)); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42)); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, short_transfer()); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) } void test_4_arg_mutable_buffer_read() { boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; boost::asio::mutable_buffer buffers = boost::asio::buffer(read_buf, sizeof(read_buf)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(buffers, 50)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); } void test_4_arg_vector_buffers_read() { boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; std::vector<boost::asio::mutable_buffer> buffers; buffers.push_back(boost::asio::buffer(read_buf, 32)); buffers.push_back(boost::asio::buffer(read_buf, 39) + 32); buffers.push_back(boost::asio::buffer(read_buf) + 39); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(s.check_buffers(buffers, 50)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bytes_transferred = boost::asio::read(s, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, buffers, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); BOOST_ASIO_CHECK(!error); } void test_4_arg_dynamic_string_read() { boost::asio::io_context ioc; test_stream s(ioc); std::string data; boost::asio::dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type> sb = boost::asio::dynamic_buffer(data, sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(sb.size() == 50); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 50)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); BOOST_ASIO_CHECK(!error); } void test_4_arg_streambuf_read() { #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) boost::asio::io_context ioc; test_stream s(ioc); boost::asio::streambuf sb(sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); boost::system::error_code error; size_t bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_all(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(1), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_at_least(42), error); BOOST_ASIO_CHECK(bytes_transferred == 50); BOOST_ASIO_CHECK(sb.size() == 50); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 50)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(1), error); BOOST_ASIO_CHECK(bytes_transferred == 1); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(10), error); BOOST_ASIO_CHECK(bytes_transferred == 10); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, boost::asio::transfer_exactly(42), error); BOOST_ASIO_CHECK(bytes_transferred == 42); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, old_style_transfer_all, error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bytes_transferred = boost::asio::read(s, sb, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); error = boost::system::error_code(); bytes_transferred = boost::asio::read(s, sb, short_transfer(), error); BOOST_ASIO_CHECK(bytes_transferred == sizeof(read_data)); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); BOOST_ASIO_CHECK(!error); #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) } void async_read_handler(const boost::system::error_code& e, size_t bytes_transferred, size_t expected_bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(!e); BOOST_ASIO_CHECK(bytes_transferred == expected_bytes_transferred); } void test_3_arg_mutable_buffer_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; boost::asio::mutable_buffer buffers = boost::asio::buffer(read_buf, sizeof(read_buf)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bool called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); int i = boost::asio::async_read(s, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_3_arg_boost_array_buffers_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; boost::array<boost::asio::mutable_buffer, 2> buffers = { { boost::asio::buffer(read_buf, 32), boost::asio::buffer(read_buf) + 32 } }; s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bool called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); int i = boost::asio::async_read(s, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) } void test_3_arg_std_array_buffers_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; std::array<boost::asio::mutable_buffer, 2> buffers = { { boost::asio::buffer(read_buf, 32), boost::asio::buffer(read_buf) + 32 } }; s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bool called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); int i = boost::asio::async_read(s, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_3_arg_vector_buffers_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; std::vector<boost::asio::mutable_buffer> buffers; buffers.push_back(boost::asio::buffer(read_buf, 32)); buffers.push_back(boost::asio::buffer(read_buf, 39) + 32); buffers.push_back(boost::asio::buffer(read_buf) + 39); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bool called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); int i = boost::asio::async_read(s, buffers, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_3_arg_dynamic_string_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); std::string data; boost::asio::dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type> sb = boost::asio::dynamic_buffer(data, sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bool called = false; boost::asio::async_read(s, sb, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); int i = boost::asio::async_read(s, sb, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); } void test_3_arg_streambuf_async_read() { #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); boost::asio::streambuf sb(sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bool called = false; boost::asio::async_read(s, sb, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); int i = boost::asio::async_read(s, sb, archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) } void test_4_arg_mutable_buffer_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; boost::asio::mutable_buffer buffers = boost::asio::buffer(read_buf, sizeof(read_buf)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bool called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 50)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); int i = boost::asio::async_read(s, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_4_arg_boost_array_buffers_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; boost::array<boost::asio::mutable_buffer, 2> buffers = { { boost::asio::buffer(read_buf, 32), boost::asio::buffer(read_buf) + 32 } }; s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bool called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 50)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); int i = boost::asio::async_read(s, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) } void test_4_arg_std_array_buffers_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; std::array<boost::asio::mutable_buffer, 2> buffers = { { boost::asio::buffer(read_buf, 32), boost::asio::buffer(read_buf) + 32 } }; s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bool called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 50)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); int i = boost::asio::async_read(s, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_4_arg_vector_buffers_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); char read_buf[sizeof(read_data)]; std::vector<boost::asio::mutable_buffer> buffers; buffers.push_back(boost::asio::buffer(read_buf, 32)); buffers.push_back(boost::asio::buffer(read_buf, 39) + 32); buffers.push_back(boost::asio::buffer(read_buf) + 39); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); bool called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 50)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 1)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 10)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, 42)); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); memset(read_buf, 0, sizeof(read_buf)); called = false; boost::asio::async_read(s, buffers, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); s.reset(read_data, sizeof(read_data)); memset(read_buf, 0, sizeof(read_buf)); int i = boost::asio::async_read(s, buffers, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(read_data))); } void test_4_arg_dynamic_string_async_read() { namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); std::string data; boost::asio::dynamic_string_buffer<char, std::string::traits_type, std::string::allocator_type> sb = boost::asio::dynamic_buffer(data, sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bool called = false; boost::asio::async_read(s, sb, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 50); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 50)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 1)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), 42)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); int i = boost::asio::async_read(s, sb, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(0, sb.size()), sizeof(read_data))); } void test_4_arg_streambuf_async_read() { #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context ioc; test_stream s(ioc); boost::asio::streambuf sb(sizeof(read_data)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); bool called = false; boost::asio::async_read(s, sb, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_all(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(1), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_at_least(42), bindns::bind(async_read_handler, _1, _2, 50, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 50); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 50)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(1), bindns::bind(async_read_handler, _1, _2, 1, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 1); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 1)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(10), bindns::bind(async_read_handler, _1, _2, 10, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 10); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 10)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, boost::asio::transfer_exactly(42), bindns::bind(async_read_handler, _1, _2, 42, &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == 42); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), 42)); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, old_style_transfer_all, bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(1); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); s.next_read_length(10); sb.consume(sb.size()); called = false; boost::asio::async_read(s, sb, short_transfer(), bindns::bind(async_read_handler, _1, _2, sizeof(read_data), &called)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(called); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); s.reset(read_data, sizeof(read_data)); sb.consume(sb.size()); int i = boost::asio::async_read(s, sb, short_transfer(), archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(sb.size() == sizeof(read_data)); BOOST_ASIO_CHECK(s.check_buffers(sb.data(), sizeof(read_data))); #endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1) } BOOST_ASIO_TEST_SUITE ( "read", BOOST_ASIO_TEST_CASE(test_2_arg_zero_buffers_read) BOOST_ASIO_TEST_CASE(test_2_arg_mutable_buffer_read) BOOST_ASIO_TEST_CASE(test_2_arg_vector_buffers_read) BOOST_ASIO_TEST_CASE(test_2_arg_dynamic_string_read) BOOST_ASIO_TEST_CASE(test_2_arg_streambuf_read) BOOST_ASIO_TEST_CASE(test_3_arg_nothrow_zero_buffers_read) BOOST_ASIO_TEST_CASE(test_3_arg_nothrow_mutable_buffer_read) BOOST_ASIO_TEST_CASE(test_3_arg_nothrow_vector_buffers_read) BOOST_ASIO_TEST_CASE(test_3_arg_nothrow_dynamic_string_read) BOOST_ASIO_TEST_CASE(test_3_arg_nothrow_streambuf_read) BOOST_ASIO_TEST_CASE(test_3_arg_mutable_buffer_read) BOOST_ASIO_TEST_CASE(test_3_arg_vector_buffers_read) BOOST_ASIO_TEST_CASE(test_3_arg_dynamic_string_read) BOOST_ASIO_TEST_CASE(test_3_arg_streambuf_read) BOOST_ASIO_TEST_CASE(test_4_arg_mutable_buffer_read) BOOST_ASIO_TEST_CASE(test_4_arg_vector_buffers_read) BOOST_ASIO_TEST_CASE(test_4_arg_dynamic_string_read) BOOST_ASIO_TEST_CASE(test_4_arg_streambuf_read) BOOST_ASIO_TEST_CASE(test_3_arg_mutable_buffer_async_read) BOOST_ASIO_TEST_CASE(test_3_arg_boost_array_buffers_async_read) BOOST_ASIO_TEST_CASE(test_3_arg_std_array_buffers_async_read) BOOST_ASIO_TEST_CASE(test_3_arg_vector_buffers_async_read) BOOST_ASIO_TEST_CASE(test_3_arg_dynamic_string_async_read) BOOST_ASIO_TEST_CASE(test_3_arg_streambuf_async_read) BOOST_ASIO_TEST_CASE(test_4_arg_mutable_buffer_async_read) BOOST_ASIO_TEST_CASE(test_4_arg_vector_buffers_async_read) BOOST_ASIO_TEST_CASE(test_4_arg_boost_array_buffers_async_read) BOOST_ASIO_TEST_CASE(test_4_arg_std_array_buffers_async_read) BOOST_ASIO_TEST_CASE(test_4_arg_dynamic_string_async_read) BOOST_ASIO_TEST_CASE(test_4_arg_streambuf_async_read) )
cpp
asio
data/projects/asio/test/bind_executor.cpp
// // bind_executor.cpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/bind_executor.hpp> #include <functional> #include <boost/asio/io_context.hpp> #include <boost/asio/steady_timer.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) # include <boost/asio/deadline_timer.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) # include <boost/asio/steady_timer.hpp> #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) using namespace boost::asio; namespace bindns = std; #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) typedef deadline_timer timer; namespace chronons = boost::posix_time; #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) typedef steady_timer timer; namespace chronons = boost::asio::chrono; #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) void increment(int* count) { ++(*count); } void bind_executor_to_function_object_test() { io_context ioc1; io_context ioc2; int count = 0; timer t(ioc1, chronons::seconds(1)); t.async_wait( bind_executor( ioc2.get_executor(), bindns::bind(&increment, &count))); ioc1.run(); BOOST_ASIO_CHECK(count == 0); ioc2.run(); BOOST_ASIO_CHECK(count == 1); t.async_wait( bind_executor( ioc2.get_executor(), bind_executor( boost::asio::system_executor(), bindns::bind(&increment, &count)))); ioc1.restart(); ioc1.run(); BOOST_ASIO_CHECK(count == 1); ioc2.restart(); ioc2.run(); BOOST_ASIO_CHECK(count == 2); } struct incrementer_token_v1 { explicit incrementer_token_v1(int* c) : count(c) {} int* count; }; struct incrementer_handler_v1 { explicit incrementer_handler_v1(incrementer_token_v1 t) : count(t.count) {} void operator()(boost::system::error_code){ increment(count); } int* count; }; namespace boost { namespace asio { template <> class async_result<incrementer_token_v1, void(boost::system::error_code)> { public: typedef incrementer_handler_v1 completion_handler_type; typedef void return_type; explicit async_result(completion_handler_type&) {} return_type get() {} }; } // namespace asio } // namespace boost void bind_executor_to_completion_token_v1_test() { io_context ioc1; io_context ioc2; int count = 0; timer t(ioc1, chronons::seconds(1)); t.async_wait( bind_executor( ioc2.get_executor(), incrementer_token_v1(&count))); ioc1.run(); BOOST_ASIO_CHECK(count == 0); ioc2.run(); BOOST_ASIO_CHECK(count == 1); } struct incrementer_token_v2 { explicit incrementer_token_v2(int* c) : count(c) {} int* count; }; namespace boost { namespace asio { template <> class async_result<incrementer_token_v2, void(boost::system::error_code)> { public: #if !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION) typedef void return_type; #endif // !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION) template <typename Initiation, typename... Args> static void initiate(Initiation initiation, incrementer_token_v2 token, Args&&... args) { initiation(bindns::bind(&increment, token.count), static_cast<Args&&>(args)...); } }; } // namespace asio } // namespace boost void bind_executor_to_completion_token_v2_test() { io_context ioc1; io_context ioc2; int count = 0; timer t(ioc1, chronons::seconds(1)); t.async_wait( bind_executor( ioc2.get_executor(), incrementer_token_v2(&count))); ioc1.run(); BOOST_ASIO_CHECK(count == 0); ioc2.run(); BOOST_ASIO_CHECK(count == 1); } BOOST_ASIO_TEST_SUITE ( "bind_executor", BOOST_ASIO_TEST_CASE(bind_executor_to_function_object_test) BOOST_ASIO_TEST_CASE(bind_executor_to_completion_token_v1_test) BOOST_ASIO_TEST_CASE(bind_executor_to_completion_token_v2_test) )
cpp
asio
data/projects/asio/test/cancellation_type.cpp
// // cancellation_type.cpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/cancellation_type.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "cancellation_type", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/execution_context.cpp
// // execution_context.cpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/execution_context.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "execution_context", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/associated_immediate_executor.cpp
// // associated_immediate_executor.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2022 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/associated_immediate_executor.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "associated_immediate_executor", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/deadline_timer.cpp
// // deadline_timer.cpp // ~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/deadline_timer.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) #include <boost/bind/bind.hpp> #include "archetypes/async_result.hpp" #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/placeholders.hpp> #include <boost/asio/detail/thread.hpp> using namespace boost::posix_time; void increment(int* count) { ++(*count); } void decrement_to_zero(boost::asio::deadline_timer* t, int* count) { if (*count > 0) { --(*count); int before_value = *count; t->expires_at(t->expires_at() + seconds(1)); t->async_wait(boost::bind(decrement_to_zero, t, count)); // Completion cannot nest, so count value should remain unchanged. BOOST_ASIO_CHECK(*count == before_value); } } void increment_if_not_cancelled(int* count, const boost::system::error_code& ec) { if (!ec) ++(*count); } void cancel_timer(boost::asio::deadline_timer* t) { std::size_t num_cancelled = t->cancel(); BOOST_ASIO_CHECK(num_cancelled == 1); } void cancel_one_timer(boost::asio::deadline_timer* t) { std::size_t num_cancelled = t->cancel_one(); BOOST_ASIO_CHECK(num_cancelled == 1); } ptime now() { #if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK) return microsec_clock::universal_time(); #else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK) return second_clock::universal_time(); #endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK) } void deadline_timer_test() { boost::asio::io_context ioc; int count = 0; ptime start = now(); boost::asio::deadline_timer t1(ioc, seconds(1)); t1.wait(); // The timer must block until after its expiry time. ptime end = now(); ptime expected_end = start + seconds(1); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); start = now(); boost::asio::deadline_timer t2(ioc, seconds(1) + microseconds(500000)); t2.wait(); // The timer must block until after its expiry time. end = now(); expected_end = start + seconds(1) + microseconds(500000); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); t2.expires_at(t2.expires_at() + seconds(1)); t2.wait(); // The timer must block until after its expiry time. end = now(); expected_end += seconds(1); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); start = now(); t2.expires_from_now(seconds(1) + microseconds(200000)); t2.wait(); // The timer must block until after its expiry time. end = now(); expected_end = start + seconds(1) + microseconds(200000); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); start = now(); boost::asio::deadline_timer t3(ioc, seconds(5)); t3.async_wait(boost::bind(increment, &count)); // No completions can be delivered until run() is called. BOOST_ASIO_CHECK(count == 0); ioc.run(); // The run() call will not return until all operations have finished, and // this should not be until after the timer's expiry time. BOOST_ASIO_CHECK(count == 1); end = now(); expected_end = start + seconds(1); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); count = 3; start = now(); boost::asio::deadline_timer t4(ioc, seconds(1)); t4.async_wait(boost::bind(decrement_to_zero, &t4, &count)); // No completions can be delivered until run() is called. BOOST_ASIO_CHECK(count == 3); ioc.restart(); ioc.run(); // The run() call will not return until all operations have finished, and // this should not be until after the timer's final expiry time. BOOST_ASIO_CHECK(count == 0); end = now(); expected_end = start + seconds(3); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); count = 0; start = now(); boost::asio::deadline_timer t5(ioc, seconds(10)); t5.async_wait(boost::bind(increment_if_not_cancelled, &count, boost::asio::placeholders::error)); boost::asio::deadline_timer t6(ioc, seconds(1)); t6.async_wait(boost::bind(cancel_timer, &t5)); // No completions can be delivered until run() is called. BOOST_ASIO_CHECK(count == 0); ioc.restart(); ioc.run(); // The timer should have been cancelled, so count should not have changed. // The total run time should not have been much more than 1 second (and // certainly far less than 10 seconds). BOOST_ASIO_CHECK(count == 0); end = now(); expected_end = start + seconds(2); BOOST_ASIO_CHECK(end < expected_end); // Wait on the timer again without cancelling it. This time the asynchronous // wait should run to completion and increment the counter. t5.async_wait(boost::bind(increment_if_not_cancelled, &count, boost::asio::placeholders::error)); ioc.restart(); ioc.run(); // The timer should not have been cancelled, so count should have changed. // The total time since the timer was created should be more than 10 seconds. BOOST_ASIO_CHECK(count == 1); end = now(); expected_end = start + seconds(10); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); count = 0; start = now(); // Start two waits on a timer, one of which will be cancelled. The one // which is not cancelled should still run to completion and increment the // counter. boost::asio::deadline_timer t7(ioc, seconds(3)); t7.async_wait(boost::bind(increment_if_not_cancelled, &count, boost::asio::placeholders::error)); t7.async_wait(boost::bind(increment_if_not_cancelled, &count, boost::asio::placeholders::error)); boost::asio::deadline_timer t8(ioc, seconds(1)); t8.async_wait(boost::bind(cancel_one_timer, &t7)); ioc.restart(); ioc.run(); // One of the waits should not have been cancelled, so count should have // changed. The total time since the timer was created should be more than 3 // seconds. BOOST_ASIO_CHECK(count == 1); end = now(); expected_end = start + seconds(3); BOOST_ASIO_CHECK(expected_end < end || expected_end == end); } void timer_handler(const boost::system::error_code&) { } void deadline_timer_cancel_test() { static boost::asio::io_context io_context; struct timer { boost::asio::deadline_timer t; timer() : t(io_context) { t.expires_at(boost::posix_time::pos_infin); } } timers[50]; timers[2].t.async_wait(&timer_handler); timers[41].t.async_wait(&timer_handler); for (int i = 10; i < 20; ++i) timers[i].t.async_wait(&timer_handler); BOOST_ASIO_CHECK(timers[2].t.cancel() == 1); BOOST_ASIO_CHECK(timers[41].t.cancel() == 1); for (int i = 10; i < 20; ++i) BOOST_ASIO_CHECK(timers[i].t.cancel() == 1); } struct custom_allocation_timer_handler { custom_allocation_timer_handler(int* count) : count_(count) {} void operator()(const boost::system::error_code&) {} int* count_; template <typename T> struct allocator { typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; typedef T value_type; template <typename U> struct rebind { typedef allocator<U> other; }; explicit allocator(int* count) noexcept : count_(count) { } allocator(const allocator& other) noexcept : count_(other.count_) { } template <typename U> allocator(const allocator<U>& other) noexcept : count_(other.count_) { } pointer allocate(size_type n, const void* = 0) { ++(*count_); return static_cast<T*>(::operator new(sizeof(T) * n)); } void deallocate(pointer p, size_type) { --(*count_); ::operator delete(p); } size_type max_size() const { return ~size_type(0); } void construct(pointer p, const T& v) { new (p) T(v); } void destroy(pointer p) { p->~T(); } int* count_; }; typedef allocator<int> allocator_type; allocator_type get_allocator() const noexcept { return allocator_type(count_); } }; void deadline_timer_custom_allocation_test() { static boost::asio::io_context io_context; struct timer { boost::asio::deadline_timer t; timer() : t(io_context) {} } timers[100]; int allocation_count = 0; for (int i = 0; i < 50; ++i) { timers[i].t.expires_at(boost::posix_time::pos_infin); timers[i].t.async_wait(custom_allocation_timer_handler(&allocation_count)); } for (int i = 50; i < 100; ++i) { timers[i].t.expires_at(boost::posix_time::neg_infin); timers[i].t.async_wait(custom_allocation_timer_handler(&allocation_count)); } for (int i = 0; i < 50; ++i) timers[i].t.cancel(); io_context.run(); BOOST_ASIO_CHECK(allocation_count == 0); } void io_context_run(boost::asio::io_context* ioc) { ioc->run(); } void deadline_timer_thread_test() { boost::asio::io_context ioc; boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work = boost::asio::make_work_guard(ioc); boost::asio::deadline_timer t1(ioc); boost::asio::deadline_timer t2(ioc); int count = 0; boost::asio::detail::thread th(boost::bind(io_context_run, &ioc)); t2.expires_from_now(boost::posix_time::seconds(2)); t2.wait(); t1.expires_from_now(boost::posix_time::seconds(2)); t1.async_wait(boost::bind(increment, &count)); t2.expires_from_now(boost::posix_time::seconds(4)); t2.wait(); ioc.stop(); th.join(); BOOST_ASIO_CHECK(count == 1); } void deadline_timer_async_result_test() { boost::asio::io_context ioc; boost::asio::deadline_timer t1(ioc); t1.expires_from_now(boost::posix_time::seconds(1)); int i = t1.async_wait(archetypes::lazy_handler()); BOOST_ASIO_CHECK(i == 42); ioc.run(); } boost::asio::deadline_timer make_timer(boost::asio::io_context& ioc, int* count) { boost::asio::deadline_timer t(ioc); t.expires_from_now(boost::posix_time::seconds(1)); t.async_wait(boost::bind(increment, count)); return t; } void deadline_timer_move_test() { boost::asio::io_context io_context1; boost::asio::io_context io_context2; int count = 0; boost::asio::deadline_timer t1 = make_timer(io_context1, &count); boost::asio::deadline_timer t2 = make_timer(io_context2, &count); boost::asio::deadline_timer t3 = std::move(t1); t2 = std::move(t1); io_context2.run(); BOOST_ASIO_CHECK(count == 1); io_context1.run(); BOOST_ASIO_CHECK(count == 2); } BOOST_ASIO_TEST_SUITE ( "deadline_timer", BOOST_ASIO_TEST_CASE(deadline_timer_test) BOOST_ASIO_TEST_CASE(deadline_timer_cancel_test) BOOST_ASIO_TEST_CASE(deadline_timer_custom_allocation_test) BOOST_ASIO_TEST_CASE(deadline_timer_thread_test) BOOST_ASIO_TEST_CASE(deadline_timer_async_result_test) BOOST_ASIO_TEST_CASE(deadline_timer_move_test) ) #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) BOOST_ASIO_TEST_SUITE ( "deadline_timer", BOOST_ASIO_TEST_CASE(null_test) ) #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
cpp
asio
data/projects/asio/test/time_traits.cpp
// // time_traits.cpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/time_traits.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "time_traits", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/high_resolution_timer.cpp
// // high_resolution_timer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Prevent link dependency on the Boost.System library. #if !defined(BOOST_SYSTEM_NO_DEPRECATED) #define BOOST_SYSTEM_NO_DEPRECATED #endif // !defined(BOOST_SYSTEM_NO_DEPRECATED) // Test that header file is self-contained. #include <boost/asio/high_resolution_timer.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "high_resolution_timer", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/connect.cpp
// // connect.cpp // ~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/connect.hpp> #include <functional> #include <vector> #include <boost/asio/detail/thread.hpp> #include <boost/asio/ip/tcp.hpp> #include "unit_test.hpp" namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; class connection_sink { public: connection_sink() : acceptor_(io_context_, boost::asio::ip::tcp::endpoint( boost::asio::ip::address_v4::loopback(), 0)), target_endpoint_(acceptor_.local_endpoint()), socket_(io_context_), thread_(bindns::bind(&connection_sink::run, this)) { } ~connection_sink() { io_context_.stop(); thread_.join(); } boost::asio::ip::tcp::endpoint target_endpoint() { return target_endpoint_; } private: void run() { io_context_.run(); } void handle_accept() { socket_.close(); acceptor_.async_accept(socket_, bindns::bind(&connection_sink::handle_accept, this)); } boost::asio::io_context io_context_; boost::asio::ip::tcp::acceptor acceptor_; boost::asio::ip::tcp::endpoint target_endpoint_; boost::asio::ip::tcp::socket socket_; boost::asio::detail::thread thread_; }; bool true_cond_1(const boost::system::error_code& /*ec*/, const boost::asio::ip::tcp::endpoint& /*endpoint*/) { return true; } struct true_cond_2 { template <typename Endpoint> bool operator()(const boost::system::error_code& /*ec*/, const Endpoint& /*endpoint*/) { return true; } }; std::vector<boost::asio::ip::tcp::endpoint>::const_iterator legacy_true_cond_1( const boost::system::error_code& /*ec*/, std::vector<boost::asio::ip::tcp::endpoint>::const_iterator next) { return next; } struct legacy_true_cond_2 { template <typename Iterator> Iterator operator()(const boost::system::error_code& /*ec*/, Iterator next) { return next; } }; bool false_cond(const boost::system::error_code& /*ec*/, const boost::asio::ip::tcp::endpoint& /*endpoint*/) { return false; } void range_handler(const boost::system::error_code& ec, const boost::asio::ip::tcp::endpoint& endpoint, boost::system::error_code* out_ec, boost::asio::ip::tcp::endpoint* out_endpoint) { *out_ec = ec; *out_endpoint = endpoint; } void iter_handler(const boost::system::error_code& ec, std::vector<boost::asio::ip::tcp::endpoint>::const_iterator iter, boost::system::error_code* out_ec, std::vector<boost::asio::ip::tcp::endpoint>::const_iterator* out_iter) { *out_ec = ec; *out_iter = iter; } void test_connect_range() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; boost::asio::ip::tcp::endpoint result; try { result = boost::asio::connect(socket, endpoints); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, endpoints); BOOST_ASIO_CHECK(result == endpoints[0]); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, endpoints); BOOST_ASIO_CHECK(result == endpoints[0]); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); result = boost::asio::connect(socket, endpoints); BOOST_ASIO_CHECK(result == endpoints[1]); } void test_connect_range_ec() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; boost::asio::ip::tcp::endpoint result; boost::system::error_code ec; result = boost::asio::connect(socket, endpoints, ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, endpoints, ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, endpoints, ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); result = boost::asio::connect(socket, endpoints, ec); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); } void test_connect_range_cond() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; boost::asio::ip::tcp::endpoint result; try { result = boost::asio::connect(socket, endpoints, true_cond_1); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } try { result = boost::asio::connect(socket, endpoints, true_cond_2()); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } try { result = boost::asio::connect(socket, endpoints, legacy_true_cond_1); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } try { result = boost::asio::connect(socket, endpoints, legacy_true_cond_2()); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } try { result = boost::asio::connect(socket, endpoints, false_cond); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, endpoints, true_cond_1); BOOST_ASIO_CHECK(result == endpoints[0]); result = boost::asio::connect(socket, endpoints, true_cond_2()); BOOST_ASIO_CHECK(result == endpoints[0]); result = boost::asio::connect(socket, endpoints, legacy_true_cond_1); BOOST_ASIO_CHECK(result == endpoints[0]); result = boost::asio::connect(socket, endpoints, legacy_true_cond_2()); BOOST_ASIO_CHECK(result == endpoints[0]); try { result = boost::asio::connect(socket, endpoints, false_cond); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, endpoints, true_cond_1); BOOST_ASIO_CHECK(result == endpoints[0]); result = boost::asio::connect(socket, endpoints, true_cond_2()); BOOST_ASIO_CHECK(result == endpoints[0]); result = boost::asio::connect(socket, endpoints, legacy_true_cond_1); BOOST_ASIO_CHECK(result == endpoints[0]); result = boost::asio::connect(socket, endpoints, legacy_true_cond_2()); BOOST_ASIO_CHECK(result == endpoints[0]); try { result = boost::asio::connect(socket, endpoints, false_cond); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); result = boost::asio::connect(socket, endpoints, true_cond_1); BOOST_ASIO_CHECK(result == endpoints[1]); result = boost::asio::connect(socket, endpoints, true_cond_2()); BOOST_ASIO_CHECK(result == endpoints[1]); result = boost::asio::connect(socket, endpoints, legacy_true_cond_1); BOOST_ASIO_CHECK(result == endpoints[1]); result = boost::asio::connect(socket, endpoints, legacy_true_cond_2()); BOOST_ASIO_CHECK(result == endpoints[1]); try { result = boost::asio::connect(socket, endpoints, false_cond); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } } void test_connect_range_cond_ec() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; boost::asio::ip::tcp::endpoint result; boost::system::error_code ec; result = boost::asio::connect(socket, endpoints, true_cond_1, ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); result = boost::asio::connect(socket, endpoints, true_cond_2(), ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); result = boost::asio::connect(socket, endpoints, legacy_true_cond_1, ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); result = boost::asio::connect(socket, endpoints, legacy_true_cond_2(), ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); result = boost::asio::connect(socket, endpoints, false_cond, ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, endpoints, true_cond_1, ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, true_cond_2(), ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, legacy_true_cond_1, ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, legacy_true_cond_2(), ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, false_cond, ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, endpoints, true_cond_1, ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, true_cond_2(), ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, legacy_true_cond_1, ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, legacy_true_cond_2(), ec); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, false_cond, ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); result = boost::asio::connect(socket, endpoints, true_cond_1, ec); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, true_cond_2(), ec); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, legacy_true_cond_1, ec); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, legacy_true_cond_2(), ec); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, endpoints, false_cond, ec); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); } void test_connect_iter() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; const std::vector<boost::asio::ip::tcp::endpoint>& cendpoints = endpoints; std::vector<boost::asio::ip::tcp::endpoint>::const_iterator result; try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end()); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end()); BOOST_ASIO_CHECK(result == cendpoints.begin()); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end()); BOOST_ASIO_CHECK(result == cendpoints.begin()); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end()); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); } void test_connect_iter_ec() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; const std::vector<boost::asio::ip::tcp::endpoint>& cendpoints = endpoints; std::vector<boost::asio::ip::tcp::endpoint>::const_iterator result; boost::system::error_code ec; result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); } void test_connect_iter_cond() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; const std::vector<boost::asio::ip::tcp::endpoint>& cendpoints = endpoints; std::vector<boost::asio::ip::tcp::endpoint>::const_iterator result; try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2()); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2()); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), false_cond); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1); BOOST_ASIO_CHECK(result == cendpoints.begin()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2()); BOOST_ASIO_CHECK(result == cendpoints.begin()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1); BOOST_ASIO_CHECK(result == cendpoints.begin()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2()); BOOST_ASIO_CHECK(result == cendpoints.begin()); try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), false_cond); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1); BOOST_ASIO_CHECK(result == cendpoints.begin()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2()); BOOST_ASIO_CHECK(result == cendpoints.begin()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1); BOOST_ASIO_CHECK(result == cendpoints.begin()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2()); BOOST_ASIO_CHECK(result == cendpoints.begin()); try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), false_cond); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2()); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2()); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); try { result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), false_cond); BOOST_ASIO_CHECK(false); } catch (boost::system::system_error& e) { BOOST_ASIO_CHECK(e.code() == boost::asio::error::not_found); } } void test_connect_iter_cond_ec() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; const std::vector<boost::asio::ip::tcp::endpoint>& cendpoints = endpoints; std::vector<boost::asio::ip::tcp::endpoint>::const_iterator result; boost::system::error_code ec; result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1, ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2(), ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1, ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2(), ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), false_cond, ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1, ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1, ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), false_cond, ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1, ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1, ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), false_cond, ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1, ec); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1, ec); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2(), ec); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); result = boost::asio::connect(socket, cendpoints.begin(), cendpoints.end(), false_cond, ec); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); } void test_async_connect_range() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; boost::asio::ip::tcp::endpoint result; boost::system::error_code ec; boost::asio::async_connect(socket, endpoints, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); boost::asio::async_connect(socket, endpoints, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); endpoints.push_back(sink.target_endpoint()); boost::asio::async_connect(socket, endpoints, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); boost::asio::async_connect(socket, endpoints, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); } void test_async_connect_range_cond() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; boost::asio::ip::tcp::endpoint result; boost::system::error_code ec; boost::asio::async_connect(socket, endpoints, true_cond_1, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); boost::asio::async_connect(socket, endpoints, true_cond_2(), bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); boost::asio::async_connect(socket, endpoints, legacy_true_cond_1, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); boost::asio::async_connect(socket, endpoints, legacy_true_cond_2(), bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); boost::asio::async_connect(socket, endpoints, false_cond, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); boost::asio::async_connect(socket, endpoints, true_cond_1, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, true_cond_2(), bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, legacy_true_cond_1, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, legacy_true_cond_2(), bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, false_cond, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); boost::asio::async_connect(socket, endpoints, true_cond_1, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, true_cond_2(), bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, legacy_true_cond_1, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, legacy_true_cond_2(), bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[0]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, false_cond, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); boost::asio::async_connect(socket, endpoints, true_cond_1, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, true_cond_2(), bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, legacy_true_cond_1, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, legacy_true_cond_2(), bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == endpoints[1]); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, endpoints, false_cond, bindns::bind(range_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == boost::asio::ip::tcp::endpoint()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); } void test_async_connect_iter() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; const std::vector<boost::asio::ip::tcp::endpoint>& cendpoints = endpoints; std::vector<boost::asio::ip::tcp::endpoint>::const_iterator result; boost::system::error_code ec; boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); endpoints.push_back(sink.target_endpoint()); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); } void test_async_connect_iter_cond() { connection_sink sink; boost::asio::io_context io_context; boost::asio::ip::tcp::socket socket(io_context); std::vector<boost::asio::ip::tcp::endpoint> endpoints; const std::vector<boost::asio::ip::tcp::endpoint>& cendpoints = endpoints; std::vector<boost::asio::ip::tcp::endpoint>::const_iterator result; boost::system::error_code ec; boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), false_cond, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), false_cond, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.push_back(sink.target_endpoint()); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin()); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), false_cond, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); endpoints.insert(endpoints.begin(), boost::asio::ip::tcp::endpoint()); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_1, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), true_cond_2(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_1, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), legacy_true_cond_2(), bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.begin() + 1); BOOST_ASIO_CHECK(!ec); boost::asio::async_connect(socket, cendpoints.begin(), cendpoints.end(), false_cond, bindns::bind(iter_handler, _1, _2, &ec, &result)); io_context.restart(); io_context.run(); BOOST_ASIO_CHECK(result == cendpoints.end()); BOOST_ASIO_CHECK(ec == boost::asio::error::not_found); } BOOST_ASIO_TEST_SUITE ( "connect", BOOST_ASIO_TEST_CASE(test_connect_range) BOOST_ASIO_TEST_CASE(test_connect_range_ec) BOOST_ASIO_TEST_CASE(test_connect_range_cond) BOOST_ASIO_TEST_CASE(test_connect_range_cond_ec) BOOST_ASIO_TEST_CASE(test_connect_iter) BOOST_ASIO_TEST_CASE(test_connect_iter_ec) BOOST_ASIO_TEST_CASE(test_connect_iter_cond) BOOST_ASIO_TEST_CASE(test_connect_iter_cond_ec) BOOST_ASIO_TEST_CASE(test_async_connect_range) BOOST_ASIO_TEST_CASE(test_async_connect_range_cond) BOOST_ASIO_TEST_CASE(test_async_connect_iter) BOOST_ASIO_TEST_CASE(test_async_connect_iter_cond) )
cpp
asio
data/projects/asio/test/buffered_read_stream.cpp
// // buffered_read_stream.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/buffered_read_stream.hpp> #include <cstring> #include <functional> #include "archetypes/async_result.hpp" #include <boost/asio/buffer.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/system/system_error.hpp> #include "unit_test.hpp" #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <boost/array.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <array> #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) typedef boost::asio::buffered_read_stream< boost::asio::ip::tcp::socket> stream_type; void write_some_handler(const boost::system::error_code&, std::size_t) { } void fill_handler(const boost::system::error_code&, std::size_t) { } void read_some_handler(const boost::system::error_code&, std::size_t) { } void test_compile() { #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) using boost::array; #else // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using std::array; #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using namespace boost::asio; try { io_context ioc; char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; array<boost::asio::mutable_buffer, 2> mutable_buffers = {{ boost::asio::buffer(mutable_char_buffer, 10), boost::asio::buffer(mutable_char_buffer + 10, 10) }}; array<boost::asio::const_buffer, 2> const_buffers = {{ boost::asio::buffer(const_char_buffer, 10), boost::asio::buffer(const_char_buffer + 10, 10) }}; archetypes::lazy_handler lazy; boost::system::error_code ec; stream_type stream1(ioc); stream_type stream2(ioc, 1024); stream_type::executor_type ex = stream1.get_executor(); (void)ex; stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer(); (void)lowest_layer; stream1.write_some(buffer(mutable_char_buffer)); stream1.write_some(buffer(const_char_buffer)); stream1.write_some(mutable_buffers); stream1.write_some(const_buffers); stream1.write_some(null_buffers()); stream1.write_some(buffer(mutable_char_buffer), ec); stream1.write_some(buffer(const_char_buffer), ec); stream1.write_some(mutable_buffers, ec); stream1.write_some(const_buffers, ec); stream1.write_some(null_buffers(), ec); stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler); stream1.async_write_some(buffer(const_char_buffer), &write_some_handler); stream1.async_write_some(mutable_buffers, &write_some_handler); stream1.async_write_some(const_buffers, &write_some_handler); stream1.async_write_some(null_buffers(), &write_some_handler); int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy); (void)i1; int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy); (void)i2; int i3 = stream1.async_write_some(mutable_buffers, lazy); (void)i3; int i4 = stream1.async_write_some(const_buffers, lazy); (void)i4; int i5 = stream1.async_write_some(null_buffers(), lazy); (void)i5; stream1.fill(); stream1.fill(ec); stream1.async_fill(&fill_handler); int i6 = stream1.async_fill(lazy); (void)i6; stream1.read_some(buffer(mutable_char_buffer)); stream1.read_some(mutable_buffers); stream1.read_some(null_buffers()); stream1.read_some(buffer(mutable_char_buffer), ec); stream1.read_some(mutable_buffers, ec); stream1.read_some(null_buffers(), ec); stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler); stream1.async_read_some(mutable_buffers, &read_some_handler); stream1.async_read_some(null_buffers(), &read_some_handler); int i7 = stream1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i7; int i8 = stream1.async_read_some(mutable_buffers, lazy); (void)i8; int i9 = stream1.async_read_some(null_buffers(), lazy); (void)i9; } catch (std::exception&) { } } void test_sync_operations() { using namespace std; // For memcmp. boost::asio::io_context io_context; boost::asio::ip::tcp::acceptor acceptor(io_context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0)); boost::asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint(); server_endpoint.address(boost::asio::ip::address_v4::loopback()); stream_type client_socket(io_context); client_socket.lowest_layer().connect(server_endpoint); stream_type server_socket(io_context); acceptor.accept(server_socket.lowest_layer()); const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const boost::asio::const_buffer write_buf = boost::asio::buffer(write_data); std::size_t bytes_written = 0; while (bytes_written < sizeof(write_data)) { bytes_written += client_socket.write_some( boost::asio::buffer(write_buf + bytes_written)); } char read_data[sizeof(write_data)]; const boost::asio::mutable_buffer read_buf = boost::asio::buffer(read_data); std::size_t bytes_read = 0; while (bytes_read < sizeof(read_data)) { bytes_read += server_socket.read_some( boost::asio::buffer(read_buf + bytes_read)); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); bytes_written = 0; while (bytes_written < sizeof(write_data)) { bytes_written += server_socket.write_some( boost::asio::buffer(write_buf + bytes_written)); } bytes_read = 0; while (bytes_read < sizeof(read_data)) { bytes_read += client_socket.read_some( boost::asio::buffer(read_buf + bytes_read)); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); server_socket.close(); boost::system::error_code error; bytes_read = client_socket.read_some( boost::asio::buffer(read_buf), error); BOOST_ASIO_CHECK(bytes_read == 0); BOOST_ASIO_CHECK(error == boost::asio::error::eof); client_socket.close(error); } void handle_accept(const boost::system::error_code& e) { BOOST_ASIO_CHECK(!e); } void handle_write(const boost::system::error_code& e, std::size_t bytes_transferred, std::size_t* total_bytes_written) { BOOST_ASIO_CHECK(!e); if (e) throw boost::system::system_error(e); // Terminate test. *total_bytes_written += bytes_transferred; } void handle_read(const boost::system::error_code& e, std::size_t bytes_transferred, std::size_t* total_bytes_read) { BOOST_ASIO_CHECK(!e); if (e) throw boost::system::system_error(e); // Terminate test. *total_bytes_read += bytes_transferred; } void handle_read_eof(const boost::system::error_code& e, std::size_t bytes_transferred) { BOOST_ASIO_CHECK(e == boost::asio::error::eof); BOOST_ASIO_CHECK(bytes_transferred == 0); } void test_async_operations() { using namespace std; // For memcmp. namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; boost::asio::io_context io_context; boost::asio::ip::tcp::acceptor acceptor(io_context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0)); boost::asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint(); server_endpoint.address(boost::asio::ip::address_v4::loopback()); stream_type client_socket(io_context); client_socket.lowest_layer().connect(server_endpoint); stream_type server_socket(io_context); acceptor.async_accept(server_socket.lowest_layer(), &handle_accept); io_context.run(); io_context.restart(); const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const boost::asio::const_buffer write_buf = boost::asio::buffer(write_data); std::size_t bytes_written = 0; while (bytes_written < sizeof(write_data)) { client_socket.async_write_some( boost::asio::buffer(write_buf + bytes_written), bindns::bind(handle_write, _1, _2, &bytes_written)); io_context.run(); io_context.restart(); } char read_data[sizeof(write_data)]; const boost::asio::mutable_buffer read_buf = boost::asio::buffer(read_data); std::size_t bytes_read = 0; while (bytes_read < sizeof(read_data)) { server_socket.async_read_some( boost::asio::buffer(read_buf + bytes_read), bindns::bind(handle_read, _1, _2, &bytes_read)); io_context.run(); io_context.restart(); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); bytes_written = 0; while (bytes_written < sizeof(write_data)) { server_socket.async_write_some( boost::asio::buffer(write_buf + bytes_written), bindns::bind(handle_write, _1, _2, &bytes_written)); io_context.run(); io_context.restart(); } bytes_read = 0; while (bytes_read < sizeof(read_data)) { client_socket.async_read_some( boost::asio::buffer(read_buf + bytes_read), bindns::bind(handle_read, _1, _2, &bytes_read)); io_context.run(); io_context.restart(); } BOOST_ASIO_CHECK(bytes_written == sizeof(write_data)); BOOST_ASIO_CHECK(bytes_read == sizeof(read_data)); BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0); server_socket.close(); client_socket.async_read_some(boost::asio::buffer(read_buf), handle_read_eof); } BOOST_ASIO_TEST_SUITE ( "buffered_read_stream", BOOST_ASIO_COMPILE_TEST_CASE(test_compile) BOOST_ASIO_TEST_CASE(test_sync_operations) BOOST_ASIO_TEST_CASE(test_async_operations) )
cpp
asio
data/projects/asio/test/consign.cpp
// // consign.cpp // ~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/consign.hpp> #include <boost/asio/bind_executor.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/system_timer.hpp> #include "unit_test.hpp" void consign_test() { boost::asio::io_context io1; boost::asio::io_context io2; boost::asio::system_timer timer1(io1); int count = 0; timer1.expires_after(boost::asio::chrono::seconds(0)); timer1.async_wait( boost::asio::consign( boost::asio::bind_executor(io2.get_executor(), [&count](boost::system::error_code) { ++count; }), 123, 321)); BOOST_ASIO_CHECK(count == 0); io1.run(); BOOST_ASIO_CHECK(count == 0); io2.run(); BOOST_ASIO_CHECK(count == 1); } BOOST_ASIO_TEST_SUITE ( "consign", BOOST_ASIO_TEST_CASE(consign_test) )
cpp
asio
data/projects/asio/test/basic_signal_set.cpp
// // basic_signal_set.cpp // ~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/basic_signal_set.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "basic_signal_set", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/post.cpp
// // post.cpp // ~~~~~~~~ // // Copyright (c) 2003-2024 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/post.hpp> #include "unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "post", BOOST_ASIO_TEST_CASE(null_test) )
cpp