diff --git a/CHANGELOG.md b/CHANGELOG.md index e9be3165..e3c01d3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +Version 125: + +API Changes: + +* Update for Net-TS Asio + +Actions Required: + +* Use BOOST_ASIO_HANDLER_TYPE instead of handler_type +* Use BOOST_ASIO_INITFN_RESULT_TYPE instead of async_result +* Use boost::asio::async_completion +* Use boost::asio::is_dynamic_buffer +* Use boost::asio::is_const_buffer_sequence +* Use boost::asio::is_mutable_buffer_sequence +* boost::asio::associated_allocator_t replaces handler_alloc + +-------------------------------------------------------------------------------- + Version 124: * Fix for a test matrix compiler diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f18d0bc..caf7a3fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,6 @@ if (MSVC) add_definitions (-D_WIN32_WINNT=0x0601) add_definitions (-D_SCL_SECURE_NO_WARNINGS=1) add_definitions (-D_CRT_SECURE_NO_WARNINGS=1) - add_definitions (-DBOOST_ASIO_NO_DEPRECATED=1) add_compile_options( /bigobj # large object file format @@ -75,6 +74,7 @@ get_filename_component (BOOST_ROOT ../../ ABSOLUTE) # VFALCO I want static but "b2 stage" builds a minimal set which excludes static add_definitions (-DBOOST_ALL_STATIC_LINK=1) +add_definitions (-DBOOST_ASIO_NO_DEPRECATED=1) add_definitions (-DBOOST_ASIO_DISABLE_BOOST_ARRAY=1) add_definitions (-DBOOST_ASIO_DISABLE_BOOST_BIND=1) add_definitions (-DBOOST_ASIO_DISABLE_BOOST_DATE_TIME=1) diff --git a/doc/images/message.png b/doc/images/message.png index 393ef30d..99f8a50e 100644 Binary files a/doc/images/message.png and b/doc/images/message.png differ diff --git a/doc/qbk/00_main.qbk b/doc/qbk/00_main.qbk index 879dca9f..943585ec 100644 --- a/doc/qbk/00_main.qbk +++ b/doc/qbk/00_main.qbk @@ -38,7 +38,7 @@ [def __asio_handler_invoke__ [@http://www.boost.org/doc/html/boost_asio/reference/asio_handler_invoke.html `asio_handler_invoke`]] [def __asio_handler_allocate__ [@http://www.boost.org/doc/html/boost_asio/reference/asio_handler_allocate.html `asio_handler_allocate`]] -[def __io_service__ [@http://www.boost.org/doc/html/boost_asio/reference/io_service.html `io_service`]] +[def __io_context__ [@http://www.boost.org/doc/html/boost_asio/reference/io_context.html `io_context`]] [def __socket__ [@http://www.boost.org/doc/html/boost_asio/reference/ip__tcp/socket.html `boost::asio::ip::tcp::socket`]] [def __ssl_stream__ [@http://www.boost.org/doc/html/boost_asio/reference/ssl__stream.html `boost::asio::ssl::stream`]] [def __streambuf__ [@http://www.boost.org/doc/html/boost_asio/reference/streambuf.html `boost::asio::streambuf`]] diff --git a/doc/qbk/03_core/1_asio.qbk b/doc/qbk/03_core/1_asio.qbk index 7ea72d7b..5a58ce4a 100644 --- a/doc/qbk/03_core/1_asio.qbk +++ b/doc/qbk/03_core/1_asio.qbk @@ -30,12 +30,12 @@ special meaning: [table Global Variables [[Name][Description]] [[ - [@http://www.boost.org/doc/html/boost_asio/reference/io_service.html [*`ios`]] + [@http://www.boost.org/doc/html/boost_asio/reference/io_context.html [*`ioc`]] ][ A variable of type - [@http://www.boost.org/doc/html/boost_asio/reference/io_service.html `boost::asio::io_service`] - which is running on one separate thread, and upon which a - [@http://www.boost.org/doc/html/boost_asio/reference/io_service__work.html `boost::asio::io_service::work`] + [@http://www.boost.org/doc/html/boost_asio/reference/io_context.html `boost::asio::io_context`] + which is running on one separate thread, and upon which an + [@http://www.boost.org/doc/html/boost_asio/reference/executor_work.html `boost::asio::executor_work`] object has been constructed. ]] [[ diff --git a/doc/qbk/03_core/2_streams.qbk b/doc/qbk/03_core/2_streams.qbk index 7118665a..b2db0734 100644 --- a/doc/qbk/03_core/2_streams.qbk +++ b/doc/qbk/03_core/2_streams.qbk @@ -67,10 +67,9 @@ checks helps provide more concise errors during compilation: Returns `T::lowest_layer_type` if it exists, else returns `T`. ]] [[ - [link beast.ref.boost__beast__has_get_io_service `has_get_io_service`] + [link beast.ref.boost__beast__has_get_executor `has_get_executor`] ][ - Determine if the `get_io_service` member function is present, - and returns an __io_service__. + Determine if the `get_executor` member function is present. ]] [[ [link beast.ref.boost__beast__is_async_read_stream `is_async_read_stream`] diff --git a/doc/qbk/03_core/3_buffers.qbk b/doc/qbk/03_core/3_buffers.qbk index 93d869f1..38010ea5 100644 --- a/doc/qbk/03_core/3_buffers.qbk +++ b/doc/qbk/03_core/3_buffers.qbk @@ -9,36 +9,71 @@ [section Buffer Types] -__Asio__ provides the __ConstBufferSequence__ and __MutableBufferSequence__ -concepts, whose models provide ranges of buffers, as well as the __streambuf__ -class which encapsulates memory storage that may be automatically resized as -required, where the memory is divided into an input sequence followed by an -output sequence. The Networking TS (__N4588__) generalizes this `streambuf` -interface into the __DynamicBuffer__ concept. Beast algorithms which require -resizable buffers accept dynamic buffer objects as templated parameters. -These metafunctions check if types match the buffer concepts: +To facilitate working with instances of the __ConstBufferSequence__ and +__MutableBufferSequence__ concepts introduced in __Asio__, Beast treats +those sequences as a special type of range. The following algorithms and +wrappers are provided which transform these ranges efficiently using lazy +evaluation. No memory allocations are used in the transformations; instead, +they create lightweight iterators over the existing, unmodified memory +buffers. Control of buffers is retained by the caller; ownership is not +transferred. -[table Buffer Type Checks +[table Buffer Algorithms and Types [[Name][Description]] [[ - [link beast.ref.boost__beast__is_dynamic_buffer `is_dynamic_buffer`] + [link beast.ref.boost__beast__buffers_cat `buffers_cat`] ][ - Determine if a type meets the requirements of __DynamicBuffer__. + This functions returns a new buffer sequence which, when iterated, + traverses the sequence which would be formed if all of the input buffer + sequences were concatenated. With this routine, multiple calls to a + stream's `write_some` function may be combined into one, eliminating + expensive system calls. ]] [[ - [link beast.ref.boost__beast__is_const_buffer_sequence `is_const_buffer_sequence`] + [link beast.ref.boost__beast__buffers_cat_view `buffers_cat_view`] ][ - Determine if a type meets the requirements of __ConstBufferSequence__. + This class represents the buffer sequence formed by concatenating + two or more buffer sequences. This is type of object returned by + [link beast.ref.boost__beast__buffers_cat `buffers_cat`]. ]] [[ - [link beast.ref.boost__beast__is_mutable_buffer_sequence `is_mutable_buffer_sequence`] + [link beast.ref.boost__beast__buffers_front `buffers_front`] ][ - Determine if a type meets the requirements of __MutableBufferSequence__. + This function returns the first buffer in a buffer sequence, + or a buffer of size zero if the buffer sequence has no elements. +]] +[[ + [link beast.ref.boost__beast__buffers_prefix `buffers_prefix`] +][ + This function returns a new buffer or buffer sequence which represents + a prefix of the original buffers. +]] +[[ + [link beast.ref.boost__beast__buffers_prefix_view `buffers_prefix_view`] +][ + This class represents the buffer sequence formed from a prefix of + an existing buffer sequence. This is the type of buffer returned by + [link beast.ref.boost__beast__buffers_prefix.overload3 `buffers_prefix`]. +]] +[[ + [link beast.ref.boost__beast__buffers_suffix `buffers_suffix`] +][ + This class wraps the underlying memory of an existing buffer sequence + and presents a suffix of the original sequence. The length of the suffix + may be progressively shortened. This lets callers work with sequential + increments of a buffer sequence. +]] +[[ + [link beast.ref.boost__beast__buffers_to_string `buffers_to_string`] +][ + This function converts a buffer sequence to a `std::string`. It can + be used for diagnostic purposes and tests. ]] ] -Beast provides several dynamic buffer implementations for a variety -of scenarios: +The __DynamicBuffer__ concept introduced in __Asio__ models a buffer +sequence which supports an owning, resizable range. Beast provides this +set of additional implementations of the dynamic buffer concept: [table Dynamic Buffer Implementations [[Name][Description]] @@ -95,68 +130,6 @@ of scenarios: ]] ] -Network applications frequently need to manipulate buffer sequences. To -facilitate working with buffers the library treats these sequences as -a special type of range. Algorithms and wrappers are provided which -transform these ranges efficiently using lazy evaluation. No memory -allocations are used in the transformations; instead, they create -lightweight iterators over the existing, unmodified memory buffers. -Control of buffers is retained by the caller; ownership is not -transferred. - -[table Buffer Algorithms and Types -[[Name][Description]] -[[ - [link beast.ref.boost__beast__buffers_cat `buffers_cat`] -][ - This functions returns a new buffer sequence which, when iterated, - traverses the sequence which would be formed if all of the input buffer - sequences were concatenated. With this routine, multiple calls to a - stream's `write_some` function may be combined into one, eliminating - expensive system calls. -]] -[[ - [link beast.ref.boost__beast__buffers_cat_view `buffers_cat_view`] -][ - This class represents the buffer sequence formed by concatenating - two or more buffer sequences. This is type of object returned by - [link beast.ref.boost__beast__buffers_cat `buffers_cat`]. -]] -[[ - [link beast.ref.boost__beast__buffers_front `buffers_front`] -][ - This function returns the first buffer in a buffer sequence, - or a buffer of size zero if the buffer sequence has no elements. -]] -[[ - [link beast.ref.boost__beast__buffers_prefix `buffers_prefix`] -][ - This function returns a new buffer or buffer sequence which represents - a prefix of the original buffers. -]] -[[ - [link beast.ref.boost__beast__buffers_prefix_view `buffers_prefix_view`] -][ - This class represents the buffer sequence formed from a prefix of - an existing buffer sequence. This is the type of buffer returned by - [link beast.ref.boost__beast__buffers_prefix.overload3 `buffers_prefix`]. -]] -[[ - [link beast.ref.boost__beast__buffers_suffix `buffers_suffix`] -][ - This class wraps the underlying memory of an existing buffer sequence - and presents a suffix of the original sequence. The length of the suffix - may be progressively shortened. This lets callers work with sequential - increments of a buffer sequence. -]] -[[ - [link beast.ref.boost__beast__buffers_to_string `buffers_to_string`] -][ - This function converts a buffer sequence to a `std::string`. It can - be used for diagnostic purposes and tests. -]] -] - These two functions facilitate buffer interoperability with standard output streams. diff --git a/doc/qbk/03_core/5_composed.qbk b/doc/qbk/03_core/5_composed.qbk index 81cacb56..85965f7e 100644 --- a/doc/qbk/03_core/5_composed.qbk +++ b/doc/qbk/03_core/5_composed.qbk @@ -38,23 +38,6 @@ composed operations: [table Asynchronous Helpers [[Name][Description]] -[[ - [link beast.ref.boost__beast__async_completion `async_completion`] -][ - This class aggregates the completion handler customization point and - the asynchronous initiation function return value customization point - into a single object which exposes the appropriate output types for the - given input types, and also contains boilerplate that is necessary to - implement an initiation function using the Extensible Model. -]] -[[ - [link beast.ref.boost__beast__async_return_type `async_return_type`] -][ - This template alias determines the return value of an asynchronous - initiation function given the completion token and signature. It is used - by asynchronous initiation functions to meet the requirements of the - Extensible Asynchronous Model. -]] [[ [link beast.ref.boost__beast__bind_handler `bind_handler`] ][ @@ -66,15 +49,6 @@ composed operations: `asio_handler_invoke` associated with the original completion handler. ]] -[[ - [link beast.ref.boost__beast__handler_alloc `handler_alloc`] -][ - This class meets the requirements of [*Allocator], and uses any custom - memory allocation and deallocation hooks associated with a given handler. - It is useful for when a composed operation requires temporary dynamic - allocations to achieve its result. Memory allocated using this allocator - must be freed before the final completion handler is invoked. -]] [[ [link beast.ref.boost__beast__handler_ptr `handler_ptr`] ][ @@ -87,14 +61,6 @@ composed operations: associated allocator, benefiting from all handler memory management optimizations transparently. ]] -[[ - [link beast.ref.boost__beast__handler_type `handler_type`] -][ - This template alias converts a completion token and signature to the - correct completion handler type. It is used in the implementation of - asynchronous initiation functions to meet the requirements of the - Extensible Asynchronous Model. -]] ] @@ -203,27 +169,28 @@ composed operations: * Type erasing the final handler. This will cause undefined behavior. -* Not using `std::addressof` to get the address of the handler. - * Forgetting to include a return statement after calling an initiating function. * Calling a synchronous function by accident. In general composed operations should not block for long periods of time, since this - ties up a thread running on the __io_service__. + ties up a thread running on the __io_context__. -* Forgetting to overload `asio_handler_invoke` for the composed - operation. This will cause undefined behavior if someone calls - the initiating function with a strand-wrapped function object, - and there is more than thread running on the `io_service`. +* Forgetting to provide `executor_type` and `get_executor` for the + composed operation. This will cause undefined behavior. For example, + if someone calls the initiating function with a strand-wrapped + function object, and there is more than thread running on the + `io_context`, the underlying stream may be accessed in a fashion + that violates safety guarantees. * For operations which complete immediately (i.e. without calling an - intermediate initiating function), forgetting to use `io_service::post` + intermediate initiating function), forgetting to use + [@http://www.boost.org/doc/html/boost_asio/reference/post.html `boost::asio::post`] to invoke the final handler. This breaks the following initiating function guarantee: ['Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed - in a manner equivalent to using `boost::asio::io_service::post`]. + in a manner equivalent to using `boost::asio::post`]. The function [link beast.ref.boost__beast__bind_handler `bind_handler`] is provided for this purpose. diff --git a/doc/qbk/04_http/03_streams.qbk b/doc/qbk/04_http/03_streams.qbk index 9b7854ab..f01771c6 100644 --- a/doc/qbk/04_http/03_streams.qbk +++ b/doc/qbk/04_http/03_streams.qbk @@ -83,9 +83,9 @@ as this example shows. If a read stream algorithm cannot complete its operation without exceeding the maximum specified size of the dynamic buffer provided, the error [link beast.ref.boost__beast__http__error `buffer_overflow`] -is returned. This may be used to impose a limit on the maximum size of an -HTTP message header for protection from buffer overflow attacks. The -following code will print the error message: +is returned. This is one technique which may be used to impose a limit on +the maximum size of an HTTP message header for protection from buffer +overflow attacks. The following code will print the error message: [http_snippet_6] diff --git a/doc/qbk/04_http/08_chunked_encoding.qbk b/doc/qbk/04_http/08_chunked_encoding.qbk index 1044c5ee..9fcd1ae4 100644 --- a/doc/qbk/04_http/08_chunked_encoding.qbk +++ b/doc/qbk/04_http/08_chunked_encoding.qbk @@ -31,7 +31,7 @@ field value. [heading Serializing Chunks] -The __serializer__ automatically applies the chunked tranfer encoding +The __serializer__ automatically applies the chunked transfer encoding when a message returns `true` from [link beast.ref.boost__beast__http__message.chunked.overload1 `message::chunked`]. The boundaries between chunks emitted by the serializer are implementation diff --git a/doc/qbk/06_websocket/1_streams.qbk b/doc/qbk/06_websocket/1_streams.qbk index 670fdec5..be43e1a3 100644 --- a/doc/qbk/06_websocket/1_streams.qbk +++ b/doc/qbk/06_websocket/1_streams.qbk @@ -19,7 +19,7 @@ are performed, or both. Any arguments supplied during construction of the stream wrapper are passed to next layer's constructor. Here we declare a websocket stream over a TCP/IP socket with ownership -of the socket. The `io_service` argument is forwarded to the wrapped +of the socket. The `io_context` argument is forwarded to the wrapped socket's constructor: [ws_snippet_2] @@ -27,7 +27,7 @@ socket's constructor: [heading Using SSL] To use WebSockets over SSL, use an instance of the `boost::asio::ssl::stream` -class template as the template type for the stream. The required `io_service` +class template as the template type for the stream. The required `io_context` and `ssl::context` arguments are forwarded to the wrapped stream's constructor: [wss_snippet_1] diff --git a/doc/qbk/06_websocket/3_client.qbk b/doc/qbk/06_websocket/3_client.qbk index 0a544f6a..e5574a4c 100644 --- a/doc/qbk/06_websocket/3_client.qbk +++ b/doc/qbk/06_websocket/3_client.qbk @@ -88,7 +88,7 @@ a successful upgrade, the caller may wish to perform additional validation on the received HTTP response message. For example, to check that the response to a basic authentication challenge is valid. To achieve this, overloads of the handshake member function allow the caller to store the -received HTTP message in an output reference argument as +received HTTP message in an output reference argument of type [link beast.ref.boost__beast__websocket__response_type `response_type`] as follows: diff --git a/doc/qbk/06_websocket/8_notes.qbk b/doc/qbk/06_websocket/8_notes.qbk index e85a0bd4..8cd210a9 100644 --- a/doc/qbk/06_websocket/8_notes.qbk +++ b/doc/qbk/06_websocket/8_notes.qbk @@ -31,9 +31,12 @@ handlers, stackful or stackless coroutines, and even futures: [ws_snippet_21] -[heading The io_service] +The example programs that come with the library demonstrate the usage of +websocket stream operations with all asynchronous varieties. -The creation and operation of the __io_service__ associated with the +[heading The io_context] + +The creation and operation of the __io_context__ associated with the underlying stream is left to the callers, permitting any implementation strategy including one that does not require threads for environments where threads are unavailable. Beast WebSocket itself does not use @@ -45,8 +48,8 @@ Like a regular __Asio__ socket, a [link beast.ref.boost__beast__websocket__stream `stream`] is not thread safe. Callers are responsible for synchronizing operations on the socket using an implicit or explicit strand, as per the Asio documentation. -The asynchronous interface supports one of each of the following operations -to be active at the same time: +The websocket stream asynchronous interface supports one of each of the +following operations to be active at the same time: * [link beast.ref.boost__beast__websocket__stream.async_read `async_read`] or [link beast.ref.boost__beast__websocket__stream.async_read_some `async_read_some`] * [link beast.ref.boost__beast__websocket__stream.async_write `async_write`] or [link beast.ref.boost__beast__websocket__stream.async_write_some `async_write_some`] diff --git a/doc/qbk/07_concepts/DynamicBuffer.qbk b/doc/qbk/07_concepts/DynamicBuffer.qbk index e7ac1dd4..cb22dd60 100644 --- a/doc/qbk/07_concepts/DynamicBuffer.qbk +++ b/doc/qbk/07_concepts/DynamicBuffer.qbk @@ -35,7 +35,7 @@ implementation strategies: [heading Associated Types] -* [link beast.ref.boost__beast__is_dynamic_buffer `is_dynamic_buffer`] +* `boost::asio::is_dynamic_buffer` * __ConstBufferSequence__ * __MutableBufferSequence__ diff --git a/doc/qbk/07_concepts/Fields.qbk b/doc/qbk/07_concepts/Fields.qbk index 59ff70a9..05e626e5 100644 --- a/doc/qbk/07_concepts/Fields.qbk +++ b/doc/qbk/07_concepts/Fields.qbk @@ -190,7 +190,7 @@ In this table: [ If `(v < 11 && b)`, then all "close" tokens present in the value are removed, and the "keep-alive" token is added to - the valueif it is not already present. + the value if it is not already present. ][ If `(v < 11 && ! b)`, then all "close" and "keep-alive" tokens present in the value are removed. diff --git a/doc/qbk/08_design.qbk b/doc/qbk/08_design.qbk index ef75ac63..3ccf057f 100644 --- a/doc/qbk/08_design.qbk +++ b/doc/qbk/08_design.qbk @@ -32,7 +32,7 @@ __MutableBufferSequence__ concepts for passing buffers to functions. The authors have found the dynamic buffer and buffer sequence interfaces to be optimal for interacting with Asio, and for other tasks such as incremental parsing of data in buffers (for example, parsing websocket frames stored -in a [link beast.ref.boost__beast__flat_static_buffer `flat_static_buffer`]). +in a [link beast.ref.boost__beast__static_buffer `static_buffer`]). During the development of Beast the authors have studied other software packages and in particular the comments left during the Boost Review process diff --git a/doc/qbk/08_design/1_http_message.qbk b/doc/qbk/08_design/1_http_message.qbk index c66e0646..2485d0de 100644 --- a/doc/qbk/08_design/1_http_message.qbk +++ b/doc/qbk/08_design/1_http_message.qbk @@ -260,10 +260,10 @@ struct header : Fields }; ``` -The start-line data members are replaced traditional accessors using -non-owning references to string buffers. The method is stored using -a simple integer instead of the entire string, for the case where -the method is recognized from the set of known verb strings. +The start-line data members are replaced by traditional accessors +using non-owning references to string buffers. The method is stored +using a simple integer instead of the entire string, for the case +where the method is recognized from the set of known verb strings. Now we add a requirement to the fields type: management of the corresponding string is delegated to the [*Fields] container, which can diff --git a/doc/qbk/08_design/3_websocket_zaphoyd.qbk b/doc/qbk/08_design/3_websocket_zaphoyd.qbk index 271b9ee3..945380cd 100644 --- a/doc/qbk/08_design/3_websocket_zaphoyd.qbk +++ b/doc/qbk/08_design/3_websocket_zaphoyd.qbk @@ -122,7 +122,7 @@ through the __asio_handler_invoke__ mechanism. The only requirement in Beast is that calls to asynchronous initiation functions are made from the same implicit or explicit strand. For -example, if the `io_service` associated with a `beast::websocket::stream` +example, if the `io_context` associated with a `beast::websocket::stream` is single threaded, this counts as an implicit strand and no performance costs associated with mutexes are incurred. diff --git a/doc/qbk/quickref.xml b/doc/qbk/quickref.xml index 837ac750..1a9239c8 100644 --- a/doc/qbk/quickref.xml +++ b/doc/qbk/quickref.xml @@ -174,9 +174,6 @@ Classes - async_completion - async_result - async_return_type basic_flat_buffer basic_multi_buffer buffered_read_stream @@ -197,9 +194,7 @@ flat_buffer flat_static_buffer flat_static_buffer_base - handler_alloc handler_ptr - handler_type iequal iless multi_buffer @@ -236,15 +231,12 @@ Type Traits get_lowest_layer - has_get_io_service + has_get_executor is_async_read_stream is_async_write_stream is_async_stream is_completion_handler - is_const_buffer_sequence - is_dynamic_buffer is_file - is_mutable_buffer_sequence is_sync_read_stream is_sync_stream is_sync_write_stream diff --git a/doc/source.dox b/doc/source.dox index 86e85dd7..4d9d07ad 100644 --- a/doc/source.dox +++ b/doc/source.dox @@ -285,7 +285,9 @@ INCLUDE_FILE_PATTERNS = PREDEFINED = \ BOOST_BEAST_DOXYGEN \ BOOST_BEAST_USE_POSIX_FILE=1 \ - BOOST_BEAST_USE_WIN32_FILE=1 + BOOST_BEAST_USE_WIN32_FILE=1 \ + BOOST_ASIO_INITFN_RESULT_TYPE(t,a)=void_or_deduced \ + GENERATING_DOCUMENTATION EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES diff --git a/example/advanced/server-flex/advanced_server_flex.cpp b/example/advanced/server-flex/advanced_server_flex.cpp index 5391b413..1531141a 100644 --- a/example/advanced/server-flex/advanced_server_flex.cpp +++ b/example/advanced/server-flex/advanced_server_flex.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -235,15 +236,16 @@ class websocket_session boost::beast::multi_buffer buffer_; protected: - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::asio::steady_timer timer_; public: // Construct the session explicit - websocket_session(boost::asio::io_service& ios) - : strand_(ios) - , timer_(ios, + websocket_session(boost::asio::io_context& ioc) + : strand_(ioc.get_executor()) + , timer_(ioc, (std::chrono::steady_clock::time_point::max)()) { } @@ -254,15 +256,17 @@ public: do_accept(http::request> req) { // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Accept the websocket handshake derived().ws().async_accept( req, - strand_.wrap(std::bind( - &websocket_session::on_accept, - derived().shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &websocket_session::on_accept, + derived().shared_from_this(), + std::placeholders::_1))); } // Called when the timer expires. @@ -273,15 +277,17 @@ public: return fail(ec, "timer"); // Verify that the timer really expired since the deadline may have moved. - if(timer_.expires_at() <= std::chrono::steady_clock::now()) + if(timer_.expiry() <= std::chrono::steady_clock::now()) derived().do_timeout(); // Wait on the timer timer_.async_wait( - strand_.wrap(std::bind( - &websocket_session::on_timer, - derived().shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &websocket_session::on_timer, + derived().shared_from_this(), + std::placeholders::_1))); } void @@ -302,16 +308,18 @@ public: do_read() { // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Read a message into our buffer derived().ws().async_read( buffer_, - strand_.wrap(std::bind( - &websocket_session::on_read, - derived().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &websocket_session::on_read, + derived().shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -336,11 +344,13 @@ public: derived().ws().text(derived().ws().got_text()); derived().ws().async_write( buffer_.data(), - strand_.wrap(std::bind( - &websocket_session::on_write, - derived().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &websocket_session::on_write, + derived().shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -378,7 +388,7 @@ public: explicit plain_websocket_session(tcp::socket socket) : websocket_session( - socket.get_io_service()) + socket.get_executor().context()) , ws_(std::move(socket)) { } @@ -412,15 +422,17 @@ public: close_ = true; // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Close the WebSocket Connection ws_.async_close( websocket::close_code::normal, - strand_.wrap(std::bind( - &plain_websocket_session::on_close, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &plain_websocket_session::on_close, + shared_from_this(), + std::placeholders::_1))); } void @@ -443,7 +455,8 @@ class ssl_websocket_session , public std::enable_shared_from_this { websocket::stream> ws_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; bool eof_ = false; public: @@ -451,9 +464,9 @@ public: explicit ssl_websocket_session(ssl_stream stream) : websocket_session( - stream.get_io_service()) + stream.get_executor().context()) , ws_(std::move(stream)) - , strand_(ws_.get_io_service()) + , strand_(ws_.get_executor()) { } @@ -483,14 +496,16 @@ public: eof_ = true; // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Perform the SSL shutdown ws_.next_layer().async_shutdown( - strand_.wrap(std::bind( - &ssl_websocket_session::on_shutdown, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &ssl_websocket_session::on_shutdown, + shared_from_this(), + std::placeholders::_1))); } void @@ -630,10 +645,12 @@ class http_session http::async_write( self_.derived().stream(), msg_, - self_.strand_.wrap(std::bind( - &http_session::on_write, - self_.derived().shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + self_.strand_, + std::bind( + &http_session::on_write, + self_.derived().shared_from_this(), + std::placeholders::_1))); } }; @@ -652,20 +669,21 @@ class http_session protected: boost::asio::steady_timer timer_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::flat_buffer buffer_; public: // Construct the session http_session( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, boost::beast::flat_buffer buffer, std::string const& doc_root) : doc_root_(doc_root) , queue_(*this) - , timer_(ios, + , timer_(ioc, (std::chrono::steady_clock::time_point::max)()) - , strand_(ios) + , strand_(ioc.get_executor()) , buffer_(std::move(buffer)) { } @@ -674,17 +692,19 @@ public: do_read() { // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Read a request http::async_read( derived().stream(), buffer_, req_, - strand_.wrap(std::bind( - &http_session::on_read, - derived().shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &http_session::on_read, + derived().shared_from_this(), + std::placeholders::_1))); } // Called when the timer expires. @@ -695,15 +715,17 @@ public: return fail(ec, "timer"); // Verify that the timer really expired since the deadline may have moved. - if(timer_.expires_at() <= std::chrono::steady_clock::now()) + if(timer_.expiry() <= std::chrono::steady_clock::now()) return derived().do_timeout(); // Wait on the timer timer_.async_wait( - strand_.wrap(std::bind( - &http_session::on_timer, - derived().shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &http_session::on_timer, + derived().shared_from_this(), + std::placeholders::_1))); } void @@ -769,7 +791,8 @@ class plain_http_session , public std::enable_shared_from_this { tcp::socket socket_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; public: // Create the http_session @@ -778,11 +801,11 @@ public: boost::beast::flat_buffer buffer, std::string const& doc_root) : http_session( - socket.get_io_service(), + socket.get_executor().context(), std::move(buffer), doc_root) , socket_(std::move(socket)) - , strand_(socket_.get_io_service()) + , strand_(socket_.get_executor()) { } @@ -838,7 +861,8 @@ class ssl_http_session , public std::enable_shared_from_this { ssl_stream stream_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; bool eof_ = false; public: @@ -849,11 +873,11 @@ public: boost::beast::flat_buffer buffer, std::string const& doc_root) : http_session( - socket.get_io_service(), + socket.get_executor().context(), std::move(buffer), doc_root) , stream_(std::move(socket), ctx) - , strand_(stream_.get_io_service()) + , strand_(stream_.get_executor()) { } @@ -880,18 +904,20 @@ public: on_timer({}); // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Perform the SSL handshake // Note, this is the buffered version of the handshake. stream_.async_handshake( ssl::stream_base::server, buffer_.data(), - strand_.wrap(std::bind( - &ssl_http_session::on_handshake, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &ssl_http_session::on_handshake, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void on_handshake( @@ -917,14 +943,16 @@ public: eof_ = true; // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Perform the SSL shutdown stream_.async_shutdown( - strand_.wrap(std::bind( - &ssl_http_session::on_shutdown, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &ssl_http_session::on_shutdown, + shared_from_this(), + std::placeholders::_1))); } void @@ -962,7 +990,8 @@ class detect_session : public std::enable_shared_from_this { tcp::socket socket_; ssl::context& ctx_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; std::string const& doc_root_; boost::beast::flat_buffer buffer_; @@ -974,7 +1003,7 @@ public: std::string const& doc_root) : socket_(std::move(socket)) , ctx_(ctx) - , strand_(socket_.get_io_service()) + , strand_(socket_.get_executor()) , doc_root_(doc_root) { } @@ -986,11 +1015,13 @@ public: async_detect_ssl( socket_, buffer_, - strand_.wrap(std::bind( - &detect_session::on_detect, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &detect_session::on_detect, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } @@ -1029,13 +1060,13 @@ class listener : public std::enable_shared_from_this public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, tcp::endpoint endpoint, std::string const& doc_root) : ctx_(ctx) - , acceptor_(ios) - , socket_(ios) + , acceptor_(ioc) + , socket_(ioc) , doc_root_(doc_root) { boost::system::error_code ec; @@ -1058,7 +1089,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -1120,13 +1151,13 @@ int main(int argc, char* argv[]) " advanced-server-flex 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -1136,7 +1167,7 @@ int main(int argc, char* argv[]) // Create and launch a listening port std::make_shared( - ios, + ioc, ctx, tcp::endpoint{address, port}, doc_root)->run(); @@ -1146,11 +1177,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/advanced/server/advanced_server.cpp b/example/advanced/server/advanced_server.cpp index c8d5b78e..da3f82ac 100644 --- a/example/advanced/server/advanced_server.cpp +++ b/example/advanced/server/advanced_server.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -214,7 +215,8 @@ fail(boost::system::error_code ec, char const* what) class websocket_session : public std::enable_shared_from_this { websocket::stream ws_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::asio::steady_timer timer_; boost::beast::multi_buffer buffer_; @@ -223,8 +225,8 @@ public: explicit websocket_session(tcp::socket socket) : ws_(std::move(socket)) - , strand_(ws_.get_io_service()) - , timer_(ws_.get_io_service(), + , strand_(ws_.get_executor()) + , timer_(ws_.get_executor().context(), (std::chrono::steady_clock::time_point::max)()) { } @@ -239,15 +241,17 @@ public: on_timer({}); // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Accept the websocket handshake ws_.async_accept( req, - strand_.wrap(std::bind( - &websocket_session::on_accept, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &websocket_session::on_accept, + shared_from_this(), + std::placeholders::_1))); } // Called when the timer expires. @@ -258,7 +262,7 @@ public: return fail(ec, "timer"); // Verify that the timer really expired since the deadline may have moved. - if(timer_.expires_at() <= std::chrono::steady_clock::now()) + if(timer_.expiry() <= std::chrono::steady_clock::now()) { // Closing the socket cancels all outstanding operations. They // will complete with boost::asio::error::operation_aborted @@ -269,10 +273,12 @@ public: // Wait on the timer timer_.async_wait( - strand_.wrap(std::bind( - &websocket_session::on_timer, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &websocket_session::on_timer, + shared_from_this(), + std::placeholders::_1))); } void @@ -293,16 +299,18 @@ public: do_read() { // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Read a message into our buffer ws_.async_read( buffer_, - strand_.wrap(std::bind( - &websocket_session::on_read, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &websocket_session::on_read, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -327,11 +335,13 @@ public: ws_.text(ws_.got_text()); ws_.async_write( buffer_.data(), - strand_.wrap(std::bind( - &websocket_session::on_write, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &websocket_session::on_write, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -432,10 +442,12 @@ class http_session : public std::enable_shared_from_this http::async_write( self_.socket_, msg_, - self_.strand_.wrap(std::bind( - &http_session::on_write, - self_.shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + self_.strand_, + std::bind( + &http_session::on_write, + self_.shared_from_this(), + std::placeholders::_1))); } }; @@ -449,7 +461,8 @@ class http_session : public std::enable_shared_from_this }; tcp::socket socket_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::asio::steady_timer timer_; boost::beast::flat_buffer buffer_; std::string const& doc_root_; @@ -463,8 +476,8 @@ public: tcp::socket socket, std::string const& doc_root) : socket_(std::move(socket)) - , strand_(socket_.get_io_service()) - , timer_(socket_.get_io_service(), + , strand_(socket_.get_executor()) + , timer_(socket_.get_executor().context(), (std::chrono::steady_clock::time_point::max)()) , doc_root_(doc_root) , queue_(*this) @@ -486,14 +499,16 @@ public: do_read() { // Set the timer - timer_.expires_from_now(std::chrono::seconds(15)); + timer_.expires_after(std::chrono::seconds(15)); // Read a request http::async_read(socket_, buffer_, req_, - strand_.wrap(std::bind( - &http_session::on_read, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &http_session::on_read, + shared_from_this(), + std::placeholders::_1))); } // Called when the timer expires. @@ -504,7 +519,7 @@ public: return fail(ec, "timer"); // Verify that the timer really expired since the deadline may have moved. - if(timer_.expires_at() <= std::chrono::steady_clock::now()) + if(timer_.expiry() <= std::chrono::steady_clock::now()) { // Closing the socket cancels all outstanding operations. They // will complete with boost::asio::error::operation_aborted @@ -515,10 +530,12 @@ public: // Wait on the timer timer_.async_wait( - strand_.wrap(std::bind( - &http_session::on_timer, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &http_session::on_timer, + shared_from_this(), + std::placeholders::_1))); } void @@ -599,11 +616,11 @@ class listener : public std::enable_shared_from_this public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint, std::string const& doc_root) - : acceptor_(ios) - , socket_(ios) + : acceptor_(ioc) + , socket_(ioc) , doc_root_(doc_root) { boost::system::error_code ec; @@ -626,7 +643,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -687,17 +704,17 @@ int main(int argc, char* argv[]) " advanced-server 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // Create and launch a listening port std::make_shared( - ios, + ioc, tcp::endpoint{address, port}, doc_root)->run(); @@ -706,11 +723,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/common/detect_ssl.hpp b/example/common/detect_ssl.hpp index 9018ebdc..6d031aa6 100644 --- a/example/common/detect_ssl.hpp +++ b/example/common/detect_ssl.hpp @@ -61,7 +61,8 @@ is_ssl_handshake( ConstBufferSequence const& buffers) { // Make sure buffers meets the requirements - static_assert(boost::beast::is_const_buffer_sequence::value, + static_assert( + boost::asio::is_const_buffer_sequence::value, "ConstBufferSequence requirements not met"); // We need at least one byte to really do anything @@ -135,7 +136,8 @@ detect_ssl( // Make sure arguments meet the requirements static_assert(beast::is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); // Loop until an error occurs or we get a definitive answer @@ -219,15 +221,15 @@ detect_ssl( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class AsyncReadStream, class DynamicBuffer, class CompletionToken> -boost::beast::async_return_type< /*< The [link beast.ref.boost__beast__async_return_type `async_return_type`] customizes the return value based on the completion token >*/ +BOOST_ASIO_INITFN_RESULT_TYPE( /*< `BOOST_ASIO_INITFN_RESULT_TYPE` customizes the return value based on the completion token >*/ CompletionToken, - void(boost::beast::error_code, boost::tribool)> /*< This is the signature for the completion handler >*/ + void(boost::beast::error_code, boost::tribool)) /*< This is the signature for the completion handler >*/ async_detect_ssl( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -249,9 +251,9 @@ template< class AsyncReadStream, class DynamicBuffer, class CompletionToken> -boost::beast::async_return_type< +BOOST_ASIO_INITFN_RESULT_TYPE( CompletionToken, - void(boost::beast::error_code, boost::tribool)> + void(boost::beast::error_code, boost::tribool)) async_detect_ssl( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -262,26 +264,29 @@ async_detect_ssl( // Make sure arguments meet the requirements static_assert(beast::is_async_read_stream::value, "SyncReadStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); // This helper manages some of the handler's lifetime and // uses the result and handler specializations associated with // the completion token to help customize the return value. // - beast::async_completion< + boost::asio::async_completion< CompletionToken, void(beast::error_code, boost::tribool)> init{token}; // Create the composed operation and launch it. This is a constructor - // call followed by invocation of operator(). We use handler_type + // call followed by invocation of operator(). We use BOOST_ASIO_HANDLER_TYPE // to convert the completion token into the correct handler type, // allowing user defined specializations of the async result template // to take effect. // - detect_ssl_op>{ - stream, buffer, init.completion_handler}( - beast::error_code{}, 0); + detect_ssl_op< + AsyncReadStream, + DynamicBuffer, + BOOST_ASIO_HANDLER_TYPE( + CompletionToken, void(beast::error_code, boost::tribool))>{ + stream, buffer, init.completion_handler}(beast::error_code{}, 0); // This hook lets the caller see a return value when appropriate. // For example this might return std::future if @@ -336,6 +341,35 @@ public: { } + // Associated allocator support. This is Asio's system for + // allowing the final completion handler to customize the + // memory allocation strategy used for composed operation + // states. A composed operation needs to use the same allocator + // as the final handler. These declarations achieve that. + + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(handler_); + } + + // Executor hook. This is Asio's system for customizing the + // manner in which asynchronous completion handlers are invoked. + // A composed operation needs to use the same executor to invoke + // intermediate completion handlers as that used to invoke the + // final handler. + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(stream_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor(handler_, stream_.get_executor()); + } + // Determines if the next asynchronous operation represents a // continuation of the asynchronous flow of control associated // with the final handler. If we are past step two, it means @@ -358,34 +392,6 @@ public: asio_handler_is_continuation(std::addressof(op->handler_)); } - // Handler hook forwarding. These free functions invoke the hooks - // associated with the final completion handler. In effect, they - // make the Asio implementation treat our composed operation the - // same way it would treat the final completion handler for the - // purpose of memory allocation and invocation. - // - // Our implementation just passes through the call to the hook - // associated with the final handler. - - friend void* asio_handler_allocate(std::size_t size, detect_ssl_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate(size, std::addressof(op->handler_)); - } - - friend void asio_handler_deallocate(void* p, std::size_t size, detect_ssl_op* op) - { - using boost::asio::asio_handler_deallocate; - return asio_handler_deallocate(p, size, std::addressof(op->handler_)); - } - - template - friend void asio_handler_invoke(Function&& f, detect_ssl_op* op) - { - using boost::asio::asio_handler_invoke; - return asio_handler_invoke(f, std::addressof(op->handler_)); - } - // Our main entry point. This will get called as our // intermediate operations complete. Definition below. // @@ -424,12 +430,13 @@ operator()(boost::beast::error_code ec, std::size_t bytes_transferred) // We need to invoke the handler, but the guarantee // is that the handler will not be called before the // call to async_detect_ssl returns, so we must post - // the operation to the io_service. The helper function + // the operation to the executor. The helper function // `bind_handler` lets us bind arguments in a safe way // that preserves the type customization hooks of the // original handler. step_ = 1; - return stream_.get_io_service().post( + return boost::asio::post( + stream_.get_executor(), beast::bind_handler(std::move(*this), ec, 0)); } diff --git a/example/common/session_alloc.hpp b/example/common/session_alloc.hpp index 5730e235..40615e0a 100644 --- a/example/common/session_alloc.hpp +++ b/example/common/session_alloc.hpp @@ -10,21 +10,21 @@ #ifndef BOOST_BEAST_EXAMPLE_COMMON_SESSION_ALLOC_HPP #define BOOST_BEAST_EXAMPLE_COMMON_SESSION_ALLOC_HPP -#include +#include +#include #include -#include #include #include #include #include #include +namespace detail { + template class session_alloc_base { - template - class wrapped_handler; - +protected: class pool_t { using hook_type = @@ -78,23 +78,18 @@ class session_alloc_base boost::intrusive::constant_time_size< true>>::type; - Context* ctx_; std::size_t refs_ = 1; // shared count std::size_t high_ = 0; // highest used std::size_t size_ = 0; // size of buf_ char* buf_ = nullptr; // a large block list_type list_; // list of allocations - explicit - pool_t(Context* ctx) - : ctx_(ctx) - { - } + pool_t() = default; public: static pool_t& - construct(Context* ctx); + construct(); ~pool_t(); @@ -110,73 +105,178 @@ class session_alloc_base void dealloc(void* pv, std::size_t n); }; - - pool_t& pool_; - -public: - session_alloc_base& operator=(session_alloc_base const&) = delete; - - ~session_alloc_base() - { - pool_.release(); - } - - session_alloc_base() - : pool_(pool_t::construct(nullptr)) - { - static_assert(std::is_same::value, - "Context requirements not met"); - } - - session_alloc_base(session_alloc_base const& other) - : pool_(other.pool_.addref()) - { - } - - template, - typename std::decay::type - >::value>::type> - explicit - session_alloc_base(DeducedContext& ctx) - : pool_(pool_t::construct(std::addressof(ctx))) - { - static_assert(! std::is_same::value, - "Context requirements not met"); - } - - template - wrapped_handler::type> - wrap(Handler&& handler) - { - return wrapped_handler< - typename std::decay::type>( - std::forward(handler), *this); - } - -protected: - void* - alloc(std::size_t n) - { - return pool_.alloc(n); - } - - void - dealloc(void* p, std::size_t n) - { - pool_.dealloc(p, n); - } }; +template +auto +session_alloc_base:: +pool_t:: +construct() -> + pool_t& +{ + return *(new pool_t); +} + +template +session_alloc_base:: +pool_t:: +~pool_t() +{ + BOOST_ASSERT(list_.size() == 0); + if(buf_) + delete[] buf_; +} + +template +auto +session_alloc_base:: +pool_t:: +addref() -> + pool_t& +{ + ++refs_; + return *this; +} + +template +void +session_alloc_base:: +pool_t:: +release() +{ + if(--refs_) + return; + delete this; +} + +template +void* +session_alloc_base:: +pool_t:: +alloc(std::size_t n) +{ + if(list_.empty() && size_ < high_) + { + if(buf_) + delete[] buf_; + buf_ = new char[high_]; + size_ = high_; + } + if(buf_) + { + char* end; + std::size_t used; + if(list_.empty()) + { + end = buf_; + used = sizeof(element) + n; + } + else + { + end = list_.back().end(); + used = list_.back().used() + + sizeof(element) + n; + } + if(end >= buf_ && end + + sizeof(element) + n <= buf_ + size_) + { + auto& e = *new(end) element{n, used}; + list_.push_back(e); + high_ = (std::max)(high_, used); + return e.data(); + } + } + std::size_t const used = + sizeof(element) + n + ( + buf_ && ! list_.empty() ? + list_.back().used() : 0); + auto& e = *new(new char[sizeof(element) + n]) element{n, used}; + list_.push_back(e); + high_ = (std::max)(high_, used); + return e.data(); +} + +template +void +session_alloc_base:: +pool_t:: +dealloc(void* pv, std::size_t n) +{ + auto& e = *(reinterpret_cast(pv) - 1); + BOOST_ASSERT(e.size() == n); + if( (e.end() > buf_ + size_) || + reinterpret_cast(&e) < buf_) + { + list_.erase(list_.iterator_to(e)); + e.~element(); + delete[] reinterpret_cast(&e); + return; + } + list_.erase(list_.iterator_to(e)); + e.~element(); +} + +} // detail + //------------------------------------------------------------------------------ -template -class session_alloc : public session_alloc_base +template +class session_alloc + : private detail::session_alloc_base { - template + template friend class session_alloc; + template + class wrapped_handler + { + // Can't friend partial specializations, + // so we just friend the whole thing. + template + friend struct boost::asio::associated_executor; + + Handler h_; + session_alloc alloc_; + + public: + wrapped_handler(wrapped_handler&&) = default; + wrapped_handler(wrapped_handler const&) = default; + + template + wrapped_handler( + DeducedHandler&& h, + session_alloc const& alloc) + : h_(std::forward(h)) + , alloc_(alloc) + { + } + + using allocator_type = session_alloc; + + allocator_type + get_allocator() const noexcept; + + template + void + operator()(Args&&... args) const + { + h_(std::forward(args)...); + } + + friend + bool + asio_handler_is_continuation(wrapped_handler* w) + { + using boost::asio::asio_handler_is_continuation; + return asio_handler_is_continuation(std::addressof(w->h_)); + } + }; + + using pool_t = typename + detail::session_alloc_base::pool_t; + + pool_t& pool_; + public: using value_type = T; using is_always_equal = std::false_type; @@ -193,21 +293,32 @@ public: using other = session_alloc; }; - session_alloc() = default; - session_alloc(session_alloc const&) = default; + session_alloc& operator=(session_alloc const&) = delete; + + ~session_alloc() + { + pool_.release(); + } + + session_alloc() + : pool_(pool_t::construct()) + { + } + + session_alloc(session_alloc const& other) noexcept + : pool_(other.pool_.addref()) + { + } template - session_alloc(session_alloc const& other) - : session_alloc_base(static_cast< - session_alloc_base const&>(other)) + session_alloc(session_alloc const& other) noexcept + : pool_(other.pool_) { } - explicit - session_alloc(Context& ctx) - : session_alloc_base(ctx) - { - } + template + wrapped_handler::type> + wrap(Handler&& handler); value_type* allocate(size_type n) @@ -257,209 +368,67 @@ public: { return ! (lhs == rhs); } + +protected: + void* + alloc(std::size_t n) + { + return pool_.alloc(n); + } + + void + dealloc(void* p, std::size_t n) + { + pool_.dealloc(p, n); + } }; //------------------------------------------------------------------------------ -template +template template -class session_alloc_base::wrapped_handler +auto +session_alloc:: +wrapped_handler:: +get_allocator() const noexcept -> + allocator_type { - Handler h_; - session_alloc_base alloc_; - - void* - alloc(std::size_t size) - { - return alloc_.alloc(size); - } - - void - dealloc(void* p, std::size_t size) - { - alloc_.dealloc(p, size); - } - -public: - wrapped_handler(wrapped_handler&&) = default; - wrapped_handler(wrapped_handler const&) = default; - - template - explicit - wrapped_handler(DeducedHandler&& h, - session_alloc_base const& alloc) - : h_(std::forward(h)) - , alloc_(alloc) - { - } - - template - void - operator()(Args&&... args) const - { - h_(std::forward(args)...); - } - - friend - void* - asio_handler_allocate( - std::size_t size, wrapped_handler* w) - { - return w->alloc(size); - } - - friend - void - asio_handler_deallocate( - void* p, std::size_t size, wrapped_handler* w) - { - w->dealloc(p, size); - } - - friend - bool - asio_handler_is_continuation(wrapped_handler* w) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation(std::addressof(w->h_)); - } - - template - friend - void - asio_handler_invoke(F&& f, wrapped_handler* w) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(w->h_)); - } -}; + return alloc_; +} //------------------------------------------------------------------------------ -template +template +template auto -session_alloc_base:: -pool_t:: -construct(Context* ctx) -> - pool_t& +session_alloc:: +wrap(Handler&& handler) -> + wrapped_handler::type> { - using boost::asio::asio_handler_allocate; - return *new(asio_handler_allocate( - sizeof(pool_t), ctx)) pool_t{ctx}; + return wrapped_handler< + typename std::decay::type>( + std::forward(handler), *this); } -template -session_alloc_base:: -pool_t:: -~pool_t() +namespace boost { +namespace asio { +template +struct associated_executor< + session_alloc::wrapped_handler, Executor> { - BOOST_ASSERT(list_.size() == 0); - if(buf_) + using type = typename + associated_executor::type; + + static + type + get(session_alloc::wrapped_handler const& h, + Executor const& ex = Executor()) noexcept { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate(buf_, size_, ctx_); + return associated_executor< + Handler, Executor>::get(h.h_, ex); } -} - -template -auto -session_alloc_base:: -pool_t:: -addref() -> - pool_t& -{ - ++refs_; - return *this; -} - -template -void -session_alloc_base:: -pool_t:: -release() -{ - if(--refs_) - return; - this->~pool_t(); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate(this, sizeof(*this), ctx_); -} - -template -void* -session_alloc_base:: -pool_t:: -alloc(std::size_t n) -{ - if(list_.empty() && size_ < high_) - { - if(buf_) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate(buf_, size_, ctx_); - } - using boost::asio::asio_handler_allocate; - buf_ = reinterpret_cast( - asio_handler_allocate(high_, ctx_)); - size_ = high_; - } - if(buf_) - { - char* end; - std::size_t used; - if(list_.empty()) - { - end = buf_; - used = sizeof(element) + n; - } - else - { - end = list_.back().end(); - used = list_.back().used() + - sizeof(element) + n; - } - if(end >= buf_ && end + - sizeof(element) + n <= buf_ + size_) - { - auto& e = *new(end) element{n, used}; - list_.push_back(e); - high_ = (std::max)(high_, used); - return e.data(); - } - } - std::size_t const used = - sizeof(element) + n + ( - buf_ && ! list_.empty() ? - list_.back().used() : 0); - using boost::asio::asio_handler_allocate; - auto& e = *new(asio_handler_allocate( - sizeof(element) + n, ctx_)) element{n, used}; - list_.push_back(e); - high_ = (std::max)(high_, used); - return e.data(); -} - -template -void -session_alloc_base:: -pool_t:: -dealloc(void* pv, std::size_t n) -{ - auto& e = *(reinterpret_cast(pv) - 1); - BOOST_ASSERT(e.size() == n); - if( (e.end() > buf_ + size_) || - reinterpret_cast(&e) < buf_) - { - list_.erase(list_.iterator_to(e)); - e.~element(); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - &e, sizeof(e) + n, ctx_); - return; - } - list_.erase(list_.iterator_to(e)); - e.~element(); -} +}; +} // asio +} // boost #endif diff --git a/example/common/ssl_stream.hpp b/example/common/ssl_stream.hpp index b4dabd2b..90245c43 100644 --- a/example/common/ssl_stream.hpp +++ b/example/common/ssl_stream.hpp @@ -52,9 +52,6 @@ public: /// Structure for use with deprecated impl_type. using impl_struct = typename stream_type::impl_struct; - /// (Deprecated: Use native_handle_type.) The underlying implementation type. - using impl_type = typename stream_type::impl_type; - /// The type of the next layer. using next_layer_type = typename stream_type::next_layer_type; @@ -64,14 +61,16 @@ public: ssl_stream( boost::asio::ip::tcp::socket socket, boost::asio::ssl::context& ctx) - : p_(new stream_type{socket.get_io_service(), ctx}) + : p_(new stream_type{ + socket.get_executor().context(), ctx}) , ctx_(&ctx) { p_->next_layer() = std::move(socket); } ssl_stream(ssl_stream&& other) - : p_(new stream_type(other.get_io_service(), *other.ctx_)) + : p_(new stream_type( + other.get_executor().context(), *other.ctx_)) , ctx_(other.ctx_) { using std::swap; @@ -80,8 +79,8 @@ public: ssl_stream& operator=(ssl_stream&& other) { - std::unique_ptr p( - new stream_type{other.get_io_service(), other.ctx_}); + std::unique_ptr p(new stream_type{ + other.get_executor().context(), other.ctx_}); using std::swap; swap(p_, p); swap(p_, other.p_); @@ -89,10 +88,10 @@ public: return *this; } - boost::asio::io_service& - get_io_service() + decltype(p_->get_executor()) + get_executor() noexcept { - return p_->get_io_service(); + return p_->get_executor(); } native_handle_type @@ -101,12 +100,6 @@ public: return p_->native_handle(); } - impl_type - impl() - { - return p_->impl(); - } - next_layer_type const& next_layer() const { diff --git a/example/common/write_msg.hpp b/example/common/write_msg.hpp deleted file mode 100644 index fad3dd16..00000000 --- a/example/common/write_msg.hpp +++ /dev/null @@ -1,230 +0,0 @@ -// -// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail 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) -// -// Official repository: https://github.com/boostorg/beast -// - -#ifndef BOOST_BEAST_EXAMPLE_COMMON_WRITE_MSG_HPP -#define BOOST_BEAST_EXAMPLE_COMMON_WRITE_MSG_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace detail { - -/** Composed operation to send an HTTP message - - This implements the composed operation needed for the - @ref async_write_msg function. -*/ -template< - class AsyncWriteStream, - class Handler, - bool isRequest, class Body, class Fields> -class write_msg_op -{ - // This composed operation has a state which is not trivial - // to copy (msg) so we need to store the state in an allocated - // object. - // - struct data - { - // The stream we are writing to - AsyncWriteStream& stream; - - // The message we are sending. Note that this composed - // operation takes ownership of the message and destroys - // it when it is done. - // - boost::beast::http::message msg; - - // Serializer for the message - boost::beast::http::serializer sr; - - data( - Handler& handler, - AsyncWriteStream& stream_, - boost::beast::http::message&& msg_) - : stream(stream_) - , msg(std::move(msg_)) - , sr(msg) - { - boost::ignore_unused(handler); - } - }; - - // `handler_ptr` is a utility which helps to manage a composed - // operation's state. It is similar to a shared pointer, but - // it uses handler allocation hooks to allocate and free memory, - // and it also helps to meet Asio's deallocate-before-invocation - // guarantee. - // - boost::beast::handler_ptr d_; - -public: - // Asio can move and copy the handler, we support both - write_msg_op(write_msg_op&&) = default; - write_msg_op(write_msg_op const&) = default; - - // Constructor - // - // We take the handler as a template type to - // support both const and rvalue references. - // - template< - class DeducedHandler, - class... Args> - write_msg_op( - DeducedHandler&& h, - AsyncWriteStream& s, - Args&&... args) - : d_(std::forward(h), - s, std::forward(args)...) - { - } - - // Entry point - // - // The initiation function calls this to start the operation - // - void - operator()() - { - auto& d = *d_; - boost::beast::http::async_write( - d.stream, d.sr, std::move(*this)); - } - - // Completion handler - // - // This gets called when boost::beast::http::async_write completes - // - void - operator()(boost::beast::error_code ec) - { - d_.invoke(ec); - } - - // - // These hooks are necessary for Asio - // - // The meaning is explained in the Beast documentation - // - - friend - void* asio_handler_allocate( - std::size_t size, write_msg_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_msg_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(write_msg_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation(std::addressof(op->d_.handler())); - } - - template - friend - void asio_handler_invoke(Function&& f, write_msg_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -} // detail - -/** Write an HTTP message to a stream asynchronously - - This function is used to write a complete message to a stream asynchronously - using HTTP/1. The function call always returns immediately. The asynchronous - operation will continue until one of the following conditions is true: - - @li The entire message is written. - - @li An error occurs. - - This operation is implemented in terms of zero or more calls to the stream's - `async_write_some` function, and is known as a composed operation. - The program must ensure that the stream performs no other write operations - until this operation completes. The algorithm will use a temporary - @ref serializer to produce buffers. If the semantics of the message - indicate that the connection should be closed after the message is sent, - the error delivered by this function - will be @ref error::end_of_stream - - @param stream The stream to which the data is to be written. - The type must support the @b AsyncWriteStream concept. - - @param msg The message to write. The function will take ownership - of the object as if by move constrction. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. -*/ -template< - class AsyncWriteStream, - bool isRequest, class Body, class Fields, - class WriteHandler> -boost::beast::async_return_type -async_write_msg( - AsyncWriteStream& stream, - boost::beast::http::message&& msg, - WriteHandler&& handler) -{ - static_assert( - boost::beast::is_async_write_stream::value, - "AsyncWriteStream requirements not met"); - - static_assert(boost::beast::http::is_body::value, - "Body requirements not met"); - - static_assert(boost::beast::http::is_body_reader::value, - "BodyReader requirements not met"); - - boost::beast::async_completion init{handler}; - - ::detail::write_msg_op< - AsyncWriteStream, - boost::beast::handler_type, - isRequest, Body, Fields>{ - init.completion_handler, - stream, - std::move(msg)}(); - - return init.result.get(); -} - -#endif diff --git a/example/doc/http_examples.hpp b/example/doc/http_examples.hpp index e1437830..7e10e26f 100644 --- a/example/doc/http_examples.hpp +++ b/example/doc/http_examples.hpp @@ -62,7 +62,8 @@ send_expect_100_continue( static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); // Insert or replace the Expect field @@ -123,7 +124,8 @@ receive_expect_100_continue( static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); // Declare a parser for a request with a string body @@ -194,9 +196,6 @@ send_cgi_response( static_assert(is_sync_write_stream::value, "SyncWriteStream requirements not met"); - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - // Set up the response. We use the buffer_body type, // allowing serialization to use manually provided buffers. response res; @@ -293,7 +292,8 @@ void do_server_head( { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirments not met"); // We deliver this payload for all GET requests @@ -386,7 +386,8 @@ do_head_request( // Do some type checking to be a good citizen static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirments not met"); // The interfaces we are using are low level and do not @@ -589,10 +590,6 @@ public: void operator()(error_code& ec, ConstBufferSequence const& buffers) const { - // These asio functions are needed to access a buffer's contents - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - // Error codes must be cleared on success ec = {}; @@ -600,15 +597,16 @@ public: std::size_t bytes_transferred = 0; // Loop over the buffer sequence - for(auto it = buffers.begin(); it != buffers.end(); ++ it) + for(auto it = boost::asio::buffer_sequence_begin(buffers); + it != boost::asio::buffer_sequence_end(buffers); ++it) { // This is the next buffer in the sequence boost::asio::const_buffer const buffer = *it; // Write it to the std::ostream os_.write( - buffer_cast(buffer), - buffer_size(buffer)); + reinterpret_cast(buffer.data()), + buffer.size()); // If the std::ostream fails, convert it to an error code if(os_.fail()) @@ -714,13 +712,12 @@ read_istream( if(is.rdbuf()->in_avail() > 0) { // Get a mutable buffer sequence for writing - auto const mb = buffer.prepare( + auto const b = buffer.prepare( static_cast(is.rdbuf()->in_avail())); // Now get everything we can from the istream buffer.commit(static_cast(is.readsome( - boost::asio::buffer_cast(mb), - boost::asio::buffer_size(mb)))); + reinterpret_cast(b.data()), b.size()))); } else if(buffer.size() == 0) { @@ -729,12 +726,10 @@ read_istream( if(! is.eof()) { // Get a mutable buffer sequence for writing - auto const mb = buffer.prepare(1024); + auto const b = buffer.prepare(1024); // Try to get more from the istream. This might block. - is.read( - boost::asio::buffer_cast(mb), - boost::asio::buffer_size(mb)); + is.read(reinterpret_cast(b.data()), b.size()); // If an error occurs on the istream then return it to the caller. if(is.fail() && ! is.eof()) diff --git a/example/echo-op/echo_op.cpp b/example/echo-op/echo_op.cpp index 6a9a329a..45024f3a 100644 --- a/example/echo-op/echo_op.cpp +++ b/example/echo-op/echo_op.cpp @@ -23,7 +23,7 @@ auto async_echo(AsyncStream& stream, CompletionToken&& token) //] - -> boost::beast::async_return_type; + -> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(boost::beast::error_code)); //[example_core_echo_op_2 @@ -61,14 +61,14 @@ async_echo(AsyncStream& stream, CompletionToken&& token) Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class AsyncStream, class CompletionToken> -boost::beast::async_return_type< /*< The [link beast.ref.boost__beast__async_return_type `async_return_type`] customizes the return value based on the completion token >*/ +BOOST_ASIO_INITFN_RESULT_TYPE( /*< `BOOST_ASIO_INITFN_RESULT_TYPE` customizes the return value based on the completion token >*/ CompletionToken, - void(boost::beast::error_code)> /*< This is the signature for the completion handler >*/ + void(boost::beast::error_code)) /*< This is the signature for the completion handler >*/ async_echo( AsyncStream& stream, CompletionToken&& token); @@ -95,11 +95,13 @@ class echo_op // The buffer used to hold the input and output data. // // We use a custom allocator for performance, this allows - // the implementation of the io_service to make efficient + // the implementation of the io_context to make efficient // re-use of memory allocated by composed operations during // a continuation. // - boost::asio::basic_streambuf> buffer; + boost::asio::basic_streambuf >:: + template rebind_alloc > buffer; // handler_ptr requires that the first parameter to the // contained object constructor is a reference to the @@ -108,7 +110,7 @@ class echo_op explicit state(Handler& handler, AsyncStream& stream_) : stream(stream_) , buffer((std::numeric_limits::max)(), - boost::beast::handler_alloc{handler}) + boost::asio::get_associated_allocator(handler)) { } }; @@ -116,14 +118,10 @@ class echo_op // The operation's data is kept in a cheap-to-copy smart // pointer container called `handler_ptr`. This efficiently // satisfies the CopyConstructible requirements of completion - // handlers. + // handlers with expensive-to-copy state. // - // `handler_ptr` uses these memory allocation hooks associated - // with the final completion handler, in order to allocate the - // storage for `state`: - // - // asio_handler_allocate - // asio_handler_deallocate + // `handler_ptr` uses the allocator associated with the final + // completion handler, in order to allocate the storage for `state`. // boost::beast::handler_ptr p_; @@ -144,30 +142,45 @@ public: { } + // Associated allocator support. This is Asio's system for + // allowing the final completion handler to customize the + // memory allocation strategy used for composed operation + // states. A composed operation needs to use the same allocator + // as the final handler. These declarations achieve that. + + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(p_.handler()); + } + + // Executor hook. This is Asio's system for customizing the + // manner in which asynchronous completion handlers are invoked. + // A composed operation needs to use the same executor to invoke + // intermediate completion handlers as that used to invoke the + // final handler. + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(p_->stream.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + p_.handler(), p_->stream.get_executor()); + } + + // (DEPRECATED) + template + friend bool asio_handler_is_continuation( + echo_op* op); + // The entry point for this handler. This will get called // as our intermediate operations complete. Definition below. // void operator()(boost::beast::error_code ec, std::size_t bytes_transferred); - - // The next four functions are required for our class - // to meet the requirements for composed operations. - // Definitions and exposition will follow. - - template - friend void asio_handler_invoke( - Function&& f, echo_op* op); - - template - friend void* asio_handler_allocate( - std::size_t size, echo_op* op); - - template - friend void asio_handler_deallocate( - void* p, std::size_t size, echo_op* op); - - template - friend bool asio_handler_is_continuation( - echo_op* op); }; //] @@ -226,44 +239,6 @@ operator()(boost::beast::error_code ec, std::size_t bytes_transferred) //[example_core_echo_op_6 -// Handler hook forwarding. These free functions invoke the hooks -// associated with the final completion handler. In effect, they -// make the Asio implementation treat our composed operation the -// same way it would treat the final completion handler for the -// purpose of memory allocation and invocation. -// -// Our implementation just passes the call through to the hook -// associated with the final handler. The "using" statements are -// structured to permit argument dependent lookup. Always use -// `std::addressof` or its equivalent to pass the pointer to the -// handler, otherwise an unwanted overload of `operator&` may be -// called instead. - -template -void asio_handler_invoke( - Function&& f, echo_op* op) -{ - using boost::asio::asio_handler_invoke; - return asio_handler_invoke(f, std::addressof(op->p_.handler())); -} - -template -void* asio_handler_allocate( - std::size_t size, echo_op* op) -{ - using boost::asio::asio_handler_allocate; - return asio_handler_allocate(size, std::addressof(op->p_.handler())); -} - -template -void asio_handler_deallocate( - void* p, std::size_t size, echo_op* op) -{ - using boost::asio::asio_handler_deallocate; - return asio_handler_deallocate(p, size, - std::addressof(op->p_.handler())); -} - // Determines if the next asynchronous operation represents a // continuation of the asynchronous flow of control associated // with the final handler. If we are past step one, it means @@ -297,7 +272,7 @@ class echo_op; // Read a line and echo it back // template -boost::beast::async_return_type +BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(boost::beast::error_code)) async_echo(AsyncStream& stream, CompletionToken&& token) { // Make sure stream meets the requirements. We use static_assert @@ -310,16 +285,20 @@ async_echo(AsyncStream& stream, CompletionToken&& token) // uses the result and handler specializations associated with // the completion token to help customize the return value. // - boost::beast::async_completion init{token}; + boost::asio::async_completion init{token}; // Create the composed operation and launch it. This is a constructor - // call followed by invocation of operator(). We use handler_type + // call followed by invocation of operator(). We use BOOST_ASIO_HANDLER_TYPE // to convert the completion token into the correct handler type, // allowing user-defined specializations of the async_result template // to be used. // - echo_op>{ - stream, init.completion_handler}(boost::beast::error_code{}, 0); + echo_op< + AsyncStream, + BOOST_ASIO_HANDLER_TYPE( + CompletionToken, void(boost::beast::error_code))>{ + stream, + init.completion_handler}(boost::beast::error_code{}, 0); // This hook lets the caller see a return value when appropriate. // For example this might return std::future if @@ -333,16 +312,15 @@ async_echo(AsyncStream& stream, CompletionToken&& token) int main(int, char** argv) { - using address_type = boost::asio::ip::address; using socket_type = boost::asio::ip::tcp::socket; using endpoint_type = boost::asio::ip::tcp::endpoint; // Create a listening socket, accept a connection, perform // the echo, and then shut everything down and exit. - boost::asio::io_service ios; - socket_type sock{ios}; - boost::asio::ip::tcp::acceptor acceptor{ios}; - endpoint_type ep{address_type::from_string("0.0.0.0"), 0}; + boost::asio::io_context ioc; + socket_type sock{ioc}; + boost::asio::ip::tcp::acceptor acceptor{ioc}; + endpoint_type ep{boost::asio::ip::make_address("0.0.0.0"), 0}; acceptor.open(ep.protocol()); acceptor.bind(ep); acceptor.listen(); @@ -353,6 +331,6 @@ int main(int, char** argv) if(ec) std::cerr << argv[0] << ": " << ec.message() << std::endl; }); - ios.run(); + ioc.run(); return 0; } diff --git a/example/http/client/async-ssl/http_client_async_ssl.cpp b/example/http/client/async-ssl/http_client_async_ssl.cpp index 9b0cad1d..71a55cda 100644 --- a/example/http/client/async-ssl/http_client_async_ssl.cpp +++ b/example/http/client/async-ssl/http_client_async_ssl.cpp @@ -50,11 +50,11 @@ class session : public std::enable_shared_from_this http::response res_; public: - // Resolver and stream require an io_service + // Resolver and stream require an io_context explicit - session(boost::asio::io_service& ios, ssl::context& ctx) - : resolver_(ios) - , stream_(ios, ctx) + session(boost::asio::io_context& ioc, ssl::context& ctx) + : resolver_(ioc) + , stream_(ioc, ctx) { } @@ -73,7 +73,9 @@ public: req_.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); // Look up the domain name - resolver_.async_resolve({host, port}, + resolver_.async_resolve( + host, + port, std::bind( &session::on_resolve, shared_from_this(), @@ -84,7 +86,7 @@ public: void on_resolve( boost::system::error_code ec, - tcp::resolver::iterator result) + tcp::resolver::results_type results) { if(ec) return fail(ec, "resolve"); @@ -92,7 +94,8 @@ public: // Make the connection on the IP address we get from a lookup boost::asio::async_connect( stream_.next_layer(), - result, + results.begin(), + results.end(), std::bind( &session::on_connect, shared_from_this(), @@ -202,8 +205,8 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const target = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23_client}; @@ -212,11 +215,11 @@ int main(int argc, char** argv) load_root_certificates(ctx); // Launch the asynchronous operation - std::make_shared(ios, ctx)->run(host, port, target); + std::make_shared(ioc, ctx)->run(host, port, target); // Run the I/O service. The call will return when // the get operation is complete. - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/client/async/http_client_async.cpp b/example/http/client/async/http_client_async.cpp index 6c3f9af5..c7d46468 100644 --- a/example/http/client/async/http_client_async.cpp +++ b/example/http/client/async/http_client_async.cpp @@ -46,11 +46,11 @@ class session : public std::enable_shared_from_this http::response res_; public: - // Resolver and socket require an io_service + // Resolver and socket require an io_context explicit - session(boost::asio::io_service& ios) - : resolver_(ios) - , socket_(ios) + session(boost::asio::io_context& ioc) + : resolver_(ioc) + , socket_(ioc) { } @@ -69,7 +69,9 @@ public: req_.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); // Look up the domain name - resolver_.async_resolve({host, port}, + resolver_.async_resolve( + host, + port, std::bind( &session::on_resolve, shared_from_this(), @@ -80,13 +82,16 @@ public: void on_resolve( boost::system::error_code ec, - tcp::resolver::iterator result) + tcp::resolver::results_type results) { if(ec) return fail(ec, "resolve"); // Make the connection on the IP address we get from a lookup - boost::asio::async_connect(socket_, result, + boost::asio::async_connect( + socket_, + results.begin(), + results.end(), std::bind( &session::on_connect, shared_from_this(), @@ -168,15 +173,15 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const target = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // Launch the asynchronous operation - std::make_shared(ios)->run(host, port, target); + std::make_shared(ioc)->run(host, port, target); // Run the I/O service. The call will return when // the get operation is complete. - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/client/coro-ssl/http_client_coro_ssl.cpp b/example/http/client/coro-ssl/http_client_coro_ssl.cpp index 91526163..98b5fbdd 100644 --- a/example/http/client/coro-ssl/http_client_coro_ssl.cpp +++ b/example/http/client/coro-ssl/http_client_coro_ssl.cpp @@ -46,23 +46,23 @@ do_session( std::string const& host, std::string const& port, std::string const& target, - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, boost::asio::yield_context yield) { boost::system::error_code ec; // These objects perform our I/O - tcp::resolver resolver{ios}; - ssl::stream stream{ios, ctx}; + tcp::resolver resolver{ioc}; + ssl::stream stream{ioc, ctx}; // Look up the domain name - auto const lookup = resolver.async_resolve({host, port}, yield[ec]); + auto const results = resolver.async_resolve(host, port, yield[ec]); if(ec) return fail(ec, "resolve"); // Make the connection on the IP address we get from a lookup - boost::asio::async_connect(stream.next_layer(), lookup, yield[ec]); + boost::asio::async_connect(stream.next_layer(), results.begin(), results.end(), yield[ec]); if(ec) return fail(ec, "connect"); @@ -126,8 +126,8 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const target = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23_client}; @@ -136,18 +136,18 @@ int main(int argc, char** argv) load_root_certificates(ctx); // Launch the asynchronous operation - boost::asio::spawn(ios, std::bind( + boost::asio::spawn(ioc, std::bind( &do_session, std::string(host), std::string(port), std::string(target), - std::ref(ios), + std::ref(ioc), std::ref(ctx), std::placeholders::_1)); // Run the I/O service. The call will return when // the get operation is complete. - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/client/coro/http_client_coro.cpp b/example/http/client/coro/http_client_coro.cpp index 8f5665a5..b076b2f7 100644 --- a/example/http/client/coro/http_client_coro.cpp +++ b/example/http/client/coro/http_client_coro.cpp @@ -42,22 +42,22 @@ do_session( std::string const& host, std::string const& port, std::string const& target, - boost::asio::io_service& ios, + boost::asio::io_context& ioc, boost::asio::yield_context yield) { boost::system::error_code ec; // These objects perform our I/O - tcp::resolver resolver{ios}; - tcp::socket socket{ios}; + tcp::resolver resolver{ioc}; + tcp::socket socket{ioc}; // Look up the domain name - auto const lookup = resolver.async_resolve({host, port}, yield[ec]); + auto const results = resolver.async_resolve(host, port, yield[ec]); if(ec) return fail(ec, "resolve"); // Make the connection on the IP address we get from a lookup - boost::asio::async_connect(socket, lookup, yield[ec]); + boost::asio::async_connect(socket, results.begin(), results.end(), yield[ec]); if(ec) return fail(ec, "connect"); @@ -114,21 +114,21 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const target = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // Launch the asynchronous operation - boost::asio::spawn(ios, std::bind( + boost::asio::spawn(ioc, std::bind( &do_session, std::string(host), std::string(port), std::string(target), - std::ref(ios), + std::ref(ioc), std::placeholders::_1)); // Run the I/O service. The call will return when // the get operation is complete. - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/client/crawl/http_crawl.cpp b/example/http/client/crawl/http_crawl.cpp index ed6708ce..bb620f1d 100644 --- a/example/http/client/crawl/http_crawl.cpp +++ b/example/http/client/crawl/http_crawl.cpp @@ -18,10 +18,11 @@ #include #include #include +#include #include #include +#include #include -#include #include #include #include @@ -43,16 +44,17 @@ namespace chrono = std::chrono; // from // This structure aggregates statistics on all the sites class crawl_report { - boost::asio::io_service& ios_; - boost::asio::io_service::strand strand_; + boost::asio::io_context& ioc_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; std::atomic index_; std::vector const& hosts_; std::size_t count_ = 0; public: - crawl_report(boost::asio::io_service& ios) - : ios_(ios) - , strand_(ios_) + crawl_report(boost::asio::io_context& ioc) + : ioc_(ioc) + , strand_(ioc_.get_executor()) , index_(0) , hosts_(urls_large_data()) { @@ -64,18 +66,19 @@ public: void aggregate(F const& f) { - ios_.post(strand_.wrap( - [&, f] - { - f(*this); - if(count_ % 100 == 0) + boost::asio::post( + strand_, + [&, f] { - std::cerr << - "Progress: " << count_ << " of " << hosts_.size() << "\n"; - //std::cerr << *this; - } - ++count_; - })); + f(*this); + if(count_ % 100 == 0) + { + std::cerr << + "Progress: " << count_ << " of " << hosts_.size() << "\n"; + //std::cerr << *this; + } + ++count_; + }); } // Returns the next host to check @@ -148,7 +151,8 @@ class worker : public std::enable_shared_from_this tcp::resolver resolver_; tcp::socket socket_; boost::asio::steady_timer timer_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::flat_buffer buffer_; // (Must persist between reads) http::request req_; http::response res_; @@ -156,16 +160,16 @@ class worker : public std::enable_shared_from_this public: worker(worker&&) = default; - // Resolver and socket require an io_service + // Resolver and socket require an io_context worker( crawl_report& report, - boost::asio::io_service& ios) + boost::asio::io_context& ioc) : report_(report) - , resolver_(ios) - , socket_(ios) - , timer_(ios, + , resolver_(ioc) + , socket_(ioc) + , timer_(ioc, (chrono::steady_clock::time_point::max)()) - , strand_(ios) + , strand_(ioc.get_executor()) { // Set up the common fields of the request req_.version(11); @@ -200,7 +204,7 @@ public: } // Verify that the timer really expired since the deadline may have moved. - if(timer_.expires_at() <= chrono::steady_clock::now()) + if(timer_.expiry() <= chrono::steady_clock::now()) { socket_.shutdown(tcp::socket::shutdown_both, ec); socket_.close(ec); @@ -209,10 +213,12 @@ public: // Wait on the timer timer_.async_wait( - strand_.wrap(std::bind( - &worker::on_timer, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &worker::on_timer, + shared_from_this(), + std::placeholders::_1))); } void @@ -224,8 +230,7 @@ public: // nullptr means no more work if(! host) { - boost::system::error_code ec; - timer_.cancel(ec); + timer_.cancel_one(); return; } @@ -233,23 +238,26 @@ public: req_.set(http::field::host, host); // Set the timer - timer_.expires_from_now(chrono::seconds(timeout)); + timer_.expires_after(chrono::seconds(timeout)); // Set up an HTTP GET request message // Look up the domain name resolver_.async_resolve( - tcp::resolver::query{host, "http"}, - strand_.wrap(std::bind( - &worker::on_resolve, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + host, + "http", + boost::asio::bind_executor( + strand_, + std::bind( + &worker::on_resolve, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void on_resolve( boost::system::error_code ec, - tcp::resolver::iterator result) + tcp::resolver::results_type results) { if(ec) { @@ -262,16 +270,19 @@ public: } // Set the timer - timer_.expires_from_now(chrono::seconds(timeout)); + timer_.expires_after(chrono::seconds(timeout)); // Make the connection on the IP address we get from a lookup boost::asio::async_connect( socket_, - result, - strand_.wrap(std::bind( - &worker::on_connect, - shared_from_this(), - std::placeholders::_1))); + results.begin(), + results.end(), + boost::asio::bind_executor( + strand_, + std::bind( + &worker::on_connect, + shared_from_this(), + std::placeholders::_1))); } void @@ -288,17 +299,19 @@ public: } // Set the timer - timer_.expires_from_now(chrono::seconds(timeout)); + timer_.expires_after(chrono::seconds(timeout)); // Send the HTTP request to the remote host http::async_write( socket_, req_, - strand_.wrap(std::bind( - &worker::on_write, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &worker::on_write, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -319,18 +332,20 @@ public: } // Set the timer - timer_.expires_from_now(chrono::seconds(timeout)); + timer_.expires_after(chrono::seconds(timeout)); // Receive the HTTP response http::async_read( socket_, buffer_, res_, - strand_.wrap(std::bind( - &worker::on_read, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &worker::on_read, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -400,41 +415,41 @@ int main(int argc, char* argv[]) " http-crawl 100 1\n"; return EXIT_FAILURE; } - auto const threads = std::max(1, std::atoi(argv[1])); + auto const threads = std::max(1, std::atoi(argv[1])); - // The io_service is required for all I/O - boost::asio::io_service ios{1}; + // The io_context is required for all I/O + boost::asio::io_context ioc{1}; - // The work keeps io_service::run from returning - boost::optional work{ios}; + // The work keeps io_context::run from returning + auto work = boost::asio::make_work_guard(ioc); // The report holds the aggregated statistics - crawl_report report{ios}; + crawl_report report{ioc}; timer t; // Create and launch the worker threads. std::vector workers; workers.reserve(threads + 1); - for(std::size_t i = 0; i < threads; ++i) + for(int i = 0; i < threads; ++i) workers.emplace_back( [&report] { - // We use a separate io_service for each worker because + // We use a separate io_context for each worker because // the asio resolver simulates asynchronous operation using - // a dedicated worker thread per io_service, and we want to + // a dedicated worker thread per io_context, and we want to // do a lot of name resolutions in parallel. - boost::asio::io_service ios{1}; - std::make_shared(report, ios)->run(); - ios.run(); + boost::asio::io_context ioc{1}; + std::make_shared(report, ioc)->run(); + ioc.run(); }); - // Add another thread to run the main io_service which + // Add another thread to run the main io_context which // is used to aggregate the statistics workers.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); // Now block until all threads exit @@ -442,11 +457,10 @@ int main(int argc, char* argv[]) { auto& thread = workers[i]; - // If this is the last thread, destroy the + // If this is the last thread, reset the // work object so that it can return from run. - //if(&thread == &workers.back()) if(i == workers.size() - 1) - work = boost::none; + work.reset(); // Wait for the thread to exit thread.join(); diff --git a/example/http/client/sync-ssl/http_client_sync_ssl.cpp b/example/http/client/sync-ssl/http_client_sync_ssl.cpp index 9ed63742..54bb6d67 100644 --- a/example/http/client/sync-ssl/http_client_sync_ssl.cpp +++ b/example/http/client/sync-ssl/http_client_sync_ssl.cpp @@ -47,8 +47,8 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const target = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23_client}; @@ -57,14 +57,14 @@ int main(int argc, char** argv) load_root_certificates(ctx); // These objects perform our I/O - tcp::resolver resolver{ios}; - ssl::stream stream{ios, ctx}; + tcp::resolver resolver{ioc}; + ssl::stream stream{ioc, ctx}; // Look up the domain name - auto const lookup = resolver.resolve({host, port}); + auto const results = resolver.resolve(host, port); // Make the connection on the IP address we get from a lookup - boost::asio::connect(stream.next_layer(), lookup); + boost::asio::connect(stream.next_layer(), results.begin(), results.end()); // Perform the SSL handshake stream.handshake(ssl::stream_base::client); diff --git a/example/http/client/sync/http_client_sync.cpp b/example/http/client/sync/http_client_sync.cpp index e56fdc62..09a3e04f 100644 --- a/example/http/client/sync/http_client_sync.cpp +++ b/example/http/client/sync/http_client_sync.cpp @@ -45,18 +45,18 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const target = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // These objects perform our I/O - tcp::resolver resolver{ios}; - tcp::socket socket{ios}; + tcp::resolver resolver{ioc}; + tcp::socket socket{ioc}; // Look up the domain name - auto const lookup = resolver.resolve({host, port}); + auto const results = resolver.resolve(host, port); // Make the connection on the IP address we get from a lookup - boost::asio::connect(socket, lookup); + boost::asio::connect(socket, results.begin(), results.end()); // Set up an HTTP GET request message http::request req{http::verb::get, target, 11}; diff --git a/example/http/server/async-ssl/http_server_async_ssl.cpp b/example/http/server/async-ssl/http_server_async_ssl.cpp index 57e95d99..052f2e58 100644 --- a/example/http/server/async-ssl/http_server_async_ssl.cpp +++ b/example/http/server/async-ssl/http_server_async_ssl.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -244,18 +245,21 @@ class session : public std::enable_shared_from_this http::async_write( self_.stream_, *sp, - self_.strand_.wrap(std::bind( - &session::on_write, - self_.shared_from_this(), - std::placeholders::_1, - std::placeholders::_2, - ! sp->keep_alive()))); + boost::asio::bind_executor( + self_.strand_, + std::bind( + &session::on_write, + self_.shared_from_this(), + std::placeholders::_1, + std::placeholders::_2, + ! sp->keep_alive()))); } }; tcp::socket socket_; ssl::stream stream_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::flat_buffer buffer_; std::string const& doc_root_; http::request req_; @@ -271,7 +275,7 @@ public: std::string const& doc_root) : socket_(std::move(socket)) , stream_(socket_, ctx) - , strand_(socket_.get_io_service()) + , strand_(socket_.get_executor()) , doc_root_(doc_root) , lambda_(*this) { @@ -284,10 +288,12 @@ public: // Perform the SSL handshake stream_.async_handshake( ssl::stream_base::server, - strand_.wrap(std::bind( - &session::on_handshake, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_handshake, + shared_from_this(), + std::placeholders::_1))); } void @@ -304,11 +310,13 @@ public: { // Read a request http::async_read(stream_, buffer_, req_, - strand_.wrap(std::bind( - &session::on_read, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_read, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -359,10 +367,12 @@ public: { // Perform the SSL shutdown stream_.async_shutdown( - strand_.wrap(std::bind( - &session::on_shutdown, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_shutdown, + shared_from_this(), + std::placeholders::_1))); } void @@ -387,13 +397,13 @@ class listener : public std::enable_shared_from_this public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, tcp::endpoint endpoint, std::string const& doc_root) : ctx_(ctx) - , acceptor_(ios) - , socket_(ios) + , acceptor_(ioc) + , socket_(ioc) , doc_root_(doc_root) { boost::system::error_code ec; @@ -416,7 +426,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -478,13 +488,13 @@ int main(int argc, char* argv[]) " http-server-async-ssl 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -494,7 +504,7 @@ int main(int argc, char* argv[]) // Create and launch a listening port std::make_shared( - ios, + ioc, ctx, tcp::endpoint{address, port}, doc_root)->run(); @@ -504,11 +514,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/server/async/http_server_async.cpp b/example/http/server/async/http_server_async.cpp index a388e9ca..985618b1 100644 --- a/example/http/server/async/http_server_async.cpp +++ b/example/http/server/async/http_server_async.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -240,17 +241,20 @@ class session : public std::enable_shared_from_this http::async_write( self_.socket_, *sp, - self_.strand_.wrap(std::bind( - &session::on_write, - self_.shared_from_this(), - std::placeholders::_1, - std::placeholders::_2, - ! sp->keep_alive()))); + boost::asio::bind_executor( + self_.strand_, + std::bind( + &session::on_write, + self_.shared_from_this(), + std::placeholders::_1, + std::placeholders::_2, + ! sp->keep_alive()))); } }; tcp::socket socket_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::flat_buffer buffer_; std::string const& doc_root_; http::request req_; @@ -264,7 +268,7 @@ public: tcp::socket socket, std::string const& doc_root) : socket_(std::move(socket)) - , strand_(socket_.get_io_service()) + , strand_(socket_.get_executor()) , doc_root_(doc_root) , lambda_(*this) { @@ -282,11 +286,13 @@ public: { // Read a request http::async_read(socket_, buffer_, req_, - strand_.wrap(std::bind( - &session::on_read, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_read, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -354,11 +360,11 @@ class listener : public std::enable_shared_from_this public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint, std::string const& doc_root) - : acceptor_(ios) - , socket_(ios) + : acceptor_(ioc) + , socket_(ioc) , doc_root_(doc_root) { boost::system::error_code ec; @@ -381,7 +387,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -442,17 +448,17 @@ int main(int argc, char* argv[]) " http-server-async 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // Create and launch a listening port std::make_shared( - ios, + ioc, tcp::endpoint{address, port}, doc_root)->run(); @@ -461,11 +467,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/server/coro-ssl/http_server_coro_ssl.cpp b/example/http/server/coro-ssl/http_server_coro_ssl.cpp index 5b16661e..3cc7ffb6 100644 --- a/example/http/server/coro-ssl/http_server_coro_ssl.cpp +++ b/example/http/server/coro-ssl/http_server_coro_ssl.cpp @@ -308,7 +308,7 @@ do_session( // Accepts incoming connections and launches the sessions void do_listen( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, tcp::endpoint endpoint, std::string const& doc_root, @@ -317,7 +317,7 @@ do_listen( boost::system::error_code ec; // Open the acceptor - tcp::acceptor acceptor(ios); + tcp::acceptor acceptor(ioc); acceptor.open(endpoint.protocol(), ec); if(ec) return fail(ec, "open"); @@ -328,19 +328,19 @@ do_listen( return fail(ec, "bind"); // Start listening for connections - acceptor.listen(boost::asio::socket_base::max_connections, ec); + acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); if(ec) return fail(ec, "listen"); for(;;) { - tcp::socket socket(ios); + tcp::socket socket(ioc); acceptor.async_accept(socket, yield[ec]); if(ec) fail(ec, "accept"); else boost::asio::spawn( - acceptor.get_io_service(), + acceptor.get_executor().context(), std::bind( &do_session, std::move(socket), @@ -361,13 +361,13 @@ int main(int argc, char* argv[]) " http-server-coro-ssl 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -376,10 +376,10 @@ int main(int argc, char* argv[]) load_server_certificate(ctx); // Spawn a listening port - boost::asio::spawn(ios, + boost::asio::spawn(ioc, std::bind( &do_listen, - std::ref(ios), + std::ref(ioc), std::ref(ctx), tcp::endpoint{address, port}, doc_root, @@ -390,11 +390,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/server/coro/http_server_coro.cpp b/example/http/server/coro/http_server_coro.cpp index 81a8b1af..f2aa9148 100644 --- a/example/http/server/coro/http_server_coro.cpp +++ b/example/http/server/coro/http_server_coro.cpp @@ -293,7 +293,7 @@ do_session( // Accepts incoming connections and launches the sessions void do_listen( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint, std::string const& doc_root, boost::asio::yield_context yield) @@ -301,7 +301,7 @@ do_listen( boost::system::error_code ec; // Open the acceptor - tcp::acceptor acceptor(ios); + tcp::acceptor acceptor(ioc); acceptor.open(endpoint.protocol(), ec); if(ec) return fail(ec, "open"); @@ -312,19 +312,19 @@ do_listen( return fail(ec, "bind"); // Start listening for connections - acceptor.listen(boost::asio::socket_base::max_connections, ec); + acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); if(ec) return fail(ec, "listen"); for(;;) { - tcp::socket socket(ios); + tcp::socket socket(ioc); acceptor.async_accept(socket, yield[ec]); if(ec) fail(ec, "accept"); else boost::asio::spawn( - acceptor.get_io_service(), + acceptor.get_executor().context(), std::bind( &do_session, std::move(socket), @@ -344,19 +344,19 @@ int main(int argc, char* argv[]) " http-server-coro 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // Spawn a listening port - boost::asio::spawn(ios, + boost::asio::spawn(ioc, std::bind( &do_listen, - std::ref(ios), + std::ref(ioc), tcp::endpoint{address, port}, doc_root, std::placeholders::_1)); @@ -366,11 +366,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/server/fast/http_server_fast.cpp b/example/http/server/fast/http_server_fast.cpp index 9f857c1e..b667bec8 100644 --- a/example/http/server/fast/http_server_fast.cpp +++ b/example/http/server/fast/http_server_fast.cpp @@ -97,7 +97,7 @@ private: std::string doc_root_; // The socket for the currently connected client. - tcp::socket socket_{acceptor_.get_io_service()}; + tcp::socket socket_{acceptor_.get_executor().context()}; // The buffer for performing reads boost::beast::flat_static_buffer<8192> buffer_; @@ -110,7 +110,7 @@ private: // The timer putting a time limit on requests. boost::asio::basic_waitable_timer request_deadline_{ - acceptor_.get_io_service(), (std::chrono::steady_clock::time_point::max)()}; + acceptor_.get_executor().context(), (std::chrono::steady_clock::time_point::max)()}; // The string-based response message. boost::optional>> string_response_; @@ -142,7 +142,7 @@ private: else { // Request must be fully processed within 60 seconds. - request_deadline_.expires_from_now( + request_deadline_.expires_after( std::chrono::seconds(60)); read_request(); @@ -288,7 +288,7 @@ private: void check_deadline() { // The deadline may have moved, so check it has really passed. - if (request_deadline_.expires_at() <= std::chrono::steady_clock::now()) + if (request_deadline_.expiry() <= std::chrono::steady_clock::now()) { // Close socket to cancel any outstanding operation. boost::beast::error_code ec; @@ -322,14 +322,14 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } - auto address = ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); unsigned short port = static_cast(std::atoi(argv[2])); std::string doc_root = argv[3]; int num_workers = std::atoi(argv[4]); bool spin = (std::strcmp(argv[5], "spin") == 0); - boost::asio::io_service ios{1}; - tcp::acceptor acceptor{ios, {address, port}}; + boost::asio::io_context ioc{1}; + tcp::acceptor acceptor{ioc, {address, port}}; std::list workers; for (int i = 0; i < num_workers; ++i) @@ -339,9 +339,9 @@ int main(int argc, char* argv[]) } if (spin) - for (;;) ios.poll(); + for (;;) ioc.poll(); else - ios.run(); + ioc.run(); } catch (const std::exception& e) { diff --git a/example/http/server/flex/http_server_flex.cpp b/example/http/server/flex/http_server_flex.cpp index 46084fbc..5614ec48 100644 --- a/example/http/server/flex/http_server_flex.cpp +++ b/example/http/server/flex/http_server_flex.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -255,12 +256,14 @@ class session http::async_write( self_.derived().stream(), *sp, - self_.strand_.wrap(std::bind( - &session::on_write, - self_.derived().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2, - ! sp->keep_alive()))); + boost::asio::bind_executor( + self_.strand_, + std::bind( + &session::on_write, + self_.derived().shared_from_this(), + std::placeholders::_1, + std::placeholders::_2, + ! sp->keep_alive()))); } }; @@ -270,19 +273,20 @@ class session send_lambda lambda_; protected: - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::flat_buffer buffer_; public: // Take ownership of the buffer explicit session( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, boost::beast::flat_buffer buffer, std::string const& doc_root) : doc_root_(doc_root) , lambda_(*this) - , strand_(ios) + , strand_(ioc.get_executor()) , buffer_(std::move(buffer)) { } @@ -295,11 +299,13 @@ public: derived().stream(), buffer_, req_, - strand_.wrap(std::bind( - &session::on_read, - derived().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_read, + derived().shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -352,7 +358,8 @@ class plain_session , public std::enable_shared_from_this { tcp::socket socket_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; public: // Create the session @@ -361,11 +368,11 @@ public: boost::beast::flat_buffer buffer, std::string const& doc_root) : session( - socket.get_io_service(), + socket.get_executor().context(), std::move(buffer), doc_root) , socket_(std::move(socket)) - , strand_(socket_.get_io_service()) + , strand_(socket_.get_executor()) { } @@ -401,7 +408,8 @@ class ssl_session { tcp::socket socket_; ssl::stream stream_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; public: // Create the session @@ -411,12 +419,12 @@ public: boost::beast::flat_buffer buffer, std::string const& doc_root) : session( - socket.get_io_service(), + socket.get_executor().context(), std::move(buffer), doc_root) , socket_(std::move(socket)) , stream_(socket_, ctx) - , strand_(stream_.get_io_service()) + , strand_(stream_.get_executor()) { } @@ -436,11 +444,13 @@ public: stream_.async_handshake( ssl::stream_base::server, buffer_.data(), - strand_.wrap(std::bind( - &ssl_session::on_handshake, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &ssl_session::on_handshake, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void on_handshake( @@ -461,10 +471,12 @@ public: { // Perform the SSL shutdown stream_.async_shutdown( - strand_.wrap(std::bind( - &ssl_session::on_shutdown, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &ssl_session::on_shutdown, + shared_from_this(), + std::placeholders::_1))); } void @@ -484,7 +496,8 @@ class detect_session : public std::enable_shared_from_this { tcp::socket socket_; ssl::context& ctx_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; std::string const& doc_root_; boost::beast::flat_buffer buffer_; @@ -496,7 +509,7 @@ public: std::string const& doc_root) : socket_(std::move(socket)) , ctx_(ctx) - , strand_(socket_.get_io_service()) + , strand_(socket_.get_executor()) , doc_root_(doc_root) { } @@ -508,11 +521,13 @@ public: async_detect_ssl( socket_, buffer_, - strand_.wrap(std::bind( - &detect_session::on_detect, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &detect_session::on_detect, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } @@ -545,21 +560,22 @@ public: class listener : public std::enable_shared_from_this { ssl::context& ctx_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; tcp::acceptor acceptor_; tcp::socket socket_; std::string const& doc_root_; public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, tcp::endpoint endpoint, std::string const& doc_root) : ctx_(ctx) - , strand_(ios) - , acceptor_(ios) - , socket_(ios) + , strand_(ioc.get_executor()) + , acceptor_(ioc) + , socket_(ioc) , doc_root_(doc_root) { boost::system::error_code ec; @@ -582,7 +598,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -644,13 +660,13 @@ int main(int argc, char* argv[]) " http-server-sync 0.0.0.0 8080 .\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -660,7 +676,7 @@ int main(int argc, char* argv[]) // Create and launch a listening port std::make_shared( - ios, + ioc, ctx, tcp::endpoint{address, port}, doc_root)->run(); @@ -670,11 +686,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/server/small/http_server_small.cpp b/example/http/server/small/http_server_small.cpp index c719b2d0..248eb449 100644 --- a/example/http/server/small/http_server_small.cpp +++ b/example/http/server/small/http_server_small.cpp @@ -75,7 +75,7 @@ private: // The timer for putting a deadline on connection processing. boost::asio::basic_waitable_timer deadline_{ - socket_.get_io_service(), std::chrono::seconds(60)}; + socket_.get_executor().context(), std::chrono::seconds(60)}; // Asynchronously receive a complete request message. void @@ -231,16 +231,16 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } - auto address = ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); unsigned short port = static_cast(std::atoi(argv[2])); - boost::asio::io_service ios{1}; + boost::asio::io_context ioc{1}; - tcp::acceptor acceptor{ios, {address, port}}; - tcp::socket socket{ios}; + tcp::acceptor acceptor{ioc, {address, port}}; + tcp::socket socket{ioc}; http_server(acceptor, socket); - ios.run(); + ioc.run(); } catch(std::exception const& e) { diff --git a/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp b/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp index ce037b58..eb3e7e88 100644 --- a/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp +++ b/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -247,18 +248,21 @@ class session http::async_write( self_.socket_, *sp, - self_.strand_.wrap(std::bind( - &session::loop, - self_.shared_from_this(), - std::placeholders::_1, - std::placeholders::_2, - ! sp->keep_alive()))); + boost::asio::bind_executor( + self_.strand_, + std::bind( + &session::loop, + self_.shared_from_this(), + std::placeholders::_1, + std::placeholders::_2, + ! sp->keep_alive()))); } }; tcp::socket socket_; ssl::stream stream_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::flat_buffer buffer_; std::string const& doc_root_; http::request req_; @@ -274,7 +278,7 @@ public: std::string const& doc_root) : socket_(std::move(socket)) , stream_(socket_, ctx) - , strand_(socket_.get_io_service()) + , strand_(socket_.get_executor()) , doc_root_(doc_root) , lambda_(*this) { @@ -300,12 +304,14 @@ public: // Perform the SSL handshake yield stream_.async_handshake( ssl::stream_base::server, - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - 0, - false))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + 0, + false))); if(ec) return fail(ec, "handshake"); @@ -313,12 +319,14 @@ public: { // Read a request yield http::async_read(stream_, buffer_, req_, - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2, - false))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2, + false))); if(ec == http::error::end_of_stream) { // The remote host closed the connection @@ -344,12 +352,14 @@ public: // Perform the SSL shutdown yield stream_.async_shutdown( - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - 0, - false))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + 0, + false))); if(ec) return fail(ec, "shutdown"); @@ -373,13 +383,13 @@ class listener public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, tcp::endpoint endpoint, std::string const& doc_root) : ctx_(ctx) - , acceptor_(ios) - , socket_(ios) + , acceptor_(ioc) + , socket_(ioc) , doc_root_(doc_root) { boost::system::error_code ec; @@ -402,7 +412,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -464,13 +474,13 @@ int main(int argc, char* argv[]) " http-server-stackless-ssl 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -480,7 +490,7 @@ int main(int argc, char* argv[]) // Create and launch a listening port std::make_shared( - ios, + ioc, ctx, tcp::endpoint{address, port}, doc_root)->run(); @@ -490,11 +500,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/server/stackless/http_server_stackless.cpp b/example/http/server/stackless/http_server_stackless.cpp index 2dc8d86c..936ac3f7 100644 --- a/example/http/server/stackless/http_server_stackless.cpp +++ b/example/http/server/stackless/http_server_stackless.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -244,17 +245,20 @@ class session http::async_write( self_.socket_, *sp, - self_.strand_.wrap(std::bind( - &session::loop, - self_.shared_from_this(), - std::placeholders::_1, - std::placeholders::_2, - ! sp->keep_alive()))); + boost::asio::bind_executor( + self_.strand_, + std::bind( + &session::loop, + self_.shared_from_this(), + std::placeholders::_1, + std::placeholders::_2, + ! sp->keep_alive()))); } }; tcp::socket socket_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::flat_buffer buffer_; std::string const& doc_root_; http::request req_; @@ -268,7 +272,7 @@ public: tcp::socket socket, std::string const& doc_root) : socket_(std::move(socket)) - , strand_(socket_.get_io_service()) + , strand_(socket_.get_executor()) , doc_root_(doc_root) , lambda_(*this) { @@ -295,12 +299,14 @@ public: { // Read a request yield http::async_read(socket_, buffer_, req_, - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2, - false))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2, + false))); if(ec == http::error::end_of_stream) { // The remote host closed the connection @@ -346,11 +352,11 @@ class listener public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint, std::string const& doc_root) - : acceptor_(ios) - , socket_(ios) + : acceptor_(ioc) + , socket_(ioc) , doc_root_(doc_root) { boost::system::error_code ec; @@ -372,7 +378,7 @@ public: } // Start listening for connections - acceptor_.listen(boost::asio::socket_base::max_connections, ec); + acceptor_.listen(boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -433,17 +439,17 @@ int main(int argc, char* argv[]) " http-server-stackless 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - auto const threads = std::max(1, std::atoi(argv[4])); + auto const threads = std::max(1, std::atoi(argv[4])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // Create and launch a listening port std::make_shared( - ios, + ioc, tcp::endpoint{address, port}, doc_root)->run(); @@ -452,11 +458,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/http/server/sync-ssl/http_server_sync_ssl.cpp b/example/http/server/sync-ssl/http_server_sync_ssl.cpp index 98894711..d478a0f7 100644 --- a/example/http/server/sync-ssl/http_server_sync_ssl.cpp +++ b/example/http/server/sync-ssl/http_server_sync_ssl.cpp @@ -311,12 +311,12 @@ int main(int argc, char* argv[]) " http-server-sync-ssl 0.0.0.0 8080 .\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios{1}; + // The io_context is required for all I/O + boost::asio::io_context ioc{1}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -325,11 +325,11 @@ int main(int argc, char* argv[]) load_server_certificate(ctx); // The acceptor receives incoming connections - tcp::acceptor acceptor{ios, {address, port}}; + tcp::acceptor acceptor{ioc, {address, port}}; for(;;) { // This will receive the new connection - tcp::socket socket{ios}; + tcp::socket socket{ioc}; // Block until we get a connection acceptor.accept(socket); diff --git a/example/http/server/sync/http_server_sync.cpp b/example/http/server/sync/http_server_sync.cpp index 1e76873c..f2ed7331 100644 --- a/example/http/server/sync/http_server_sync.cpp +++ b/example/http/server/sync/http_server_sync.cpp @@ -298,19 +298,19 @@ int main(int argc, char* argv[]) " http-server-sync 0.0.0.0 8080 .\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); std::string const doc_root = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios{1}; + // The io_context is required for all I/O + boost::asio::io_context ioc{1}; // The acceptor receives incoming connections - tcp::acceptor acceptor{ios, {address, port}}; + tcp::acceptor acceptor{ioc, {address, port}}; for(;;) { // This will receive the new connection - tcp::socket socket{ios}; + tcp::socket socket{ioc}; // Block until we get a connection acceptor.accept(socket); diff --git a/example/websocket/client/async-ssl/websocket_client_async_ssl.cpp b/example/websocket/client/async-ssl/websocket_client_async_ssl.cpp index e1ee6238..c6337ae6 100644 --- a/example/websocket/client/async-ssl/websocket_client_async_ssl.cpp +++ b/example/websocket/client/async-ssl/websocket_client_async_ssl.cpp @@ -50,11 +50,11 @@ class session : public std::enable_shared_from_this std::string text_; public: - // Resolver and socket require an io_service + // Resolver and socket require an io_context explicit - session(boost::asio::io_service& ios, ssl::context& ctx) - : resolver_(ios) - , ws_(ios, ctx) + session(boost::asio::io_context& ioc, ssl::context& ctx) + : resolver_(ioc) + , ws_(ioc, ctx) { } @@ -70,7 +70,9 @@ public: text_ = text; // Look up the domain name - resolver_.async_resolve({host, port}, + resolver_.async_resolve( + host, + port, std::bind( &session::on_resolve, shared_from_this(), @@ -81,7 +83,7 @@ public: void on_resolve( boost::system::error_code ec, - tcp::resolver::iterator result) + tcp::resolver::results_type results) { if(ec) return fail(ec, "resolve"); @@ -89,7 +91,8 @@ public: // Make the connection on the IP address we get from a lookup boost::asio::async_connect( ws_.next_layer().next_layer(), - result, + results.begin(), + results.end(), std::bind( &session::on_connect, shared_from_this(), @@ -209,8 +212,8 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const text = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23_client}; @@ -219,11 +222,11 @@ int main(int argc, char** argv) load_root_certificates(ctx); // Launch the asynchronous operation - std::make_shared(ios, ctx)->run(host, port, text); + std::make_shared(ioc, ctx)->run(host, port, text); // Run the I/O service. The call will return when // the get operation is complete. - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/client/async/websocket_client_async.cpp b/example/websocket/client/async/websocket_client_async.cpp index 757a8fcd..e09f6a5b 100644 --- a/example/websocket/client/async/websocket_client_async.cpp +++ b/example/websocket/client/async/websocket_client_async.cpp @@ -45,11 +45,11 @@ class session : public std::enable_shared_from_this std::string text_; public: - // Resolver and socket require an io_service + // Resolver and socket require an io_context explicit - session(boost::asio::io_service& ios) - : resolver_(ios) - , ws_(ios) + session(boost::asio::io_context& ioc) + : resolver_(ioc) + , ws_(ioc) { } @@ -65,7 +65,9 @@ public: text_ = text; // Look up the domain name - resolver_.async_resolve({host, port}, + resolver_.async_resolve( + host, + port, std::bind( &session::on_resolve, shared_from_this(), @@ -76,7 +78,7 @@ public: void on_resolve( boost::system::error_code ec, - tcp::resolver::iterator result) + tcp::resolver::results_type results) { if(ec) return fail(ec, "resolve"); @@ -84,7 +86,8 @@ public: // Make the connection on the IP address we get from a lookup boost::asio::async_connect( ws_.next_layer(), - result, + results.begin(), + results.end(), std::bind( &session::on_connect, shared_from_this(), @@ -189,15 +192,15 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const text = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // Launch the asynchronous operation - std::make_shared(ios)->run(host, port, text); + std::make_shared(ioc)->run(host, port, text); // Run the I/O service. The call will return when // the get operation is complete. - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp b/example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp index 066d7f49..6fed0d05 100644 --- a/example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp +++ b/example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp @@ -46,23 +46,23 @@ do_session( std::string const& host, std::string const& port, std::string const& text, - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, boost::asio::yield_context yield) { boost::system::error_code ec; // These objects perform our I/O - tcp::resolver resolver{ios}; - websocket::stream> ws{ios, ctx}; + tcp::resolver resolver{ioc}; + websocket::stream> ws{ioc, ctx}; // Look up the domain name - auto const lookup = resolver.async_resolve({host, port}, yield[ec]); + auto const results = resolver.async_resolve(host, port, yield[ec]); if(ec) return fail(ec, "resolve"); // Make the connection on the IP address we get from a lookup - boost::asio::async_connect(ws.next_layer().next_layer(), lookup, yield[ec]); + boost::asio::async_connect(ws.next_layer().next_layer(), results.begin(), results.end(), yield[ec]); if(ec) return fail(ec, "connect"); @@ -117,8 +117,8 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const text = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23_client}; @@ -127,18 +127,18 @@ int main(int argc, char** argv) load_root_certificates(ctx); // Launch the asynchronous operation - boost::asio::spawn(ios, std::bind( + boost::asio::spawn(ioc, std::bind( &do_session, std::string(host), std::string(port), std::string(text), - std::ref(ios), + std::ref(ioc), std::ref(ctx), std::placeholders::_1)); // Run the I/O service. The call will return when // the get operation is complete. - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/client/coro/websocket_client_coro.cpp b/example/websocket/client/coro/websocket_client_coro.cpp index d12b298a..5aa4c755 100644 --- a/example/websocket/client/coro/websocket_client_coro.cpp +++ b/example/websocket/client/coro/websocket_client_coro.cpp @@ -41,22 +41,22 @@ do_session( std::string const& host, std::string const& port, std::string const& text, - boost::asio::io_service& ios, + boost::asio::io_context& ioc, boost::asio::yield_context yield) { boost::system::error_code ec; // These objects perform our I/O - tcp::resolver resolver{ios}; - websocket::stream ws{ios}; + tcp::resolver resolver{ioc}; + websocket::stream ws{ioc}; // Look up the domain name - auto const lookup = resolver.async_resolve({host, port}, yield[ec]); + auto const results = resolver.async_resolve(host, port, yield[ec]); if(ec) return fail(ec, "resolve"); // Make the connection on the IP address we get from a lookup - boost::asio::async_connect(ws.next_layer(), lookup, yield[ec]); + boost::asio::async_connect(ws.next_layer(), results.begin(), results.end(), yield[ec]); if(ec) return fail(ec, "connect"); @@ -106,21 +106,21 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const text = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // Launch the asynchronous operation - boost::asio::spawn(ios, std::bind( + boost::asio::spawn(ioc, std::bind( &do_session, std::string(host), std::string(port), std::string(text), - std::ref(ios), + std::ref(ioc), std::placeholders::_1)); // Run the I/O service. The call will return when // the get operation is complete. - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp b/example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp index fe388a17..6281ec7c 100644 --- a/example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp +++ b/example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp @@ -47,8 +47,8 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const text = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23_client}; @@ -57,14 +57,14 @@ int main(int argc, char** argv) load_root_certificates(ctx); // These objects perform our I/O - tcp::resolver resolver{ios}; - websocket::stream> ws{ios, ctx}; + tcp::resolver resolver{ioc}; + websocket::stream> ws{ioc, ctx}; // Look up the domain name - auto const lookup = resolver.resolve({host, port}); + auto const results = resolver.resolve(host, port); // Make the connection on the IP address we get from a lookup - boost::asio::connect(ws.next_layer().next_layer(), lookup); + boost::asio::connect(ws.next_layer().next_layer(), results.begin(), results.end()); // Perform the SSL handshake ws.next_layer().handshake(ssl::stream_base::client); diff --git a/example/websocket/client/sync/websocket_client_sync.cpp b/example/websocket/client/sync/websocket_client_sync.cpp index 690630a2..bde16c56 100644 --- a/example/websocket/client/sync/websocket_client_sync.cpp +++ b/example/websocket/client/sync/websocket_client_sync.cpp @@ -44,18 +44,18 @@ int main(int argc, char** argv) auto const port = argv[2]; auto const text = argv[3]; - // The io_service is required for all I/O - boost::asio::io_service ios; + // The io_context is required for all I/O + boost::asio::io_context ioc; // These objects perform our I/O - tcp::resolver resolver{ios}; - websocket::stream ws{ios}; + tcp::resolver resolver{ioc}; + websocket::stream ws{ioc}; // Look up the domain name - auto const lookup = resolver.resolve({host, port}); + auto const results = resolver.resolve(host, port); // Make the connection on the IP address we get from a lookup - boost::asio::connect(ws.next_layer(), lookup); + boost::asio::connect(ws.next_layer(), results.begin(), results.end()); // Perform the websocket handshake ws.handshake(host, "/"); diff --git a/example/websocket/server/async-ssl/websocket_server_async_ssl.cpp b/example/websocket/server/async-ssl/websocket_server_async_ssl.cpp index a3469d56..a08aceb5 100644 --- a/example/websocket/server/async-ssl/websocket_server_async_ssl.cpp +++ b/example/websocket/server/async-ssl/websocket_server_async_ssl.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,8 @@ class session : public std::enable_shared_from_this { tcp::socket socket_; websocket::stream> ws_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::multi_buffer buffer_; public: @@ -56,7 +58,7 @@ public: session(tcp::socket socket, ssl::context& ctx) : socket_(std::move(socket)) , ws_(socket_, ctx) - , strand_(ws_.get_io_service()) + , strand_(ws_.get_executor()) { } @@ -67,10 +69,12 @@ public: // Perform the SSL handshake ws_.next_layer().async_handshake( ssl::stream_base::server, - strand_.wrap(std::bind( - &session::on_handshake, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_handshake, + shared_from_this(), + std::placeholders::_1))); } void @@ -81,10 +85,12 @@ public: // Accept the websocket handshake ws_.async_accept( - strand_.wrap(std::bind( - &session::on_accept, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_accept, + shared_from_this(), + std::placeholders::_1))); } void @@ -103,11 +109,13 @@ public: // Read a message into our buffer ws_.async_read( buffer_, - strand_.wrap(std::bind( - &session::on_read, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_read, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -128,11 +136,13 @@ public: ws_.text(ws_.got_text()); ws_.async_write( buffer_.data(), - strand_.wrap(std::bind( - &session::on_write, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_write, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -164,12 +174,12 @@ class listener : public std::enable_shared_from_this public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, tcp::endpoint endpoint) : ctx_(ctx) - , acceptor_(ios) - , socket_(ios) + , acceptor_(ioc) + , socket_(ioc) { boost::system::error_code ec; @@ -191,7 +201,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -250,12 +260,12 @@ int main(int argc, char* argv[]) " websocket-server-async-ssl 0.0.0.0 8080 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - auto const threads = std::max(1, std::atoi(argv[3])); + auto const threads = std::max(1, std::atoi(argv[3])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -264,18 +274,18 @@ int main(int argc, char* argv[]) load_server_certificate(ctx); // Create and launch a listening port - std::make_shared(ios, ctx, tcp::endpoint{address, port})->run(); + std::make_shared(ioc, ctx, tcp::endpoint{address, port})->run(); // Run the I/O service on the requested number of threads std::vector v; v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/server/async/websocket_server_async.cpp b/example/websocket/server/async/websocket_server_async.cpp index ae87fea5..afaafc52 100644 --- a/example/websocket/server/async/websocket_server_async.cpp +++ b/example/websocket/server/async/websocket_server_async.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,8 @@ fail(boost::system::error_code ec, char const* what) class session : public std::enable_shared_from_this { websocket::stream ws_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::multi_buffer buffer_; public: @@ -50,7 +52,7 @@ public: explicit session(tcp::socket socket) : ws_(std::move(socket)) - , strand_(ws_.get_io_service()) + , strand_(ws_.get_executor()) { } @@ -60,10 +62,12 @@ public: { // Accept the websocket handshake ws_.async_accept( - strand_.wrap(std::bind( - &session::on_accept, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_accept, + shared_from_this(), + std::placeholders::_1))); } void @@ -82,11 +86,13 @@ public: // Read a message into our buffer ws_.async_read( buffer_, - strand_.wrap(std::bind( - &session::on_read, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_read, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -107,11 +113,13 @@ public: ws_.text(ws_.got_text()); ws_.async_write( buffer_.data(), - strand_.wrap(std::bind( - &session::on_write, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::on_write, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -142,10 +150,10 @@ class listener : public std::enable_shared_from_this public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint) - : acceptor_(ios) - , socket_(ios) + : acceptor_(ioc) + , socket_(ioc) { boost::system::error_code ec; @@ -167,7 +175,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -226,26 +234,26 @@ int main(int argc, char* argv[]) " websocket-server-async 0.0.0.0 8080 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - auto const threads = std::max(1, std::atoi(argv[3])); + auto const threads = std::max(1, std::atoi(argv[3])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // Create and launch a listening port - std::make_shared(ios, tcp::endpoint{address, port})->run(); + std::make_shared(ioc, tcp::endpoint{address, port})->run(); // Run the I/O service on the requested number of threads std::vector v; v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp b/example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp index ef522ace..b480557d 100644 --- a/example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp +++ b/example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp @@ -93,7 +93,7 @@ do_session( // Accepts incoming connections and launches the sessions void do_listen( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, tcp::endpoint endpoint, boost::asio::yield_context yield) @@ -101,7 +101,7 @@ do_listen( boost::system::error_code ec; // Open the acceptor - tcp::acceptor acceptor(ios); + tcp::acceptor acceptor(ioc); acceptor.open(endpoint.protocol(), ec); if(ec) return fail(ec, "open"); @@ -112,19 +112,19 @@ do_listen( return fail(ec, "bind"); // Start listening for connections - acceptor.listen(boost::asio::socket_base::max_connections, ec); + acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); if(ec) return fail(ec, "listen"); for(;;) { - tcp::socket socket(ios); + tcp::socket socket(ioc); acceptor.async_accept(socket, yield[ec]); if(ec) fail(ec, "accept"); else boost::asio::spawn( - acceptor.get_io_service(), + acceptor.get_executor().context(), std::bind( &do_session, std::move(socket), @@ -144,12 +144,12 @@ int main(int argc, char* argv[]) " websocket-server-coro-ssl 0.0.0.0 8080 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - auto const threads = std::max(1, std::atoi(argv[3])); + auto const threads = std::max(1, std::atoi(argv[3])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -158,10 +158,10 @@ int main(int argc, char* argv[]) load_server_certificate(ctx); // Spawn a listening port - boost::asio::spawn(ios, + boost::asio::spawn(ioc, std::bind( &do_listen, - std::ref(ios), + std::ref(ioc), std::ref(ctx), tcp::endpoint{address, port}, std::placeholders::_1)); @@ -171,11 +171,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/server/coro/websocket_server_coro.cpp b/example/websocket/server/coro/websocket_server_coro.cpp index ee36a2ec..85d2e9c5 100644 --- a/example/websocket/server/coro/websocket_server_coro.cpp +++ b/example/websocket/server/coro/websocket_server_coro.cpp @@ -80,14 +80,14 @@ do_session(tcp::socket& socket, boost::asio::yield_context yield) // Accepts incoming connections and launches the sessions void do_listen( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint, boost::asio::yield_context yield) { boost::system::error_code ec; // Open the acceptor - tcp::acceptor acceptor(ios); + tcp::acceptor acceptor(ioc); acceptor.open(endpoint.protocol(), ec); if(ec) return fail(ec, "open"); @@ -98,19 +98,19 @@ do_listen( return fail(ec, "bind"); // Start listening for connections - acceptor.listen(boost::asio::socket_base::max_connections, ec); + acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); if(ec) return fail(ec, "listen"); for(;;) { - tcp::socket socket(ios); + tcp::socket socket(ioc); acceptor.async_accept(socket, yield[ec]); if(ec) fail(ec, "accept"); else boost::asio::spawn( - acceptor.get_io_service(), + acceptor.get_executor().context(), std::bind( &do_session, std::move(socket), @@ -129,18 +129,18 @@ int main(int argc, char* argv[]) " websocket-server-coro 0.0.0.0 8080 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - auto const threads = std::max(1, std::atoi(argv[3])); + auto const threads = std::max(1, std::atoi(argv[3])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // Spawn a listening port - boost::asio::spawn(ios, + boost::asio::spawn(ioc, std::bind( &do_listen, - std::ref(ios), + std::ref(ioc), tcp::endpoint{address, port}, std::placeholders::_1)); @@ -149,11 +149,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/server/fast/websocket_server_fast.cpp b/example/websocket/server/fast/websocket_server_fast.cpp index d0570465..f0654c6c 100644 --- a/example/websocket/server/fast/websocket_server_fast.cpp +++ b/example/websocket/server/fast/websocket_server_fast.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -113,14 +114,14 @@ do_sync_session(tcp::socket& socket) void do_sync_listen( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint) { boost::system::error_code ec; - tcp::acceptor acceptor{ios, endpoint}; + tcp::acceptor acceptor{ioc, endpoint}; for(;;) { - tcp::socket socket{ios}; + tcp::socket socket{ioc}; acceptor.accept(socket, ec); if(ec) @@ -138,7 +139,8 @@ do_sync_listen( class async_session : public std::enable_shared_from_this { websocket::stream ws_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::multi_buffer buffer_; public: @@ -146,7 +148,7 @@ public: explicit async_session(tcp::socket socket) : ws_(std::move(socket)) - , strand_(ws_.get_io_service()) + , strand_(ws_.get_executor()) { setup_stream(ws_); } @@ -162,10 +164,12 @@ public: res.set(http::field::server, "Boost.Beast.async/" + std::to_string(BOOST_BEAST_VERSION)); }, - strand_.wrap(std::bind( - &async_session::on_accept, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &async_session::on_accept, + shared_from_this(), + std::placeholders::_1))); } void @@ -184,11 +188,13 @@ public: // Read a message into our buffer ws_.async_read( buffer_, - strand_.wrap(std::bind( - &async_session::on_read, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &async_session::on_read, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -209,11 +215,13 @@ public: ws_.text(ws_.got_text()); ws_.async_write( buffer_.data(), - strand_.wrap(std::bind( - &async_session::on_write, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &async_session::on_write, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); } void @@ -237,17 +245,18 @@ public: // Accepts incoming connections and launches the sessions class async_listener : public std::enable_shared_from_this { - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; tcp::acceptor acceptor_; tcp::socket socket_; public: async_listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint) - : strand_(ios) - , acceptor_(ios) - , socket_(ios) + : strand_(ioc.get_executor()) + , acceptor_(ioc) + , socket_(ioc) { boost::system::error_code ec; @@ -269,7 +278,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -291,10 +300,12 @@ public: { acceptor_.async_accept( socket_, - strand_.wrap(std::bind( - &async_listener::on_accept, - shared_from_this(), - std::placeholders::_1))); + boost::asio::bind_executor( + strand_, + std::bind( + &async_listener::on_accept, + shared_from_this(), + std::placeholders::_1))); } void @@ -354,13 +365,13 @@ do_coro_session(tcp::socket& socket, boost::asio::yield_context yield) void do_coro_listen( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint, boost::asio::yield_context yield) { boost::system::error_code ec; - tcp::acceptor acceptor(ios); + tcp::acceptor acceptor(ioc); acceptor.open(endpoint.protocol(), ec); if(ec) return fail(ec, "open"); @@ -369,13 +380,13 @@ do_coro_listen( if(ec) return fail(ec, "bind"); - acceptor.listen(boost::asio::socket_base::max_connections, ec); + acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); if(ec) return fail(ec, "listen"); for(;;) { - tcp::socket socket(ios); + tcp::socket socket(ioc); acceptor.async_accept(socket, yield[ec]); if(ec) @@ -385,7 +396,7 @@ do_coro_listen( } boost::asio::spawn( - acceptor.get_io_service(), + acceptor.get_executor().context(), std::bind( &do_coro_session, std::move(socket), @@ -410,17 +421,17 @@ int main(int argc, char* argv[]) " starting-port+2 for coroutine.\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - auto const threads = std::max(1, std::atoi(argv[3])); + auto const threads = std::max(1, std::atoi(argv[3])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // Create sync port std::thread(std::bind( &do_sync_listen, - std::ref(ios), + std::ref(ioc), tcp::endpoint{ address, static_cast(port + 0u)} @@ -428,16 +439,16 @@ int main(int argc, char* argv[]) // Create async port std::make_shared( - ios, + ioc, tcp::endpoint{ address, static_cast(port + 1u)})->run(); // Create coro port - boost::asio::spawn(ios, + boost::asio::spawn(ioc, std::bind( &do_coro_listen, - std::ref(ios), + std::ref(ioc), tcp::endpoint{ address, static_cast(port + 2u)}, @@ -448,11 +459,11 @@ int main(int argc, char* argv[]) v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp b/example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp index 7c94f59b..7162ab78 100644 --- a/example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp +++ b/example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,8 @@ class session { tcp::socket socket_; websocket::stream> ws_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::multi_buffer buffer_; public: @@ -59,7 +61,7 @@ public: session(tcp::socket socket, ssl::context& ctx) : socket_(std::move(socket)) , ws_(socket_, ctx) - , strand_(ws_.get_io_service()) + , strand_(ws_.get_executor()) { } @@ -83,21 +85,25 @@ public: // Perform the SSL handshake yield ws_.next_layer().async_handshake( ssl::stream_base::server, - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - 0))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + 0))); if(ec) return fail(ec, "handshake"); // Accept the websocket handshake yield ws_.async_accept( - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - 0))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + 0))); if(ec) return fail(ec, "accept"); @@ -106,11 +112,13 @@ public: // Read a message into our buffer yield ws_.async_read( buffer_, - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); if(ec == websocket::error::closed) { // This indicates that the session was closed @@ -123,11 +131,13 @@ public: ws_.text(ws_.got_text()); yield ws_.async_write( buffer_.data(), - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); if(ec) return fail(ec, "write"); @@ -152,12 +162,12 @@ class listener public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, ssl::context& ctx, tcp::endpoint endpoint) : ctx_(ctx) - , acceptor_(ios) - , socket_(ios) + , acceptor_(ioc) + , socket_(ioc) { boost::system::error_code ec; @@ -179,7 +189,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -238,12 +248,12 @@ int main(int argc, char* argv[]) " websocket-server-async-ssl 0.0.0.0 8080 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - auto const threads = std::max(1, std::atoi(argv[3])); + auto const threads = std::max(1, std::atoi(argv[3])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -252,18 +262,18 @@ int main(int argc, char* argv[]) load_server_certificate(ctx); // Create and launch a listening port - std::make_shared(ios, ctx, tcp::endpoint{address, port})->run(); + std::make_shared(ioc, ctx, tcp::endpoint{address, port})->run(); // Run the I/O service on the requested number of threads std::vector v; v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/server/stackless/websocket_server_stackless.cpp b/example/websocket/server/stackless/websocket_server_stackless.cpp index d76949ad..cc4eb252 100644 --- a/example/websocket/server/stackless/websocket_server_stackless.cpp +++ b/example/websocket/server/stackless/websocket_server_stackless.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -45,7 +46,8 @@ class session , public std::enable_shared_from_this { websocket::stream ws_; - boost::asio::io_service::strand strand_; + boost::asio::strand< + boost::asio::io_context::executor_type> strand_; boost::beast::multi_buffer buffer_; public: @@ -53,7 +55,7 @@ public: explicit session(tcp::socket socket) : ws_(std::move(socket)) - , strand_(ws_.get_io_service()) + , strand_(ws_.get_executor()) { } @@ -75,11 +77,13 @@ public: { // Accept the websocket handshake yield ws_.async_accept( - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - 0))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + 0))); if(ec) return fail(ec, "accept"); @@ -88,11 +92,13 @@ public: // Read a message into our buffer yield ws_.async_read( buffer_, - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); if(ec == websocket::error::closed) { // This indicates that the session was closed @@ -105,11 +111,13 @@ public: ws_.text(ws_.got_text()); yield ws_.async_write( buffer_.data(), - strand_.wrap(std::bind( - &session::loop, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + boost::asio::bind_executor( + strand_, + std::bind( + &session::loop, + shared_from_this(), + std::placeholders::_1, + std::placeholders::_2))); if(ec) return fail(ec, "write"); @@ -133,10 +141,10 @@ class listener public: listener( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, tcp::endpoint endpoint) - : acceptor_(ios) - , socket_(ios) + : acceptor_(ioc) + , socket_(ioc) { boost::system::error_code ec; @@ -158,7 +166,7 @@ public: // Start listening for connections acceptor_.listen( - boost::asio::socket_base::max_connections, ec); + boost::asio::socket_base::max_listen_connections, ec); if(ec) { fail(ec, "listen"); @@ -217,26 +225,26 @@ int main(int argc, char* argv[]) " websocket-server-stackless 0.0.0.0 8080 1\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - auto const threads = std::max(1, std::atoi(argv[3])); + auto const threads = std::max(1, std::atoi(argv[3])); - // The io_service is required for all I/O - boost::asio::io_service ios{threads}; + // The io_context is required for all I/O + boost::asio::io_context ioc{threads}; // Create and launch a listening port - std::make_shared(ios, tcp::endpoint{address, port})->run(); + std::make_shared(ioc, tcp::endpoint{address, port})->run(); // Run the I/O service on the requested number of threads std::vector v; v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( - [&ios] + [&ioc] { - ios.run(); + ioc.run(); }); - ios.run(); + ioc.run(); return EXIT_SUCCESS; } diff --git a/example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp b/example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp index 8328ec78..1e3f7332 100644 --- a/example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp +++ b/example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp @@ -87,11 +87,11 @@ int main(int argc, char* argv[]) " websocket-server-sync-ssl 0.0.0.0 8080\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - // The io_service is required for all I/O - boost::asio::io_service ios{1}; + // The io_context is required for all I/O + boost::asio::io_context ioc{1}; // The SSL context is required, and holds certificates ssl::context ctx{ssl::context::sslv23}; @@ -100,11 +100,11 @@ int main(int argc, char* argv[]) load_server_certificate(ctx); // The acceptor receives incoming connections - tcp::acceptor acceptor{ios, {address, port}}; + tcp::acceptor acceptor{ioc, {address, port}}; for(;;) { // This will receive the new connection - tcp::socket socket{ios}; + tcp::socket socket{ioc}; // Block until we get a connection acceptor.accept(socket); diff --git a/example/websocket/server/sync/websocket_server_sync.cpp b/example/websocket/server/sync/websocket_server_sync.cpp index 8ba0f3f6..7a4878cf 100644 --- a/example/websocket/server/sync/websocket_server_sync.cpp +++ b/example/websocket/server/sync/websocket_server_sync.cpp @@ -79,18 +79,18 @@ int main(int argc, char* argv[]) " websocket-server-sync 0.0.0.0 8080\n"; return EXIT_FAILURE; } - auto const address = boost::asio::ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); - // The io_service is required for all I/O - boost::asio::io_service ios{1}; + // The io_context is required for all I/O + boost::asio::io_context ioc{1}; // The acceptor receives incoming connections - tcp::acceptor acceptor{ios, {address, port}}; + tcp::acceptor acceptor{ioc, {address, port}}; for(;;) { // This will receive the new connection - tcp::socket socket{ios}; + tcp::socket socket{ioc}; // Block until we get a connection acceptor.accept(socket); diff --git a/include/boost/beast/core.hpp b/include/boost/beast/core.hpp index 0cc3d457..620d42ad 100644 --- a/include/boost/beast/core.hpp +++ b/include/boost/beast/core.hpp @@ -12,7 +12,6 @@ #include -#include #include #include #include @@ -28,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/include/boost/beast/core/async_result.hpp b/include/boost/beast/core/async_result.hpp deleted file mode 100644 index 47d7aa92..00000000 --- a/include/boost/beast/core/async_result.hpp +++ /dev/null @@ -1,209 +0,0 @@ -// -// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail 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) -// -// Official repository: https://github.com/boostorg/beast -// - -#ifndef BOOST_BEAST_ASYNC_COMPLETION_HPP -#define BOOST_BEAST_ASYNC_COMPLETION_HPP - -#include -#include -#include -#include -#include -#include - -namespace boost { -namespace beast { - -/** An interface for customising the behaviour of an asynchronous initiation function. - - This class is used for determining: - - @li The concrete completion handler type to be called at the end of the - asynchronous operation; - - @li the initiating function return type; and - - @li how the return value of the initiating function is obtained. - - The trait allows the handler and return types to be determined at the point - where the specific completion handler signature is known. - - This template takes advantage of specializations of both - `boost::asio::async_result` and `boost::asio::handler_type` for user-defined - completion token types. The primary template assumes that the - @b CompletionToken is the completion handler. - - @par Example - - The example shows how to define an asynchronous initiation function - whose completion handler receives an error code: - - @code - template< - class AsyncStream, // A stream supporting asynchronous read and write - class Handler // The handler to call with signature void(error_code) - > - async_return_type< // This provides the return type customization - Handler, void(error_code)> - do_async( - AsyncStream& stream, // The stream to work on - Handler&& handler) // Could be an rvalue or const reference - { - // Make sure we have an async stream - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - - // This helper converts the handler into the real handler type - async_completion init{handler}; - - ... // Create and invoke the composed operation - - // This provides the return value and executor customization - return init.result.get(); - } - @endcode - - @see @ref async_completion, @ref async_return_type, @ref handler_type -*/ -template -class async_result -{ - BOOST_STATIC_ASSERT( - ! std::is_reference::value); - - boost::asio::async_result::type> impl_; - - async_result(async_result const&) = delete; - async_result& operator=(async_result const&) = delete; - -public: - /// The concrete completion handler type for the specific signature. - using completion_handler_type = - typename boost::asio::handler_type< - CompletionToken, Signature>::type; - - /// The return type of the initiating function. - using return_type = - typename boost::asio::async_result< - completion_handler_type>::type; - - /** Construct an async result from a given handler. - - When using a specalised async_result, the constructor has - an opportunity to initialise some state associated with the - completion handler, which is then returned from the initiating - function. - */ - explicit - async_result(completion_handler_type& h) - : impl_(h) - { - } - - /// Obtain the value to be returned from the initiating function. - return_type - get() - { - return impl_.get(); - } -}; - -/** Helper for customizing the return type of asynchronous initiation functions. - - This class template is used to transform caller-provided completion - handlers in calls to asynchronous initiation functions. The transformation - allows customization of the return type of the initiating function, and the - function signature of the final handler. - - Example: - @code - ... - template - typename async_completion::result_type - async_initfn(..., CompletionToken&& handler) - { - async_completion completion{handler}; - ... - return completion.result.get(); - } - @endcode - - @tparam CompletionToken Specifies the model used to obtain the result of - the asynchronous operation. - - @tparam Signature The call signature for the completion handler type invoked - on completion of the asynchronous operation. - - @note See - Working Draft, C++ Extensions for Networking - - @see @ref async_return_type, @ref handler_type -*/ -template -struct async_completion -{ - /** The type of the final handler called by the asynchronous initiation function. - - Objects of this type will be callable with the specified signature. - */ - using completion_handler_type = typename async_result< - typename std::decay::type, - Signature>::completion_handler_type; - - /** Constructor - - The constructor creates the concrete completion handler and - makes the link between the handler and the asynchronous - result. - - @param token The completion token. If this is a regular completion - handler, copies may be made as needed. If the handler is movable, - it may also be moved. - */ - explicit - async_completion(CompletionToken& token) - : completion_handler(static_cast::value, - completion_handler_type&, CompletionToken&&>::type>(token)) - , result(completion_handler) - { - // CompletionToken is not invokable with the given signature - static_assert(is_completion_handler< - completion_handler_type, Signature>::value, - "CompletionToken requirements not met: signature mismatch"); - } - - /// The final completion handler, callable with the specified signature. - typename std::conditional::value, - completion_handler_type&, - completion_handler_type - >::type completion_handler; - - /// The return value of the asynchronous initiation function. - async_result::type, Signature> result; -}; - -template -using handler_type = typename beast::async_result< - typename std::decay::type, - Signature>::completion_handler_type; - -template -using async_return_type = typename beast::async_result< - typename std::decay::type, - Signature>::return_type; - -} // beast -} // boost - -#endif diff --git a/include/boost/beast/core/bind_handler.hpp b/include/boost/beast/core/bind_handler.hpp index da3e05d1..0756bc5a 100644 --- a/include/boost/beast/core/bind_handler.hpp +++ b/include/boost/beast/core/bind_handler.hpp @@ -27,12 +27,12 @@ namespace beast { placeholders present in the list of bound arguments. Parameters which are not matched to placeholders are silently discarded. The passed handler and arguments are forwarded into the returned - handler, which provides the same `io_service` execution guarantees + handler, which provides the same `io_context` execution guarantees as the original handler. - Unlike `boost::asio::io_service::wrap`, the returned handler can - be used in a subsequent call to `boost::asio::io_service::post` - instead of `boost::asio::io_service::dispatch`, to ensure that + Unlike `boost::asio::io_context::wrap`, the returned handler can + be used in a subsequent call to `boost::asio::io_context::post` + instead of `boost::asio::io_context::dispatch`, to ensure that the handler will not be invoked immediately by the calling function. @@ -43,7 +43,8 @@ namespace beast { void signal_aborted(AsyncReadStream& stream, ReadHandler&& handler) { - stream.get_io_service().post( + boost::asio::post( + stream.get_executor(), bind_handler(std::forward(handler), boost::asio::error::operation_aborted, 0)); } diff --git a/include/boost/beast/core/buffered_read_stream.hpp b/include/boost/beast/core/buffered_read_stream.hpp index 1c15720a..378ae232 100644 --- a/include/boost/beast/core/buffered_read_stream.hpp +++ b/include/boost/beast/core/buffered_read_stream.hpp @@ -11,12 +11,12 @@ #define BOOST_BEAST_BUFFERED_READ_STREAM_HPP #include -#include #include #include #include +#include #include -#include +#include #include #include @@ -91,7 +91,8 @@ namespace beast { template class buffered_read_stream { - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); template @@ -163,11 +164,29 @@ public: return next_layer_.lowest_layer(); } - /// Get the io_service associated with the object. - boost::asio::io_service& - get_io_service() + /** Get the executor associated with the object. + + This function may be used to obtain the executor object that the stream + uses to dispatch handlers for asynchronous operations. + + @return A copy of the executor that stream will use to dispatch handlers. + + @note This function participates in overload resolution only if + `NextLayer` has a member function named `get_executor`. + */ +#if BOOST_BEAST_DOXYGEN + implementation_defined +#else + template< + class T = next_layer_type, + class = typename std::enable_if< + has_get_executor::value>::type> + auto +#endif + get_executor() noexcept -> + decltype(std::declval().get_executor()) { - return next_layer_.get_io_service(); + return next_layer_.get_executor(); } /** Access the internal buffer. @@ -265,14 +284,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code)) async_read_some(MutableBufferSequence const& buffers, ReadHandler&& handler); @@ -340,14 +356,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code)) async_write_some(ConstBufferSequence const& buffers, WriteHandler&& handler); }; diff --git a/include/boost/beast/core/buffers_adapter.hpp b/include/boost/beast/core/buffers_adapter.hpp index bf401aee..826183ed 100644 --- a/include/boost/beast/core/buffers_adapter.hpp +++ b/include/boost/beast/core/buffers_adapter.hpp @@ -35,10 +35,12 @@ namespace beast { template class buffers_adapter { - static_assert(is_mutable_buffer_sequence::value, + static_assert(boost::asio::is_mutable_buffer_sequence::value, "MutableBufferSequence requirements not met"); - using iter_type = typename MutableBufferSequence::const_iterator; + using iter_type = typename + detail::buffer_sequence_iterator< + MutableBufferSequence>::type; MutableBufferSequence bs_; iter_type begin_; diff --git a/include/boost/beast/core/buffers_prefix.hpp b/include/boost/beast/core/buffers_prefix.hpp index fcbfa59c..67d58b5c 100644 --- a/include/boost/beast/core/buffers_prefix.hpp +++ b/include/boost/beast/core/buffers_prefix.hpp @@ -34,8 +34,8 @@ class buffers_prefix_view using buffers_type = typename std::decay::type; - using iter_type = - typename buffers_type::const_iterator; + using iter_type = typename + detail::buffer_sequence_iterator::type; BufferSequence bs_; std::size_t size_; @@ -141,10 +141,8 @@ boost::asio::const_buffer buffers_prefix(std::size_t size, boost::asio::const_buffer buffer) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return { buffer_cast(buffer), - (std::min)(size, buffer_size(buffer)) }; + return {buffer.data(), + (std::min)(size, buffer.size())}; } /** Returns a prefix of a mutable buffer. @@ -166,10 +164,8 @@ boost::asio::mutable_buffer buffers_prefix(std::size_t size, boost::asio::mutable_buffer buffer) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return {buffer_cast(buffer), - (std::min)(size, buffer_size(buffer))}; + return {buffer.data(), + (std::min)(size, buffer.size())}; } /** Returns a prefix of a buffer sequence. @@ -203,8 +199,8 @@ typename std::enable_if< buffers_prefix(std::size_t size, BufferSequence const& buffers) { static_assert( - is_const_buffer_sequence::value || - is_mutable_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value || + boost::asio::is_mutable_buffer_sequence::value, "BufferSequence requirements not met"); return buffers_prefix_view(size, buffers); } @@ -221,13 +217,14 @@ buffers_prefix(std::size_t size, BufferSequence const& buffers) */ template typename std::conditional< - is_mutable_buffer_sequence::value, + boost::asio::is_mutable_buffer_sequence::value, boost::asio::mutable_buffer, boost::asio::const_buffer>::type buffers_front(BufferSequence const& buffers) { - auto const first = buffers.begin(); - if(first == buffers.end()) + auto const first = + boost::asio::buffer_sequence_begin(buffers); + if(first == boost::asio::buffer_sequence_end(buffers)) return {}; return *first; } diff --git a/include/boost/beast/core/buffers_suffix.hpp b/include/boost/beast/core/buffers_suffix.hpp index 9be31a87..81eb5a6b 100644 --- a/include/boost/beast/core/buffers_suffix.hpp +++ b/include/boost/beast/core/buffers_suffix.hpp @@ -12,11 +12,11 @@ #include #include +#include #include #include #include #include -#include #include namespace boost { @@ -57,8 +57,8 @@ class buffers_suffix using buffers_type = typename std::decay::type; - using iter_type = - typename buffers_type::const_iterator; + using iter_type = typename + detail::buffer_sequence_iterator::type; BufferSequence bs_; iter_type begin_; @@ -67,7 +67,9 @@ class buffers_suffix template buffers_suffix(Deduced&& other, std::size_t dist) : bs_(std::forward(other).bs_) - , begin_(std::next(bs_.begin(), dist)) + , begin_(std::next( + boost::asio::buffer_sequence_begin(bs_), + dist)) , skip_(other.skip_) { } diff --git a/include/boost/beast/core/buffers_to_string.hpp b/include/boost/beast/core/buffers_to_string.hpp index 79d25975..aae3d3aa 100644 --- a/include/boost/beast/core/buffers_to_string.hpp +++ b/include/boost/beast/core/buffers_to_string.hpp @@ -11,6 +11,7 @@ #define BOOST_BEAST_BUFFERS_TO_STRING_HPP #include +#include #include #include @@ -45,10 +46,10 @@ buffers_to_string(ConstBufferSequence const& buffers) { std::string result; result.reserve(boost::asio::buffer_size(buffers)); - for(boost::asio::const_buffer buffer : buffers) - result.append( - boost::asio::buffer_cast(buffer), - boost::asio::buffer_size(buffer)); + for(boost::asio::const_buffer buffer : + detail::buffers_range(buffers)) + result.append(reinterpret_cast< + char const*>(buffer.data()), buffer.size()); return result; } diff --git a/include/boost/beast/core/detail/bind_handler.hpp b/include/boost/beast/core/detail/bind_handler.hpp index 5a2ceafe..5a9059b8 100644 --- a/include/boost/beast/core/detail/bind_handler.hpp +++ b/include/boost/beast/core/detail/bind_handler.hpp @@ -11,9 +11,9 @@ #define BOOST_BEAST_DETAIL_BIND_HANDLER_HPP #include -#include +#include +#include #include -#include #include #include #include @@ -24,13 +24,17 @@ namespace detail { /* Nullary handler that calls Handler with bound arguments. - The bound handler provides the same io_service execution + The bound handler provides the same io_context execution guarantees as the original handler. */ template class bound_handler { -private: + // Can't friend partial specializations, + // so we just friend the whole thing. + template + friend struct boost::asio::associated_executor; + using args_type = std::tuple< typename std::decay::type...>; @@ -101,6 +105,9 @@ private: public: using result_type = void; + using allocator_type = + boost::asio::associated_allocator_t; + bound_handler(bound_handler&&) = default; bound_handler(bound_handler const&) = default; @@ -113,6 +120,20 @@ public: { } + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + friend + bool + asio_handler_is_continuation(bound_handler* h) + { + using boost::asio::asio_handler_is_continuation; + return asio_handler_is_continuation(std::addressof(h->h_)); + } + template void operator()(Values&&... values) @@ -132,48 +153,30 @@ public: std::forward(values)...), index_sequence_for()); } - - friend - void* - asio_handler_allocate( - std::size_t size, bound_handler* h) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(h->h_)); - } - - friend - void - asio_handler_deallocate( - void* p, std::size_t size, bound_handler* h) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(h->h_)); - } - - friend - bool - asio_handler_is_continuation(bound_handler* h) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation(std::addressof(h->h_)); - } - - template - friend - void - asio_handler_invoke(F&& f, bound_handler* h) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(h->h_)); - } }; } // detail } // beast + +namespace asio { +template +struct associated_executor< + beast::detail::bound_handler, Executor> +{ + using type = typename + associated_executor::type; + + static + type + get(beast::detail::bound_handler const& h, + Executor const& ex = Executor()) noexcept + { + return associated_executor< + Handler, Executor>::get(h.h_, ex); + } +}; +} // asio + } // boost namespace std { diff --git a/include/boost/beast/core/detail/buffers_ref.hpp b/include/boost/beast/core/detail/buffers_ref.hpp index e6a63622..e56a9764 100644 --- a/include/boost/beast/core/detail/buffers_ref.hpp +++ b/include/boost/beast/core/detail/buffers_ref.hpp @@ -11,6 +11,7 @@ #define BOOST_BEAST_DETAIL_BUFFERS_REF_HPP #include +#include namespace boost { namespace beast { @@ -23,11 +24,11 @@ class buffers_ref BufferSequence const* buffers_; public: - using value_type = - typename BufferSequence::value_type; + using const_iterator = typename + buffer_sequence_iterator::type; - using const_iterator = - typename BufferSequence::const_iterator; + using value_type = typename std::iterator_traits< + const_iterator>::value_type; buffers_ref(buffers_ref const&) = default; buffers_ref& operator=(buffers_ref const&) = default; @@ -41,13 +42,13 @@ public: const_iterator begin() const { - return buffers_->begin(); + return boost::asio::buffer_sequence_begin(*buffers_); } const_iterator end() const { - return buffers_->end(); + return boost::asio::buffer_sequence_end(*buffers_); } }; diff --git a/include/boost/beast/core/detail/ostream.hpp b/include/boost/beast/core/detail/ostream.hpp index 4128d1b2..8d6eb94f 100644 --- a/include/boost/beast/core/detail/ostream.hpp +++ b/include/boost/beast/core/detail/ostream.hpp @@ -10,8 +10,10 @@ #ifndef BOOST_BEAST_DETAIL_OSTREAM_HPP #define BOOST_BEAST_DETAIL_OSTREAM_HPP -#include +#include #include +#include +#include #include #include #include @@ -46,11 +48,10 @@ std::ostream& operator<<(std::ostream& os, buffers_helper const& v) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - for(boost::asio::const_buffer b : v.b_) - os.write(buffer_cast(b), - buffer_size(b)); + for(auto b : buffers_range(v.b_)) + os.write( + reinterpret_cast(b.data()), + b.size()); return os; } @@ -130,14 +131,12 @@ private: void prepare() { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - auto mbs = buf_.prepare( + auto bs = buf_.prepare( read_size_or_throw(buf_, max_size)); - auto const mb = *mbs.begin(); - auto const p = buffer_cast(mb); + auto const b = buffers_front(bs); + auto const p = reinterpret_cast(b.data()); this->setp(p, - p + buffer_size(mb) / sizeof(CharT) - 1); + p + b.size() / sizeof(CharT) - 1); } void @@ -211,14 +210,12 @@ private: void prepare() { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - auto mbs = buf_.prepare( + auto bs = buf_.prepare( read_size_or_throw(buf_, max_size)); - auto const mb = *mbs.begin(); - auto const p = buffer_cast(mb); + auto const b = buffers_front(bs); + auto const p = reinterpret_cast(b.data()); this->setp(p, - p + buffer_size(mb) / sizeof(CharT) - 1); + p + b.size() / sizeof(CharT) - 1); } void diff --git a/include/boost/beast/core/detail/type_traits.hpp b/include/boost/beast/core/detail/type_traits.hpp index 8401fa74..06fbda29 100644 --- a/include/boost/beast/core/detail/type_traits.hpp +++ b/include/boost/beast/core/detail/type_traits.hpp @@ -12,38 +12,12 @@ #include #include -#include #include #include #include #include #include -// A few workarounds to keep things working - -namespace boost { -namespace asio { - -// for has_get_io_service -class io_service; - -// for is_dynamic_buffer -template -class basic_streambuf; - -namespace detail { - -// for is_buffer_sequence -template -class consuming_buffers; - -} // detail - -} // asio -} // boost - -//------------------------------------------------------------------------------ - namespace boost { namespace beast { namespace detail { @@ -281,57 +255,17 @@ using ConstBufferSequence = using MutableBufferSequence = BufferSequence; -template -struct is_buffer_sequence : std::false_type {}; - -template -struct is_buffer_sequence(), - std::declval() = - std::declval().begin(), - std::declval() = - std::declval().end(), - (void)0)>> : std::integral_constant::value && -#if 0 - std::is_base_of::iterator_category>::value -#else - // workaround: - // boost::asio::detail::consuming_buffers::const_iterator - // is not bidirectional - std::is_base_of::iterator_category>::value -#endif - > -{ -}; - -#if 0 -// workaround: -// boost::asio::detail::consuming_buffers::const_iterator -// is not bidirectional -template -struct is_buffer_sequence< - boost::asio::detail::consuming_buffers> - : std::true_type -{ -}; -#endif - template struct is_all_const_buffer_sequence : std::integral_constant::value && + boost::asio::is_const_buffer_sequence::value && is_all_const_buffer_sequence::value> { }; -template -struct is_all_const_buffer_sequence - : is_buffer_sequence +template +struct is_all_const_buffer_sequence + : boost::asio::is_const_buffer_sequence { }; @@ -346,6 +280,14 @@ struct common_buffers_type boost::asio::const_buffer>::type; }; +template +struct buffer_sequence_iterator +{ + using type = decltype( + boost::asio::buffer_sequence_begin( + std::declval())); +}; + // Types that meet the requirements, // for use with std::declval only. struct StreamHandler @@ -356,6 +298,54 @@ struct StreamHandler using ReadHandler = StreamHandler; using WriteHandler = StreamHandler; +template +class buffers_range_adapter +{ + Buffers const& b_; + +public: + using value_type = typename std::conditional< + std::is_convertible::type>::value_type, + boost::asio::const_buffer>::value, + boost::asio::const_buffer, + boost::asio::mutable_buffer>::type; + + /* VFALCO This isn't right, because range-for will pick up the iterator's + value_type which might not be const_buffer or mutable_buffer. We + need to declare our own iterator wrapper that converts the underlying + iterator's value_type to const_buffer or mutable_buffer so that + range-for sees one of those types. + */ + using const_iterator = typename + buffer_sequence_iterator::type; + + explicit + buffers_range_adapter(Buffers const& b) + : b_(b) + { + } + + const_iterator + begin() const noexcept + { + return boost::asio::buffer_sequence_begin(b_); + } + + const_iterator + end() const noexcept + { + return boost::asio::buffer_sequence_end(b_); + } +}; + +template +buffers_range_adapter +buffers_range(Buffers const& buffers) +{ + return buffers_range_adapter{buffers}; +} + } // detail } // beast } // boost diff --git a/include/boost/beast/core/flat_buffer.hpp b/include/boost/beast/core/flat_buffer.hpp index 2fe2b2be..0ccd16bc 100644 --- a/include/boost/beast/core/flat_buffer.hpp +++ b/include/boost/beast/core/flat_buffer.hpp @@ -84,10 +84,10 @@ public: using allocator_type = Allocator; /// The type used to represent the input sequence as a list of buffers. - using const_buffers_type = boost::asio::mutable_buffers_1; + using const_buffers_type = boost::asio::mutable_buffer; /// The type used to represent the output sequence as a list of buffers. - using mutable_buffers_type = boost::asio::mutable_buffers_1; + using mutable_buffers_type = boost::asio::mutable_buffer; /// Destructor ~basic_flat_buffer(); diff --git a/include/boost/beast/core/flat_static_buffer.hpp b/include/boost/beast/core/flat_static_buffer.hpp index 8007011f..cfac9855 100644 --- a/include/boost/beast/core/flat_static_buffer.hpp +++ b/include/boost/beast/core/flat_static_buffer.hpp @@ -52,13 +52,13 @@ public: This buffer sequence is guaranteed to have length 1. */ - using const_buffers_type = boost::asio::mutable_buffers_1; + using const_buffers_type = boost::asio::mutable_buffer; /** The type used to represent the output sequence as a list of buffers. This buffer sequence is guaranteed to have length 1. */ - using mutable_buffers_type = boost::asio::mutable_buffers_1; + using mutable_buffers_type = boost::asio::mutable_buffer; /** Constructor diff --git a/include/boost/beast/core/handler_alloc.hpp b/include/boost/beast/core/handler_alloc.hpp deleted file mode 100644 index 896e88a4..00000000 --- a/include/boost/beast/core/handler_alloc.hpp +++ /dev/null @@ -1,162 +0,0 @@ -// -// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail 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) -// -// Official repository: https://github.com/boostorg/beast -// - -#ifndef BOOST_BEAST_HANDLER_ALLOC_HPP -#define BOOST_BEAST_HANDLER_ALLOC_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost { -namespace beast { - -// Guidance from -// http://howardhinnant.github.io/allocator_boilerplate.html - -/** An allocator that uses handler customizations. - - This allocator uses the handler customizations `asio_handler_allocate` - and `asio_handler_deallocate` to manage memory. It meets the requirements - of @b Allocator and can be used anywhere a `std::allocator` is - accepted. - - @tparam T The type of objects allocated by the allocator. - - @tparam Handler The type of handler. - - @note Memory allocated by this allocator must be freed before - the handler is invoked or undefined behavior results. This behavior - is described as the "deallocate before invocation" Asio guarantee. -*/ -#if BOOST_BEAST_DOXYGEN -template -class handler_alloc; -#else -template -class handler_alloc -{ -private: - // We want a partial template specialization as a friend - // but that isn't allowed so we friend all versions. This - // should produce a compile error if Handler is not - // constructible from H. - // - template - friend class handler_alloc; - - Handler& h_; - -public: - using value_type = T; - using is_always_equal = std::true_type; - using pointer = T*; - using reference = T&; - using const_pointer = T const*; - using const_reference = T const&; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - - template - struct rebind - { - using other = handler_alloc; - }; - - handler_alloc() = delete; - handler_alloc(handler_alloc&&) = default; - handler_alloc(handler_alloc const&) = default; - handler_alloc& operator=(handler_alloc&&) = default; - handler_alloc& operator=(handler_alloc const&) = default; - - /** Construct the allocator. - - A reference of the handler is stored. The handler must - remain valid for at least the lifetime of the allocator. - */ - explicit - handler_alloc(Handler& h) - : h_(h) - { - } - - /// Copy constructor - template - handler_alloc( - handler_alloc const& other) - : h_(other.h_) - { - } - - value_type* - allocate(size_type n) - { - auto const size = n * sizeof(T); - using boost::asio::asio_handler_allocate; - return static_cast( - asio_handler_allocate(size, std::addressof(h_))); - } - - void - deallocate(value_type* p, size_type n) - { - auto const size = n * sizeof(T); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate(p, size, std::addressof(h_)); - } - -//#if BOOST_WORKAROUND(BOOST_GCC, < 60000) // Works, but too coarse - -#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000 - template - void - construct(U* ptr, Args&&... args) - { - ::new((void*)ptr) U(std::forward(args)...); - } - - template - void - destroy(U* ptr) - { - ptr->~U(); - } -#endif - - template - friend - bool - operator==( - handler_alloc const&, - handler_alloc const&) - { - return true; - } - - template - friend - bool - operator!=( - handler_alloc const& lhs, - handler_alloc const& rhs) - { - return ! (lhs == rhs); - } -}; -#endif - -} // beast -} // boost - -#endif diff --git a/include/boost/beast/core/impl/buffered_read_stream.ipp b/include/boost/beast/core/impl/buffered_read_stream.ipp index 020a16c0..f88c2748 100644 --- a/include/boost/beast/core/impl/buffered_read_stream.ipp +++ b/include/boost/beast/core/impl/buffered_read_stream.ipp @@ -16,9 +16,10 @@ #include #include #include -#include +#include +#include #include -#include +#include #include namespace boost { @@ -48,28 +49,28 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(s_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, s_.get_executor()); + } + void operator()(error_code const& ec, std::size_t bytes_transferred); - friend - void* asio_handler_allocate( - std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(read_some_op* op) { @@ -77,14 +78,6 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, read_some_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke(f, std::addressof(op->h_)); - } }; template @@ -116,9 +109,9 @@ read_some_op::operator()( } step_ = 3; - s_.get_io_service().post( + return boost::asio::post( + s_.get_executor(), bind_handler(std::move(*this), ec, 0)); - return; case 1: // upcall @@ -153,11 +146,11 @@ auto buffered_read_stream:: async_write_some(ConstBufferSequence const& buffers, WriteHandler&& handler) -> - async_return_type + BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(error_code)) { static_assert(is_async_write_stream::value, "AsyncWriteStream requirements not met"); - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); static_assert(is_completion_handler::value, "SyncReadStream requirements not met"); - static_assert(is_mutable_buffer_sequence< + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); error_code ec; @@ -195,7 +188,7 @@ read_some(MutableBufferSequence const& buffers, { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(is_mutable_buffer_sequence< + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); using boost::asio::buffer_size; @@ -226,20 +219,20 @@ auto buffered_read_stream:: async_read_some(MutableBufferSequence const& buffers, ReadHandler&& handler) -> - async_return_type + BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void(error_code)) { static_assert(is_async_read_stream::value, - "Stream requirements not met"); - static_assert(is_mutable_buffer_sequence< + "AsyncReadStream requirements not met"); + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); if(buffer_.size() == 0 && capacity_ == 0) return next_layer_.async_read_some(buffers, std::forward(handler)); - async_completion init{handler}; - read_some_op>{ + read_some_op{ init.completion_handler, *this, buffers}( error_code{}, 0); return init.result.get(); diff --git a/include/boost/beast/core/impl/buffers_adapter.ipp b/include/boost/beast/core/impl/buffers_adapter.ipp index d88d6734..e16d2a9b 100644 --- a/include/boost/beast/core/impl/buffers_adapter.ipp +++ b/include/boost/beast/core/impl/buffers_adapter.ipp @@ -90,11 +90,10 @@ public: reference operator*() const { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return value_type{buffer_cast(*it_), - (ba_->out_ == ba_->bs_.end() || - it_ != ba_->out_) ? buffer_size(*it_) : ba_->out_pos_} + + value_type const b = *it_; + return value_type{b.data(), + (ba_->out_ == boost::asio::buffer_sequence_end(ba_->bs_) || + it_ != ba_->out_) ? b.size() : ba_->out_pos_} + (it_ == ba_->begin_ ? ba_->in_pos_ : 0); } @@ -233,11 +232,10 @@ public: reference operator*() const { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return value_type{buffer_cast(*it_), + value_type const b = *it_; + return value_type{b.data(), it_ == std::prev(ba_->end_) ? - ba_->out_end_ : buffer_size(*it_)} + + ba_->out_end_ : b.size()} + (it_ == ba_->out_ ? ba_->out_pos_ : 0); } @@ -288,7 +286,9 @@ private: template inline auto -buffers_adapter::mutable_buffers_type::begin() const -> +buffers_adapter:: +mutable_buffers_type:: +begin() const -> const_iterator { return const_iterator{*ba_, ba_->out_}; @@ -297,7 +297,9 @@ buffers_adapter::mutable_buffers_type::begin() const -> template inline auto -buffers_adapter::mutable_buffers_type::end() const -> +buffers_adapter:: +mutable_buffers_type:: +end() const -> const_iterator { return const_iterator{*ba_, ba_->end_}; @@ -309,9 +311,9 @@ template buffers_adapter::buffers_adapter( buffers_adapter&& other) : buffers_adapter(std::move(other), - std::distance(other.bs_.begin(), other.begin_), - std::distance(other.bs_.begin(), other.out_), - std::distance(other.bs_.begin(), other.end_)) + std::distance(boost::asio::buffer_sequence_begin(other.bs_), other.begin_), + std::distance(boost::asio::buffer_sequence_begin(other.bs_), other.out_), + std::distance(boost::asio::buffer_sequence_begin(other.bs_), other.end_)) { } @@ -319,9 +321,9 @@ template buffers_adapter::buffers_adapter( buffers_adapter const& other) : buffers_adapter(other, - std::distance(other.bs_.begin(), other.begin_), - std::distance(other.bs_.begin(), other.out_), - std::distance(other.bs_.begin(), other.end_)) + std::distance(boost::asio::buffer_sequence_begin(other.bs_), other.begin_), + std::distance(boost::asio::buffer_sequence_begin(other.bs_), other.out_), + std::distance(boost::asio::buffer_sequence_begin(other.bs_), other.end_)) { } @@ -331,15 +333,18 @@ buffers_adapter::operator=( buffers_adapter&& other) -> buffers_adapter& { auto const nbegin = std::distance( - other.bs_.begin(), other.begin_); + boost::asio::buffer_sequence_begin(other.bs_), + other.begin_); auto const nout = std::distance( - other.bs_.begin(), other.out_); + boost::asio::buffer_sequence_begin(other.bs_), + other.out_); auto const nend = std::distance( - other.bs_.begin(), other.end_); + boost::asio::buffer_sequence_begin(other.bs_), + other.end_); bs_ = std::move(other.bs_); - begin_ = std::next(bs_.begin(), nbegin); - out_ = std::next(bs_.begin(), nout); - end_ = std::next(bs_.begin(), nend); + begin_ = std::next(boost::asio::buffer_sequence_begin(bs_), nbegin); + out_ = std::next(boost::asio::buffer_sequence_begin(bs_), nout); + end_ = std::next(boost::asio::buffer_sequence_begin(bs_), nend); max_size_ = other.max_size_; in_pos_ = other.in_pos_; in_size_ = other.in_size_; @@ -354,15 +359,18 @@ buffers_adapter::operator=( buffers_adapter const& other) -> buffers_adapter& { auto const nbegin = std::distance( - other.bs_.begin(), other.begin_); + boost::asio::buffer_sequence_begin(other.bs_), + other.begin_); auto const nout = std::distance( - other.bs_.begin(), other.out_); + boost::asio::buffer_sequence_begin(other.bs_), + other.out_); auto const nend = std::distance( - other.bs_.begin(), other.end_); + boost::asio::buffer_sequence_begin(other.bs_), + other.end_); bs_ = other.bs_; - begin_ = std::next(bs_.begin(), nbegin); - out_ = std::next(bs_.begin(), nout); - end_ = std::next(bs_.begin(), nend); + begin_ = std::next(boost::asio::buffer_sequence_begin(bs_), nbegin); + out_ = std::next(boost::asio::buffer_sequence_begin(bs_), nout); + end_ = std::next(boost::asio::buffer_sequence_begin(bs_), nend); max_size_ = other.max_size_; in_pos_ = other.in_pos_; in_size_ = other.in_size_; @@ -375,9 +383,9 @@ template buffers_adapter::buffers_adapter( MutableBufferSequence const& bs) : bs_(bs) - , begin_(bs_.begin()) - , out_(bs_.begin()) - , end_(bs_.begin()) + , begin_(boost::asio::buffer_sequence_begin(bs_)) + , out_ (boost::asio::buffer_sequence_begin(bs_)) + , end_ (boost::asio::buffer_sequence_begin(bs_)) , max_size_(boost::asio::buffer_size(bs_)) { } @@ -389,13 +397,14 @@ buffers_adapter::prepare(std::size_t n) -> { using boost::asio::buffer_size; end_ = out_; - if(end_ != bs_.end()) + if(end_ != boost::asio::buffer_sequence_end(bs_)) { auto size = buffer_size(*end_) - out_pos_; if(n > size) { n -= size; - while(++end_ != bs_.end()) + while(++end_ != + boost::asio::buffer_sequence_end(bs_)) { size = buffer_size(*end_); if(n < size) diff --git a/include/boost/beast/core/impl/buffers_cat.ipp b/include/boost/beast/core/impl/buffers_cat.ipp index bed9606a..d92d5523 100644 --- a/include/boost/beast/core/impl/buffers_cat.ipp +++ b/include/boost/beast/core/impl/buffers_cat.ipp @@ -30,7 +30,7 @@ class buffers_cat_view::const_iterator std::size_t n_; std::tuple const* bn_; std::array()> buf_; + typename detail::buffer_sequence_iterator::type...>()> buf_; friend class buffers_cat_view; @@ -38,8 +38,8 @@ class buffers_cat_view::const_iterator using C = std::integral_constant; template - using iter_t = typename std::tuple_element< - I, std::tuple>::type::const_iterator; + using iter_t = typename detail::buffer_sequence_iterator< + typename std::tuple_element>::type>::type; template iter_t& @@ -123,7 +123,8 @@ private: { n_ = I; new(&buf_[0]) iter_t{ - std::get(*bn_).begin()}; + boost::asio::buffer_sequence_begin( + std::get(*bn_))}; return; } construct(C{}); @@ -138,7 +139,8 @@ private: { n_ = I; new(&buf_[0]) iter_t{ - std::get(*bn_).end()}; + boost::asio::buffer_sequence_end( + std::get(*bn_))}; return; } BOOST_THROW_EXCEPTION(std::logic_error{ @@ -154,7 +156,8 @@ private: { n_ = I; new(&buf_[0]) iter_t{ - std::get(*bn_).end()}; + boost::asio::buffer_sequence_end( + std::get(*bn_))}; return; } rconstruct(C{}); @@ -268,7 +271,8 @@ private: if(n_ == I) { if(++iter() != - std::get(*bn_).end()) + boost::asio::buffer_sequence_end( + std::get(*bn_))) return; using Iter = iter_t; iter().~Iter(); @@ -292,7 +296,9 @@ private: { if(n_ == I) { - if(iter() != std::get(*bn_).begin()) + if(iter() != + boost::asio::buffer_sequence_begin( + std::get(*bn_))) { --iter(); return; @@ -309,7 +315,9 @@ private: decrement(C<0> const&) { auto constexpr I = 0; - if(iter() != std::get(*bn_).begin()) + if(iter() != + boost::asio::buffer_sequence_begin( + std::get(*bn_))) { --iter(); return; diff --git a/include/boost/beast/core/impl/buffers_prefix.ipp b/include/boost/beast/core/impl/buffers_prefix.ipp index f40f7f56..0bb92cc3 100644 --- a/include/boost/beast/core/impl/buffers_prefix.ipp +++ b/include/boost/beast/core/impl/buffers_prefix.ipp @@ -27,10 +27,8 @@ boost::asio::const_buffer buffers_prefix(std::size_t size, boost::asio::const_buffer buffer) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return {buffer_cast(buffer), - (std::min)(size, buffer_size(buffer))}; + return {buffer.data(), + (std::min)(size, buffer.size())}; } inline @@ -38,10 +36,8 @@ boost::asio::mutable_buffer buffers_prefix(std::size_t size, boost::asio::mutable_buffer buffer) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return {buffer_cast(buffer), - (std::min)(size, buffer_size(buffer))}; + return {buffer.data(), + (std::min)(size, buffer.size())}; } } // detail @@ -138,7 +134,7 @@ private: std::false_type) : b_(&b) , remain_(b_->size_) - , it_(b_->bs_.begin()) + , it_(boost::asio::buffer_sequence_begin(b_->bs_)) { } }; @@ -149,7 +145,7 @@ buffers_prefix_view:: setup(std::size_t size) { size_ = 0; - end_ = bs_.begin(); + end_ = boost::asio::buffer_sequence_begin(bs_); auto const last = bs_.end(); while(end_ != last) { @@ -170,7 +166,8 @@ buffers_prefix_view:: buffers_prefix_view(buffers_prefix_view&& other) : buffers_prefix_view(std::move(other), std::distance( - other.bs_.begin(), other.end_)) + boost::asio::buffer_sequence_begin(other.bs_), + other.end_)) { } @@ -179,7 +176,8 @@ buffers_prefix_view:: buffers_prefix_view(buffers_prefix_view const& other) : buffers_prefix_view(other, std::distance( - other.bs_.begin(), other.end_)) + boost::asio::buffer_sequence_begin(other.bs_), + other.end_)) { } @@ -190,10 +188,13 @@ operator=(buffers_prefix_view&& other) -> buffers_prefix_view& { auto const dist = std::distance( - other.bs_.begin(), other.end_); + boost::asio::buffer_sequence_begin(other.bs_), + other.end_); bs_ = std::move(other.bs_); size_ = other.size_; - end_ = std::next(bs_.begin(), dist); + end_ = std::next( + boost::asio::buffer_sequence_begin(bs_), + dist); return *this; } @@ -204,10 +205,13 @@ operator=(buffers_prefix_view const& other) -> buffers_prefix_view& { auto const dist = std::distance( - other.bs_.begin(), other.end_); + boost::asio::buffer_sequence_begin(other.bs_), + other.end_); bs_ = other.bs_; size_ = other.size_; - end_ = std::next(bs_.begin(), dist); + end_ = std::next( + boost::asio::buffer_sequence_begin(bs_), + dist); return *this; } diff --git a/include/boost/beast/core/impl/buffers_suffix.ipp b/include/boost/beast/core/impl/buffers_suffix.ipp index f46e79ae..6356d63e 100644 --- a/include/boost/beast/core/impl/buffers_suffix.ipp +++ b/include/boost/beast/core/impl/buffers_suffix.ipp @@ -25,8 +25,8 @@ class buffers_suffix::const_iterator { friend class buffers_suffix; - using iter_type = - typename Buffers::const_iterator; + using iter_type = typename + detail::buffer_sequence_iterator::type; iter_type it_; buffers_suffix const* b_ = nullptr; @@ -117,7 +117,7 @@ private: template buffers_suffix:: buffers_suffix() - : begin_(bs_.begin()) + : begin_(boost::asio::buffer_sequence_begin(bs_)) { } @@ -126,7 +126,8 @@ buffers_suffix:: buffers_suffix(buffers_suffix&& other) : buffers_suffix(std::move(other), std::distance( - other.bs_.begin(), other.begin_)) + boost::asio::buffer_sequence_begin( + other.bs_), other.begin_)) { } @@ -135,7 +136,8 @@ buffers_suffix:: buffers_suffix(buffers_suffix const& other) : buffers_suffix(other, std::distance( - other.bs_.begin(), other.begin_)) + boost::asio::buffer_sequence_begin( + other.bs_), other.begin_)) { } @@ -143,11 +145,11 @@ template buffers_suffix:: buffers_suffix(Buffers const& bs) : bs_(bs) - , begin_(bs_.begin()) + , begin_(boost::asio::buffer_sequence_begin(bs_)) { static_assert( - is_const_buffer_sequence::value|| - is_mutable_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value|| + boost::asio::is_mutable_buffer_sequence::value, "BufferSequence requirements not met"); } @@ -156,7 +158,7 @@ template buffers_suffix:: buffers_suffix(boost::in_place_init_t, Args&&... args) : bs_(std::forward(args)...) - , begin_(bs_.begin()) + , begin_(boost::asio::buffer_sequence_begin(bs_)) { static_assert(sizeof...(Args) > 0, "Missing constructor arguments"); @@ -172,9 +174,12 @@ operator=(buffers_suffix&& other) -> buffers_suffix& { auto const dist = std::distance( - other.bs_.begin(), other.begin_); + boost::asio::buffer_sequence_begin(other.bs_), + other.begin_); bs_ = std::move(other.bs_); - begin_ = std::next(bs_.begin(), dist); + begin_ = std::next( + boost::asio::buffer_sequence_begin(bs_), + dist); skip_ = other.skip_; return *this; } @@ -186,9 +191,11 @@ operator=(buffers_suffix const& other) -> buffers_suffix& { auto const dist = std::distance( - other.bs_.begin(), other.begin_); + boost::asio::buffer_sequence_begin(other.bs_), + other.begin_); bs_ = other.bs_; - begin_ = std::next(bs_.begin(), dist); + begin_ = std::next( + boost::asio::buffer_sequence_begin(bs_), dist); skip_ = other.skip_; return *this; } @@ -210,7 +217,8 @@ buffers_suffix:: end() const -> const_iterator { - return const_iterator{*this, bs_.end()}; + return const_iterator{*this, + boost::asio::buffer_sequence_end(bs_)}; } template @@ -219,7 +227,9 @@ buffers_suffix:: consume(std::size_t amount) { using boost::asio::buffer_size; - for(;amount > 0 && begin_ != bs_.end(); ++begin_) + auto const end = + boost::asio::buffer_sequence_end(bs_); + for(;amount > 0 && begin_ != end; ++begin_) { auto const len = buffer_size(*begin_) - skip_; diff --git a/include/boost/beast/core/impl/handler_ptr.ipp b/include/boost/beast/core/impl/handler_ptr.ipp index aab5d8ce..15a159a8 100644 --- a/include/boost/beast/core/impl/handler_ptr.ipp +++ b/include/boost/beast/core/impl/handler_ptr.ipp @@ -10,9 +10,7 @@ #ifndef BOOST_BEAST_IMPL_HANDLER_PTR_HPP #define BOOST_BEAST_IMPL_HANDLER_PTR_HPP -#include -#include -#include +#include #include #include @@ -27,10 +25,11 @@ P(DeducedHandler&& h, Args&&... args) : n(1) , handler(std::forward(h)) { - using boost::asio::asio_handler_allocate; - t = reinterpret_cast( - asio_handler_allocate( - sizeof(T), std::addressof(handler))); + typename std::allocator_traits< + boost::asio::associated_allocator_t>:: + template rebind_alloc alloc{ + boost::asio::get_associated_allocator(handler)}; + t = std::allocator_traits::allocate(alloc, 1); try { t = new(t) T{handler, @@ -38,9 +37,8 @@ P(DeducedHandler&& h, Args&&... args) } catch(...) { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - t, sizeof(T), std::addressof(handler)); + std::allocator_traits< + decltype(alloc)>::deallocate(alloc, t, 1); throw; } } @@ -56,9 +54,13 @@ handler_ptr:: if(p_->t) { p_->t->~T(); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p_->t, sizeof(T), std::addressof(p_->handler)); + typename std::allocator_traits< + boost::asio::associated_allocator_t>:: + template rebind_alloc alloc{ + boost::asio::get_associated_allocator( + p_->handler)}; + std::allocator_traits< + decltype(alloc)>::deallocate(alloc, p_->t, 1); } delete p_; } @@ -108,9 +110,13 @@ release_handler() -> BOOST_ASSERT(p_); BOOST_ASSERT(p_->t); p_->t->~T(); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p_->t, sizeof(T), std::addressof(p_->handler)); + typename std::allocator_traits< + boost::asio::associated_allocator_t>:: + template rebind_alloc alloc{ + boost::asio::get_associated_allocator( + p_->handler)}; + std::allocator_traits< + decltype(alloc)>::deallocate(alloc, p_->t, 1); p_->t = nullptr; return std::move(p_->handler); } @@ -124,9 +130,13 @@ invoke(Args&&... args) BOOST_ASSERT(p_); BOOST_ASSERT(p_->t); p_->t->~T(); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p_->t, sizeof(T), std::addressof(p_->handler)); + typename std::allocator_traits< + boost::asio::associated_allocator_t>:: + template rebind_alloc alloc{ + boost::asio::get_associated_allocator( + p_->handler)}; + std::allocator_traits< + decltype(alloc)>::deallocate(alloc, p_->t, 1); p_->t = nullptr; p_->handler(std::forward(args)...); } diff --git a/include/boost/beast/core/impl/read_size.ipp b/include/boost/beast/core/impl/read_size.ipp index 9e72ffed..d29eeaa7 100644 --- a/include/boost/beast/core/impl/read_size.ipp +++ b/include/boost/beast/core/impl/read_size.ipp @@ -38,7 +38,8 @@ std::size_t read_size(DynamicBuffer& buffer, std::size_t max_size, std::false_type) { - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); BOOST_ASSERT(max_size >= 1); auto const size = buffer.size(); diff --git a/include/boost/beast/core/ostream.hpp b/include/boost/beast/core/ostream.hpp index 50aca179..1f00289b 100644 --- a/include/boost/beast/core/ostream.hpp +++ b/include/boost/beast/core/ostream.hpp @@ -49,7 +49,7 @@ detail::buffers_helper #endif buffers(ConstBufferSequence const& b) { - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); return detail::buffers_helper< @@ -90,7 +90,8 @@ detail::ostream_helper< #endif ostream(DynamicBuffer& buffer) { - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); return detail::ostream_helper< DynamicBuffer, char, std::char_traits, diff --git a/include/boost/beast/core/type_traits.hpp b/include/boost/beast/core/type_traits.hpp index 269f3da6..d622e0e8 100644 --- a/include/boost/beast/core/type_traits.hpp +++ b/include/boost/beast/core/type_traits.hpp @@ -19,153 +19,6 @@ namespace boost { namespace beast { -//------------------------------------------------------------------------------ -// -// Buffer concepts -// -//------------------------------------------------------------------------------ - -/** Determine if `T` meets the requirements of @b ConstBufferSequence. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(ConstBufferSequence const& buffers) - { - static_assert(is_const_buffer_sequence::value, - "ConstBufferSequence requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(ConstBufferSequence const& buffers); - @endcode -*/ -template -#if BOOST_BEAST_DOXYGEN -struct is_const_buffer_sequence : std::integral_constant -#else -struct is_const_buffer_sequence : - detail::is_buffer_sequence -#endif -{ -}; - -/** Determine if `T` meets the requirements of @b MutableBufferSequence. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(MutableBufferSequence const& buffers) - { - static_assert(is_const_buffer_sequence::value, - "MutableBufferSequence requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(MutableBufferSequence const& buffers); - @endcode -*/ -template -#if BOOST_BEAST_DOXYGEN -struct is_mutable_buffer_sequence : std::integral_constant -#else -struct is_mutable_buffer_sequence : - detail::is_buffer_sequence -#endif -{ -}; - -/** Determine if `T` meets the requirements of @b DynamicBuffer. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(DynamicBuffer& buffer) - { - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(DynamicBuffer const& buffer); - @endcode -*/ -#if BOOST_BEAST_DOXYGEN -template -struct is_dynamic_buffer : std::integral_constant {}; -#else -template -struct is_dynamic_buffer : std::false_type {}; - -template -struct is_dynamic_buffer() = - std::declval().size(), - std::declval() = - std::declval().max_size(), - std::declval() = - std::declval().capacity(), - std::declval().commit(std::declval()), - std::declval().consume(std::declval()), - (void)0)> > : std::integral_constant::value && - is_mutable_buffer_sequence< - typename T::mutable_buffers_type>::value && - std::is_same().data())>::value && - std::is_same().prepare( - std::declval()))>::value - > -{ -}; - -// Special case for Boost.Asio which doesn't adhere to -// net-ts but still provides a read_size_helper so things work -template -struct is_dynamic_buffer< - boost::asio::basic_streambuf> : std::true_type -{ -}; -#endif - //------------------------------------------------------------------------------ // // Handler concepts @@ -209,7 +62,7 @@ using is_completion_handler = std::integral_constant void maybe_hello(T& t, std::true_type) { - t.get_io_service().post([]{ std::cout << "Hello, world!" << std::endl; }); + boost::asio::post( + t.get_executor(), + [] + { + std::cout << "Hello, world!" << std::endl; + }); } template void maybe_hello(T&, std::false_type) { - // T does not have get_io_service + // T does not have get_executor } template void maybe_hello(T& t) { - maybe_hello(t, has_get_io_service{}); + maybe_hello(t, has_get_executor{}); } @endcode @@ -244,24 +102,23 @@ using is_completion_handler = std::integral_constant::value, - "Missing get_io_service member"); + static_assert(has_get_executor::value, "Missing get_executor member"); @endcode */ #if BOOST_BEAST_DOXYGEN template -struct has_get_io_service : std::integral_constant{}; +struct has_get_executor : std::integral_constant{}; #else template -struct has_get_io_service : std::false_type {}; +struct has_get_executor : std::false_type {}; template -struct has_get_io_service( - std::declval().get_io_service()), +struct has_get_executor().get_executor(), (void)0)>> : std::true_type {}; #endif @@ -350,7 +207,7 @@ struct is_async_read_stream(), std::declval()), (void)0)>> : std::integral_constant::value + has_get_executor::value > {}; #endif @@ -394,7 +251,7 @@ struct is_async_write_stream(), std::declval()), (void)0)>> : std::integral_constant::value + has_get_executor::value > {}; #endif @@ -439,12 +296,10 @@ struct is_sync_read_stream() = std::declval().read_some( std::declval(), std::declval()), - (void)0)>> : std::integral_constant::value - > {}; + (void)0)>> : std::true_type {}; #endif -/** Determine if `T` meets the requirements of @b SyncWriterStream. +/** Determine if `T` meets the requirements of @b SyncWriteStream. Metafunctions are used to perform compile time checking of template types. This type will be `std::true_type` if `T` meets the requirements, @@ -485,9 +340,7 @@ struct is_sync_write_stream() = std::declval().write_some( std::declval(), std::declval()), - (void)0)>> : std::integral_constant::value - > {}; + (void)0)>> : std::true_type {}; #endif /** Determine if `T` meets the requirements of @b AsyncStream. diff --git a/include/boost/beast/http/basic_dynamic_body.hpp b/include/boost/beast/http/basic_dynamic_body.hpp index fb4c92fa..6bc8fa91 100644 --- a/include/boost/beast/http/basic_dynamic_body.hpp +++ b/include/boost/beast/http/basic_dynamic_body.hpp @@ -32,7 +32,8 @@ namespace http { template struct basic_dynamic_body { - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); /** The type of container used for the body diff --git a/include/boost/beast/http/basic_file_body.hpp b/include/boost/beast/http/basic_file_body.hpp index 8767a71e..22fb91fc 100644 --- a/include/boost/beast/http/basic_file_body.hpp +++ b/include/boost/beast/http/basic_file_body.hpp @@ -143,7 +143,13 @@ public: /** Set the open file - This function is used to set the open + This function is used to set the open file. Any previously + set file will be closed. + + @param file The file to set. The file must be open or else + an error occurs + + @param ec Set to the error, if any occurred */ void reset(File&& file, error_code& ec); @@ -229,7 +235,7 @@ public: // The type of buffer sequence returned by `get`. // using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; // Constructor. // @@ -485,13 +491,13 @@ put(ConstBufferSequence const& buffers, error_code& ec) // Loop over all the buffers in the sequence, // and write each one to the file. - for(boost::asio::const_buffer buffer : buffers) + for(auto it = boost::asio::buffer_sequence_begin(buffers); + it != boost::asio::buffer_sequence_end(buffers); ++it) { // Write this buffer to the file + boost::asio::const_buffer buffer = *it; nwritten += body_.file_.write( - boost::asio::buffer_cast(buffer), - boost::asio::buffer_size(buffer), - ec); + buffer.data(), buffer.size(), ec); if(ec) return nwritten; } diff --git a/include/boost/beast/http/basic_parser.hpp b/include/boost/beast/http/basic_parser.hpp index b4b138a9..fdc002f8 100644 --- a/include/boost/beast/http/basic_parser.hpp +++ b/include/boost/beast/http/basic_parser.hpp @@ -515,7 +515,7 @@ public: #if ! BOOST_BEAST_DOXYGEN std::size_t - put(boost::asio::const_buffers_1 const& buffer, + put(boost::asio::const_buffer const& buffer, error_code& ec); #endif diff --git a/include/boost/beast/http/buffer_body.hpp b/include/boost/beast/http/buffer_body.hpp index 43032cda..82b2b4b4 100644 --- a/include/boost/beast/http/buffer_body.hpp +++ b/include/boost/beast/http/buffer_body.hpp @@ -105,7 +105,7 @@ struct buffer_body public: using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template explicit diff --git a/include/boost/beast/http/chunk_encode.hpp b/include/boost/beast/http/chunk_encode.hpp index 2afc099b..4994765f 100644 --- a/include/boost/beast/http/chunk_encode.hpp +++ b/include/boost/beast/http/chunk_encode.hpp @@ -106,7 +106,7 @@ class chunk_header { using view_type = buffers_cat_view< detail::chunk_size, // chunk-size - boost::asio::const_buffers_1, // chunk-extensions + boost::asio::const_buffer, // chunk-extensions chunk_crlf>; // CRLF std::shared_ptr< @@ -285,7 +285,7 @@ class chunk_body { using view_type = buffers_cat_view< detail::chunk_size, // chunk-size - boost::asio::const_buffers_1, // chunk-extensions + boost::asio::const_buffer, // chunk-extensions chunk_crlf, // CRLF ConstBufferSequence, // chunk-body chunk_crlf>; // CRLF @@ -459,7 +459,7 @@ class chunk_last { static_assert( is_fields::value || - is_const_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value, "Trailer requirements not met"); using buffers_type = typename diff --git a/include/boost/beast/http/detail/chunk_encode.hpp b/include/boost/beast/http/detail/chunk_encode.hpp index ad1c223c..f0f3c858 100644 --- a/include/boost/beast/http/detail/chunk_encode.hpp +++ b/include/boost/beast/http/detail/chunk_encode.hpp @@ -25,7 +25,7 @@ namespace detail { struct chunk_extensions { virtual ~chunk_extensions() = default; - virtual boost::asio::const_buffers_1 str() = 0; + virtual boost::asio::const_buffer str() = 0; }; template @@ -43,7 +43,7 @@ struct chunk_extensions_impl : chunk_extensions { } - boost::asio::const_buffers_1 + boost::asio::const_buffer str() override { auto const s = ext_.str(); @@ -151,7 +151,7 @@ prepare(std::size_t n) /// Returns a buffer sequence holding a CRLF for chunk encoding inline -boost::asio::const_buffers_1 +boost::asio::const_buffer chunk_crlf() { return {"\r\n", 2}; @@ -159,7 +159,7 @@ chunk_crlf() /// Returns a buffer sequence holding a final chunk header inline -boost::asio::const_buffers_1 +boost::asio::const_buffer chunk_last() { return {"0\r\n", 3}; diff --git a/include/boost/beast/http/impl/basic_parser.ipp b/include/boost/beast/http/impl/basic_parser.ipp index 73810639..2837095c 100644 --- a/include/boost/beast/http/impl/basic_parser.ipp +++ b/include/boost/beast/http/impl/basic_parser.ipp @@ -103,14 +103,13 @@ basic_parser:: put(ConstBufferSequence const& buffers, error_code& ec) { - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); - using boost::asio::buffer_cast; using boost::asio::buffer_copy; using boost::asio::buffer_size; - auto const p = buffers.begin(); - auto const last = buffers.end(); + auto const p = boost::asio::buffer_sequence_begin(buffers); + auto const last = boost::asio::buffer_sequence_end(buffers); if(p == last) { ec.assign(0, ec.category()); @@ -119,10 +118,7 @@ put(ConstBufferSequence const& buffers, if(std::next(p) == last) { // single buffer - auto const b = *p; - return put(boost::asio::const_buffers_1{ - buffer_cast(b), - buffer_size(b)}, ec); + return put(boost::asio::const_buffer(*p), ec); } auto const size = buffer_size(buffers); if(size <= max_stack_buffer) @@ -136,21 +132,21 @@ put(ConstBufferSequence const& buffers, // flatten buffer_copy(boost::asio::buffer( buf_.get(), buf_len_), buffers); - return put(boost::asio::const_buffers_1{ + return put(boost::asio::const_buffer{ buf_.get(), buf_len_}, ec); } template std::size_t basic_parser:: -put(boost::asio::const_buffers_1 const& buffer, +put(boost::asio::const_buffer const& buffer, error_code& ec) { BOOST_ASSERT(state_ != state::complete); using boost::asio::buffer_size; - auto p = boost::asio::buffer_cast< - char const*>(*buffer.begin()); - auto n = buffer_size(*buffer.begin()); + auto p = reinterpret_cast< + char const*>(buffer.data()); + auto n = buffer.size(); auto const p0 = p; auto const p1 = p0 + n; ec.assign(0, ec.category()); @@ -324,7 +320,7 @@ put_from_stack(std::size_t size, using boost::asio::buffer; using boost::asio::buffer_copy; buffer_copy(buffer(buf, sizeof(buf)), buffers); - return put(boost::asio::const_buffers_1{ + return put(boost::asio::const_buffer{ buf, size}, ec); } diff --git a/include/boost/beast/http/impl/chunk_encode.ipp b/include/boost/beast/http/impl/chunk_encode.ipp index 461c895a..ddb96881 100644 --- a/include/boost/beast/http/impl/chunk_encode.ipp +++ b/include/boost/beast/http/impl/chunk_encode.ipp @@ -24,7 +24,7 @@ chunk_header:: chunk_header(std::size_t size) : view_( size, - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}) { BOOST_ASSERT(size > 0); @@ -37,7 +37,7 @@ chunk_header( string_view extensions) : view_( size, - boost::asio::const_buffers_1{ + boost::asio::const_buffer{ extensions.data(), extensions.size()}, chunk_crlf{}) { @@ -90,7 +90,7 @@ chunk_body:: chunk_body(ConstBufferSequence const& buffers) : view_( boost::asio::buffer_size(buffers), - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}, buffers, chunk_crlf{}) @@ -104,7 +104,7 @@ chunk_body( string_view extensions) : view_( boost::asio::buffer_size(buffers), - boost::asio::const_buffers_1{ + boost::asio::const_buffer{ extensions.data(), extensions.size()}, chunk_crlf{}, buffers, diff --git a/include/boost/beast/http/impl/fields.ipp b/include/boost/beast/http/impl/fields.ipp index 6d78382a..64bf7f14 100644 --- a/include/boost/beast/http/impl/fields.ipp +++ b/include/boost/beast/http/impl/fields.ipp @@ -143,9 +143,9 @@ public: }; using view_type = buffers_cat_view< - boost::asio::const_buffers_1, - boost::asio::const_buffers_1, - boost::asio::const_buffers_1, + boost::asio::const_buffer, + boost::asio::const_buffer, + boost::asio::const_buffer, field_range, chunk_crlf>; @@ -178,9 +178,9 @@ reader(basic_fields const& f) : f_(f) { view_.emplace( - boost::asio::const_buffers_1{nullptr, 0}, - boost::asio::const_buffers_1{nullptr, 0}, - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, field_range(f_.list_.begin(), f_.list_.end()), chunk_crlf()); } @@ -218,11 +218,11 @@ reader(basic_fields const& f, buf_[10]= '\n'; view_.emplace( - boost::asio::const_buffers_1{sv.data(), sv.size()}, - boost::asio::const_buffers_1{ + boost::asio::const_buffer{sv.data(), sv.size()}, + boost::asio::const_buffer{ f_.target_or_reason_.data(), f_.target_or_reason_.size()}, - boost::asio::const_buffers_1{buf_, 11}, + boost::asio::const_buffer{buf_, 11}, field_range(f_.list_.begin(), f_.list_.end()), chunk_crlf()); } @@ -260,9 +260,9 @@ reader(basic_fields const& f, sv = obsolete_reason(static_cast(code)); view_.emplace( - boost::asio::const_buffers_1{buf_, 13}, - boost::asio::const_buffers_1{sv.data(), sv.size()}, - boost::asio::const_buffers_1{"\r\n", 2}, + boost::asio::const_buffer{buf_, 13}, + boost::asio::const_buffer{sv.data(), sv.size()}, + boost::asio::const_buffer{"\r\n", 2}, field_range(f_.list_.begin(), f_.list_.end()), chunk_crlf{}); } diff --git a/include/boost/beast/http/impl/file_body_win32.ipp b/include/boost/beast/http/impl/file_body_win32.ipp index 1ef2472e..9c7ae6be 100644 --- a/include/boost/beast/http/impl/file_body_win32.ipp +++ b/include/boost/beast/http/impl/file_body_win32.ipp @@ -12,15 +12,15 @@ #if BOOST_BEAST_USE_WIN32_FILE -#include #include #include #include #include +#include +#include +#include #include -#include #include -#include #include #include #include @@ -120,7 +120,7 @@ struct basic_file_body public: using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template reader(message error_code& ec) { std::size_t nwritten = 0; - for(boost::asio::const_buffer buffer : buffers) + for(auto buffer : beast::detail::buffers_range(buffers)) { nwritten += body_.file_.write( - boost::asio::buffer_cast(buffer), - boost::asio::buffer_size(buffer), - ec); + buffer.data(), buffer.size(), ec); if(ec) return nwritten; } @@ -360,6 +358,24 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(sock_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, sock_.get_executor()); + } + void operator()(); @@ -368,24 +384,6 @@ public: error_code ec, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate( - std::size_t size, write_some_win32_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_some_win32_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(write_some_win32_op* op) { @@ -393,15 +391,6 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, write_some_win32_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } }; template< @@ -431,7 +420,7 @@ operator()() r.body_.last_ - r.pos_, sr_.limit())), 2147483646); boost::asio::windows::overlapped_ptr overlapped{ - sock_.get_io_service(), *this}; + sock_.get_executor().context(), *this}; auto& ov = *overlapped.get(); ov.Offset = lowPart(r.pos_); ov.OffsetHigh = highPart(r.pos_); @@ -567,21 +556,20 @@ template< class Protocol, bool isRequest, class Fields, class WriteHandler> -async_return_type< - WriteHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write_some( boost::asio::basic_stream_socket& sock, serializer, Fields>& sr, WriteHandler&& handler) { - async_completion init{handler}; detail::write_some_win32_op< Protocol, - handler_type, + BOOST_ASIO_HANDLER_TYPE(WriteHandler, + void(error_code, std::size_t)), isRequest, Fields>{ init.completion_handler, sock, sr}(); return init.result.get(); diff --git a/include/boost/beast/http/impl/read.ipp b/include/boost/beast/http/impl/read.ipp index de5f963c..7a639266 100644 --- a/include/boost/beast/http/impl/read.ipp +++ b/include/boost/beast/http/impl/read.ipp @@ -18,9 +18,10 @@ #include #include #include -#include +#include +#include #include -#include +#include #include #include #include @@ -61,29 +62,29 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(s_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, s_.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate( - std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(read_some_op* op) { @@ -92,15 +93,6 @@ public: asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, read_some_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } }; template= 2) goto upcall; state_ = 3; - return s_.get_io_service().post( + return boost::asio::post( + s_.get_executor(), bind_handler(std::move(*this), ec, 0)); case 3: @@ -231,29 +224,29 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(s_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, s_.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate( - std::size_t size, read_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(read_op* op) { @@ -262,15 +255,6 @@ public: asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, read_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } }; template; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(d_.handler()); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(d_->s.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + d_.handler(), d_->s.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate( - std::size_t size, read_msg_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_msg_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - friend bool asio_handler_is_continuation(read_msg_op* op) { @@ -392,15 +377,6 @@ public: asio_handler_is_continuation( std::addressof(op->d_.handler())); } - - template - friend - void asio_handler_invoke(Function&& f, read_msg_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } }; template::value, "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); BOOST_ASSERT(! parser.is_done()); error_code ec; @@ -482,7 +459,8 @@ read_some( { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); BOOST_ASSERT(! parser.is_done()); std::size_t bytes_transferred = 0; @@ -541,8 +519,8 @@ template< class DynamicBuffer, bool isRequest, class Derived, class ReadHandler> -async_return_type< - ReadHandler, void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read_some( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -551,13 +529,14 @@ async_read_some( { static_assert(is_async_read_stream::value, "AsyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); BOOST_ASSERT(! parser.is_done()); - async_completion init{handler}; + boost::asio::async_completion init{handler}; detail::read_some_op>{ + DynamicBuffer, isRequest, Derived, BOOST_ASIO_HANDLER_TYPE( + ReadHandler, void(error_code, std::size_t))>{ init.completion_handler, stream, buffer, parser}(); return init.result.get(); } @@ -576,7 +555,8 @@ read_header( { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); error_code ec; auto const bytes_transferred = @@ -599,7 +579,8 @@ read_header( { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); parser.eager(false); if(parser.is_header_done()) @@ -624,9 +605,8 @@ template< class DynamicBuffer, bool isRequest, class Derived, class ReadHandler> -async_return_type< - ReadHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read_header( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -635,14 +615,15 @@ async_read_header( { static_assert(is_async_read_stream::value, "AsyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); parser.eager(false); - async_completion init{handler}; detail::read_op>{ + BOOST_ASIO_HANDLER_TYPE(ReadHandler, void(error_code, std::size_t))>{ init.completion_handler, stream, buffer, parser}(); return init.result.get(); } @@ -661,7 +642,8 @@ read( { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); error_code ec; auto const bytes_transferred = @@ -684,7 +666,8 @@ read( { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); parser.eager(true); if(parser.is_done()) @@ -709,9 +692,8 @@ template< class DynamicBuffer, bool isRequest, class Derived, class ReadHandler> -async_return_type< - ReadHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -720,15 +702,16 @@ async_read( { static_assert(is_async_read_stream::value, "AsyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); parser.eager(true); - async_completion< + boost::asio::async_completion< ReadHandler, void(error_code, std::size_t)> init{handler}; detail::read_op>{ + BOOST_ASIO_HANDLER_TYPE(ReadHandler, void(error_code, std::size_t))>{ init.completion_handler, stream, buffer, parser}(); return init.result.get(); } @@ -747,7 +730,8 @@ read( { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); static_assert(is_body::value, "Body requirements not met"); @@ -774,7 +758,8 @@ read( { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); static_assert(is_body::value, "Body requirements not met"); @@ -795,9 +780,8 @@ template< class DynamicBuffer, bool isRequest, class Body, class Allocator, class ReadHandler> -async_return_type< - ReadHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -806,21 +790,22 @@ async_read( { static_assert(is_async_read_stream::value, "AsyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); static_assert(is_body::value, "Body requirements not met"); static_assert(is_body_writer::value, "BodyWriter requirements not met"); - async_completion< + boost::asio::async_completion< ReadHandler, void(error_code, std::size_t)> init{handler}; detail::read_msg_op< AsyncReadStream, DynamicBuffer, isRequest, Body, Allocator, - handler_type>{ + BOOST_ASIO_HANDLER_TYPE( + ReadHandler, void(error_code, std::size_t))>{ init.completion_handler, stream, buffer, msg}(); return init.result.get(); } diff --git a/include/boost/beast/http/impl/serializer.ipp b/include/boost/beast/http/impl/serializer.ipp index c6d0be86..ccbaa248 100644 --- a/include/boost/beast/http/impl/serializer.ipp +++ b/include/boost/beast/http/impl/serializer.ipp @@ -166,12 +166,12 @@ next(error_code& ec, Visit&& visit) boost::in_place_init, frd_->get(), buffer_size(result->first), - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}, result->first, chunk_crlf{}, detail::chunk_last(), - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}); goto go_all_c; } @@ -179,7 +179,7 @@ next(error_code& ec, Visit&& visit) boost::in_place_init, frd_->get(), buffer_size(result->first), - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}, result->first, chunk_crlf{}); @@ -216,19 +216,19 @@ next(error_code& ec, Visit&& visit) v_.template emplace<6>( boost::in_place_init, buffer_size(result->first), - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}, result->first, chunk_crlf{}, detail::chunk_last(), - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}); goto go_body_final_c; } v_.template emplace<5>( boost::in_place_init, buffer_size(result->first), - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}, result->first, chunk_crlf{}); @@ -257,7 +257,7 @@ next(error_code& ec, Visit&& visit) v_.template emplace<8>( boost::in_place_init, detail::chunk_last(), - boost::asio::const_buffers_1{nullptr, 0}, + boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}); s_ = do_final_c + 1; BOOST_BEAST_FALLTHROUGH; diff --git a/include/boost/beast/http/impl/write.ipp b/include/boost/beast/http/impl/write.ipp index 617f4cde..792045fc 100644 --- a/include/boost/beast/http/impl/write.ipp +++ b/include/boost/beast/http/impl/write.ipp @@ -16,9 +16,10 @@ #include #include #include -#include +#include +#include #include -#include +#include #include #include #include @@ -77,6 +78,24 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(s_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, s_.get_executor()); + } + void operator()(); @@ -85,24 +104,6 @@ public: error_code ec, std::size_t bytes_transferred); - friend - void* asio_handler_allocate( - std::size_t size, write_some_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_some_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(write_some_op* op) { @@ -110,14 +111,6 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, write_some_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke(f, std::addressof(op->h_)); - } }; template< @@ -136,7 +129,8 @@ operator()() if(ec) { BOOST_ASSERT(! f.invoked); - return s_.get_io_service().post( + return boost::asio::post( + s_.get_executor(), bind_handler(std::move(*this), ec, 0)); } if(f.invoked) @@ -148,7 +142,8 @@ operator()() // What else could it be? BOOST_ASSERT(sr_.is_done()); } - return s_.get_io_service().post( + return boost::asio::post( + s_.get_executor(), bind_handler(std::move(*this), ec, 0)); } @@ -218,29 +213,29 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(s_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, s_.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate( - std::size_t size, write_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(write_op* op) { @@ -249,15 +244,6 @@ public: asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, write_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } }; template< @@ -278,7 +264,8 @@ operator()( if(Predicate{}(sr_)) { state_ = 1; - return s_.get_io_service().post( + return boost::asio::post( + s_.get_executor(), bind_handler(std::move(*this), ec, 0)); } state_ = 2; @@ -338,6 +325,24 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(d_.handler()); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(d_->s.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + d_.handler(), d_->s.get_executor()); + } + void operator()(); @@ -345,24 +350,6 @@ public: operator()( error_code ec, std::size_t bytes_transferred); - friend - void* asio_handler_allocate( - std::size_t size, write_msg_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_msg_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - friend bool asio_handler_is_continuation(write_msg_op* op) { @@ -370,15 +357,6 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } - - template - friend - void asio_handler_invoke(Function&& f, write_msg_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } }; template -async_return_type< - WriteHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write_some( AsyncWriteStream& stream, serializer& sr, WriteHandler&& handler) { - async_completion< + boost::asio::async_completion< WriteHandler, void(error_code, std::size_t)> init{handler}; detail::write_some_op< AsyncWriteStream, - handler_type, + BOOST_ASIO_HANDLER_TYPE(WriteHandler, + void(error_code, std::size_t)), isRequest, Body, Fields>{ init.completion_handler, stream, sr}(); return init.result.get(); @@ -551,9 +528,8 @@ template< class AsyncWriteStream, bool isRequest, class Body, class Fields, class WriteHandler> -async_return_type< - WriteHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write_some( AsyncWriteStream& stream, serializer& sr, @@ -635,9 +611,8 @@ template< class AsyncWriteStream, bool isRequest, class Body, class Fields, class WriteHandler> -async_return_type< - WriteHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write_header( AsyncWriteStream& stream, serializer& sr, @@ -651,13 +626,13 @@ async_write_header( static_assert(is_body_reader::value, "BodyReader requirements not met"); sr.split(true); - async_completion< + boost::asio::async_completion< WriteHandler, void(error_code, std::size_t)> init{handler}; detail::write_op< AsyncWriteStream, - handler_type, + BOOST_ASIO_HANDLER_TYPE(WriteHandler, + void(error_code, std::size_t)), detail::serializer_is_header_done, isRequest, Body, Fields>{ init.completion_handler, stream, sr}(); @@ -713,9 +688,8 @@ template< class AsyncWriteStream, bool isRequest, class Body, class Fields, class WriteHandler> -async_return_type< - WriteHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write( AsyncWriteStream& stream, serializer& sr, @@ -729,13 +703,13 @@ async_write( static_assert(is_body_reader::value, "BodyReader requirements not met"); sr.split(false); - async_completion< + boost::asio::async_completion< WriteHandler, void(error_code, std::size_t)> init{handler}; detail::write_op< AsyncWriteStream, - handler_type, + BOOST_ASIO_HANDLER_TYPE(WriteHandler, + void(error_code, std::size_t)), detail::serializer_is_done, isRequest, Body, Fields>{ init.completion_handler, stream, sr}(); @@ -789,9 +763,8 @@ template< class AsyncWriteStream, bool isRequest, class Body, class Fields, class WriteHandler> -async_return_type< - WriteHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write( AsyncWriteStream& stream, message& msg, @@ -804,13 +777,13 @@ async_write( "Body requirements not met"); static_assert(is_body_reader::value, "BodyReader requirements not met"); - async_completion< + boost::asio::async_completion< WriteHandler, void(error_code, std::size_t)> init{handler}; detail::write_msg_op< AsyncWriteStream, - handler_type, + BOOST_ASIO_HANDLER_TYPE(WriteHandler, + void(error_code, std::size_t)), isRequest, Body, Fields>{ init.completion_handler, stream, msg}(); return init.result.get(); @@ -843,17 +816,13 @@ public: if(os_.fail()) return; std::size_t bytes_transferred = 0; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - for(auto it = buffers.begin(); - it != buffers.end(); ++it) + for(auto b : buffers_range(buffers)) { - boost::asio::const_buffer b = *it; - auto const n = buffer_size(b); - os_.write(buffer_cast(b), n); + os_.write(reinterpret_cast( + b.data()), b.size()); if(os_.fail()) return; - bytes_transferred += n; + bytes_transferred += b.size(); } sr_.consume(bytes_transferred); } diff --git a/include/boost/beast/http/read.hpp b/include/boost/beast/http/read.hpp index 58b7cf9f..96f2fff0 100644 --- a/include/boost/beast/http/read.hpp +++ b/include/boost/beast/http/read.hpp @@ -11,10 +11,10 @@ #define BOOST_BEAST_HTTP_READ_HPP #include -#include #include #include #include +#include namespace boost { namespace beast { @@ -185,7 +185,7 @@ read_some( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. The completion handler will receive as a parameter the number of octets processed from the dynamic buffer. The octets should @@ -197,12 +197,8 @@ template< class DynamicBuffer, bool isRequest, class Derived, class ReadHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - ReadHandler, void(error_code, std::size_t)> -#endif +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read_some( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -375,7 +371,7 @@ read_header( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. @note The implementation will call @ref basic_parser::eager with the value `false` on the parser passed in. @@ -385,12 +381,8 @@ template< class DynamicBuffer, bool isRequest, class Derived, class ReadHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - ReadHandler, void(error_code, std::size_t)> -#endif +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read_header( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -563,7 +555,7 @@ read( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. @note The implementation will call @ref basic_parser::eager with the value `true` on the parser passed in. @@ -573,13 +565,8 @@ template< class DynamicBuffer, bool isRequest, class Derived, class ReadHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - ReadHandler, - void(error_code, std::size_t)> -#endif +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read( AsyncReadStream& stream, DynamicBuffer& buffer, @@ -754,20 +741,15 @@ read( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class AsyncReadStream, class DynamicBuffer, bool isRequest, class Body, class Allocator, class ReadHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - ReadHandler, - void(error_code, std::size_t)> -#endif +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read( AsyncReadStream& stream, DynamicBuffer& buffer, diff --git a/include/boost/beast/http/serializer.hpp b/include/boost/beast/http/serializer.hpp index e375f163..2ba86608 100644 --- a/include/boost/beast/http/serializer.hpp +++ b/include/boost/beast/http/serializer.hpp @@ -132,7 +132,7 @@ private: using cb4_t = buffers_suffix>; // crlf @@ -140,7 +140,7 @@ private: using cb5_t = buffers_suffix>; // crlf @@ -148,30 +148,30 @@ private: using cb6_t = buffers_suffix>; // crlf using pcb6_t = buffers_prefix_view; using cb7_t = buffers_suffix>; // crlf using pcb7_t = buffers_prefix_view; using cb8_t = buffers_suffix>; // crlf using pcb8_t = buffers_prefix_view; diff --git a/include/boost/beast/http/span_body.hpp b/include/boost/beast/http/span_body.hpp index a2dd81f9..9af836af 100644 --- a/include/boost/beast/http/span_body.hpp +++ b/include/boost/beast/http/span_body.hpp @@ -72,7 +72,7 @@ public: public: using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template explicit diff --git a/include/boost/beast/http/string_body.hpp b/include/boost/beast/http/string_body.hpp index e8a38ce1..28a337b7 100644 --- a/include/boost/beast/http/string_body.hpp +++ b/include/boost/beast/http/string_body.hpp @@ -80,7 +80,7 @@ public: public: using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template explicit @@ -172,13 +172,11 @@ public: } ec.assign(0, ec.category()); CharT* dest = &body_[size]; - for(boost::asio::const_buffer b : buffers) + for(auto b : beast::detail::buffers_range(buffers)) { - using boost::asio::buffer_cast; - auto const len = boost::asio::buffer_size(b); - Traits::copy( - dest, buffer_cast(b), len); - dest += len; + Traits::copy(dest, reinterpret_cast< + CharT const*>(b.data()), b.size()); + dest += b.size(); } return extra; } diff --git a/include/boost/beast/http/type_traits.hpp b/include/boost/beast/http/type_traits.hpp index 1328c7f3..7b2fd4d7 100644 --- a/include/boost/beast/http/type_traits.hpp +++ b/include/boost/beast/http/type_traits.hpp @@ -88,7 +88,7 @@ struct is_body_reader>&>() = std::declval().get(std::declval()), (void)0)>> : std::integral_constant::value && std::is_constructible&>::value && @@ -131,7 +131,7 @@ struct is_body_writer()), std::declval() = std::declval().put( - std::declval(), + std::declval(), std::declval()), std::declval().finish( std::declval()), diff --git a/include/boost/beast/http/vector_body.hpp b/include/boost/beast/http/vector_body.hpp index 8e5948dd..91378917 100644 --- a/include/boost/beast/http/vector_body.hpp +++ b/include/boost/beast/http/vector_body.hpp @@ -75,7 +75,7 @@ public: public: using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template explicit diff --git a/include/boost/beast/http/write.hpp b/include/boost/beast/http/write.hpp index 964555b6..befc0fe7 100644 --- a/include/boost/beast/http/write.hpp +++ b/include/boost/beast/http/write.hpp @@ -18,8 +18,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -158,7 +158,7 @@ write_some( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. @see @ref serializer */ @@ -166,13 +166,8 @@ template< class AsyncWriteStream, bool isRequest, class Body, class Fields, class WriteHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - WriteHandler, - void(error_code, std::size_t)> -#endif +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write_some( AsyncWriteStream& stream, serializer& sr, @@ -284,7 +279,7 @@ write_header( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. @note The implementation will call @ref serializer::split with the value `true` on the serializer passed in. @@ -295,13 +290,8 @@ template< class AsyncWriteStream, bool isRequest, class Body, class Fields, class WriteHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - WriteHandler, - void(error_code, std::size_t)> -#endif +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write_header( AsyncWriteStream& stream, serializer& sr, @@ -407,7 +397,7 @@ write( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. @see @ref serializer */ @@ -415,13 +405,8 @@ template< class AsyncWriteStream, bool isRequest, class Body, class Fields, class WriteHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - WriteHandler, - void(error_code, std::size_t)> -#endif +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write( AsyncWriteStream& stream, serializer& sr, @@ -527,7 +512,7 @@ write( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. @see @ref message */ @@ -535,9 +520,8 @@ template< class AsyncWriteStream, bool isRequest, class Body, class Fields, class WriteHandler> -async_return_type< - WriteHandler, - void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write( AsyncWriteStream& stream, message& msg, diff --git a/include/boost/beast/websocket/detail/frame.hpp b/include/boost/beast/websocket/detail/frame.hpp index 19b0f46e..95080aee 100644 --- a/include/boost/beast/websocket/detail/frame.hpp +++ b/include/boost/beast/websocket/detail/frame.hpp @@ -233,10 +233,10 @@ read_ping(ping_data& data, Buffers const& bs) { using boost::asio::buffer_copy; using boost::asio::buffer_size; - using boost::asio::mutable_buffers_1; + using boost::asio::mutable_buffer; BOOST_ASSERT(buffer_size(bs) <= data.max_size()); data.resize(buffer_size(bs)); - buffer_copy(mutable_buffers_1{ + buffer_copy(mutable_buffer{ data.data(), data.size()}, bs); } diff --git a/include/boost/beast/websocket/detail/mask.hpp b/include/boost/beast/websocket/detail/mask.hpp index a6386f95..e5729aa2 100644 --- a/include/boost/beast/websocket/detail/mask.hpp +++ b/include/boost/beast/websocket/detail/mask.hpp @@ -122,10 +122,8 @@ mask_inplace_fast( boost::asio::mutable_buffer const& b, std::uint32_t& key) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - auto n = buffer_size(b); - auto p = buffer_cast(b); + auto n = b.size(); + auto p = reinterpret_cast(b.data()); if(n >= sizeof(key)) { // Bring p to 4-byte alignment @@ -177,10 +175,8 @@ mask_inplace_fast( boost::asio::mutable_buffer const& b, std::uint64_t& key) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - auto n = buffer_size(b); - auto p = buffer_cast(b); + auto n = b.size(); + auto p = reinterpret_cast(b.data()); if(n >= sizeof(key)) { // Bring p to 8-byte alignment diff --git a/include/boost/beast/websocket/detail/pausation.hpp b/include/boost/beast/websocket/detail/pausation.hpp index 82f7a854..74aa9dfa 100644 --- a/include/boost/beast/websocket/detail/pausation.hpp +++ b/include/boost/beast/websocket/detail/pausation.hpp @@ -11,6 +11,7 @@ #define BOOST_BEAST_WEBSOCKET_DETAIL_PAUSATION_HPP #include +#include #include #include #include @@ -88,13 +89,16 @@ class pausation public: ~saved_op() { - using boost::asio::asio_handler_deallocate; if(op_) { Op op(std::move(*op_)); op_->~Op(); - asio_handler_deallocate(op_, - sizeof(*op_), std::addressof(op.handler())); + typename std::allocator_traits< + boost::asio::associated_allocator_t>:: + template rebind_alloc alloc{ + boost::asio::get_associated_allocator(op)}; + std::allocator_traits< + decltype(alloc)>::deallocate(alloc, op_, 1); } } @@ -115,10 +119,13 @@ class pausation explicit saved_op(Op&& op) { - using boost::asio::asio_handler_allocate; - op_ = new(asio_handler_allocate(sizeof(Op), - std::addressof(op.handler()))) Op{ - std::move(op)}; + typename std::allocator_traits< + boost::asio::associated_allocator_t>:: + template rebind_alloc alloc{ + boost::asio::get_associated_allocator(op)}; + auto const p = std::allocator_traits< + decltype(alloc)>::allocate(alloc, 1); + op_ = new(p) Op{std::move(op)}; } void @@ -126,9 +133,12 @@ class pausation { BOOST_ASSERT(op_); Op op{std::move(*op_)}; - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate(op_, - sizeof(*op_), std::addressof(op_->handler())); + typename std::allocator_traits< + boost::asio::associated_allocator_t>:: + template rebind_alloc alloc{ + boost::asio::get_associated_allocator(op)}; + std::allocator_traits< + decltype(alloc)>::deallocate(alloc, op_, 1); op_ = nullptr; op(); } diff --git a/include/boost/beast/websocket/detail/pmd_extension.hpp b/include/boost/beast/websocket/detail/pmd_extension.hpp index 6342eb14..4aab7f50 100644 --- a/include/boost/beast/websocket/detail/pmd_extension.hpp +++ b/include/boost/beast/websocket/detail/pmd_extension.hpp @@ -371,33 +371,31 @@ deflate( error_code& ec) { using boost::asio::buffer; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - BOOST_ASSERT(buffer_size(out) >= 6); + BOOST_ASSERT(out.size() >= 6); zlib::z_params zs; zs.avail_in = 0; zs.next_in = nullptr; - zs.avail_out = buffer_size(out); - zs.next_out = buffer_cast(out); - for(boost::asio::const_buffer in : cb) + zs.avail_out = out.size(); + zs.next_out = out.data(); + for(auto in : beast::detail::buffers_range(cb)) { - zs.avail_in = buffer_size(in); + zs.avail_in = in.size(); if(zs.avail_in == 0) continue; - zs.next_in = buffer_cast(in); + zs.next_in = in.data(); zo.write(zs, zlib::Flush::none, ec); if(ec) { if(ec != zlib::error::need_buffers) return false; BOOST_ASSERT(zs.avail_out == 0); - BOOST_ASSERT(zs.total_out == buffer_size(out)); + BOOST_ASSERT(zs.total_out == out.size()); ec.assign(0, ec.category()); break; } if(zs.avail_out == 0) { - BOOST_ASSERT(zs.total_out == buffer_size(out)); + BOOST_ASSERT(zs.total_out == out.size()); break; } BOOST_ASSERT(zs.avail_in == 0); @@ -406,7 +404,7 @@ deflate( cb.consume(zs.total_in); if(zs.avail_out > 0 && fin) { - auto const remain = buffer_size(cb); + auto const remain = boost::asio::buffer_size(cb); if(remain == 0) { // Inspired by Mark Adler @@ -426,15 +424,13 @@ deflate( BOOST_ASSERT(! ec); // remove flush marker zs.total_out -= 4; - out = buffer( - buffer_cast(out), zs.total_out); + out = buffer(out.data(), zs.total_out); return false; } } } ec.assign(0, ec.category()); - out = buffer( - buffer_cast(out), zs.total_out); + out = buffer(out.data(), zs.total_out); return true; } diff --git a/include/boost/beast/websocket/detail/utf8_checker.hpp b/include/boost/beast/websocket/detail/utf8_checker.hpp index 9d1b9ce9..08f35a6e 100644 --- a/include/boost/beast/websocket/detail/utf8_checker.hpp +++ b/include/boost/beast/websocket/detail/utf8_checker.hpp @@ -86,13 +86,12 @@ bool utf8_checker_t<_>:: write(ConstBufferSequence const& bs) { - static_assert(is_const_buffer_sequence::value, + static_assert(boost::asio::is_const_buffer_sequence::value, "ConstBufferSequence requirements not met"); - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - for(boost::asio::const_buffer b : bs) - if(! write(buffer_cast(b), - buffer_size(b))) + for(auto b : beast::detail::buffers_range(bs)) + if(! write(reinterpret_cast< + std::uint8_t const*>(b.data()), + b.size())) return false; return true; } diff --git a/include/boost/beast/websocket/impl/accept.ipp b/include/boost/beast/websocket/impl/accept.ipp index c701e685..c6429382 100644 --- a/include/boost/beast/websocket/impl/accept.ipp +++ b/include/boost/beast/websocket/impl/accept.ipp @@ -20,9 +20,10 @@ #include #include #include -#include +#include +#include #include -#include +#include #include #include #include @@ -67,28 +68,28 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(d_.handler()); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(d_->ws.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + d_.handler(), d_->ws.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate( - std::size_t size, response_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, response_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - friend bool asio_handler_is_continuation(response_op* op) { @@ -96,15 +97,6 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } - - template - friend - void asio_handler_invoke(Function&& f, response_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } }; template @@ -171,6 +163,24 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(d_.handler()); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(d_->ws.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + d_.handler(), d_->ws.get_executor()); + } + template void run(Buffers const& buffers); @@ -178,24 +188,6 @@ public: error_code ec = {}, std::size_t bytes_used = 0); - friend - void* asio_handler_allocate( - std::size_t size, accept_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, accept_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - friend bool asio_handler_is_continuation(accept_op* op) { @@ -203,15 +195,6 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } - - template - friend - void asio_handler_invoke(Function&& f, accept_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } }; template @@ -256,7 +239,8 @@ operator()(error_code ec, std::size_t) if(ec) { BOOST_ASIO_CORO_YIELD - d.ws.get_io_service().post( + boost::asio::post( + d.ws.get_executor(), bind_handler(std::move(*this), ec)); } else @@ -269,7 +253,7 @@ operator()(error_code ec, std::size_t) ec = error::closed; if(! ec) { - // Arguments from our step must be + // Arguments from our state must be // moved to the stack before releasing // the handler. auto& ws = d.ws; @@ -359,7 +343,7 @@ accept(ConstBufferSequence const& buffers) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); error_code ec; @@ -381,7 +365,7 @@ accept_ex( { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); static_assert(detail::is_ResponseDecorator< @@ -403,7 +387,7 @@ accept( { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); using boost::asio::buffer_copy; @@ -440,10 +424,10 @@ accept_ex( { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); using boost::asio::buffer_copy; @@ -544,22 +528,24 @@ accept_ex( template template< class AcceptHandler> -async_return_type +BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code)) stream:: async_accept( AcceptHandler&& handler) { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - async_completion init{handler}; reset(); accept_op< decltype(&default_decorate_res), - handler_type>{ - init.completion_handler, - *this, - &default_decorate_res}({}); + BOOST_ASIO_HANDLER_TYPE( + AcceptHandler, void(error_code))>{ + init.completion_handler, + *this, + &default_decorate_res}({}); return init.result.get(); } @@ -567,7 +553,8 @@ template template< class ResponseDecorator, class AcceptHandler> -async_return_type +BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code)) stream:: async_accept_ex( ResponseDecorator const& decorator, @@ -578,15 +565,16 @@ async_accept_ex( static_assert(detail::is_ResponseDecorator< ResponseDecorator>::value, "ResponseDecorator requirements not met"); - async_completion init{handler}; reset(); accept_op< ResponseDecorator, - handler_type>{ - init.completion_handler, - *this, - decorator}({}); + BOOST_ASIO_HANDLER_TYPE( + AcceptHandler, void(error_code))>{ + init.completion_handler, + *this, + decorator}({}); return init.result.get(); } @@ -596,7 +584,8 @@ template< class AcceptHandler> typename std::enable_if< ! http::detail::is_header::value, - async_return_type>::type + BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code))>::type stream:: async_accept( ConstBufferSequence const& buffers, @@ -604,18 +593,19 @@ async_accept( { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); - async_completion init{handler}; reset(); accept_op< decltype(&default_decorate_res), - handler_type>{ - init.completion_handler, - *this, - &default_decorate_res}.run(buffers); + BOOST_ASIO_HANDLER_TYPE( + AcceptHandler, void(error_code))>{ + init.completion_handler, + *this, + &default_decorate_res}.run(buffers); return init.result.get(); } @@ -626,7 +616,8 @@ template< class AcceptHandler> typename std::enable_if< ! http::detail::is_header::value, - async_return_type>::type + BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code))>::type stream:: async_accept_ex( ConstBufferSequence const& buffers, @@ -635,21 +626,22 @@ async_accept_ex( { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); static_assert(detail::is_ResponseDecorator< ResponseDecorator>::value, "ResponseDecorator requirements not met"); - async_completion init{handler}; reset(); accept_op< ResponseDecorator, - handler_type>{ - init.completion_handler, - *this, - decorator}.run(buffers); + BOOST_ASIO_HANDLER_TYPE( + AcceptHandler, void(error_code))>{ + init.completion_handler, + *this, + decorator}.run(buffers); return init.result.get(); } @@ -657,7 +649,8 @@ template template< class Body, class Allocator, class AcceptHandler> -async_return_type +BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code)) stream:: async_accept( http::request> const& req, @@ -665,16 +658,17 @@ async_accept( { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - async_completion init{handler}; reset(); using boost::asio::asio_handler_is_continuation; response_op< - handler_type>{ - init.completion_handler, - *this, - req, - &default_decorate_res}(); + BOOST_ASIO_HANDLER_TYPE( + AcceptHandler, void(error_code))>{ + init.completion_handler, + *this, + req, + &default_decorate_res}(); return init.result.get(); } @@ -683,7 +677,8 @@ template< class Body, class Allocator, class ResponseDecorator, class AcceptHandler> -async_return_type +BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code)) stream:: async_accept_ex( http::request> const& req, @@ -695,16 +690,17 @@ async_accept_ex( static_assert(detail::is_ResponseDecorator< ResponseDecorator>::value, "ResponseDecorator requirements not met"); - async_completion init{handler}; reset(); using boost::asio::asio_handler_is_continuation; response_op< - handler_type>{ - init.completion_handler, - *this, - req, - decorator}(); + BOOST_ASIO_HANDLER_TYPE( + AcceptHandler, void(error_code))>{ + init.completion_handler, + *this, + req, + decorator}(); return init.result.get(); } diff --git a/include/boost/beast/websocket/impl/close.ipp b/include/boost/beast/websocket/impl/close.ipp index c4ce0f28..c5559b20 100644 --- a/include/boost/beast/websocket/impl/close.ipp +++ b/include/boost/beast/websocket/impl/close.ipp @@ -15,10 +15,11 @@ #include #include #include +#include +#include #include -#include #include -#include +#include #include #include @@ -74,30 +75,30 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(d_.handler()); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(d_->ws.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + d_.handler(), d_->ws.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0, bool cont = true); - friend - void* asio_handler_allocate( - std::size_t size, close_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, close_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - friend bool asio_handler_is_continuation(close_op* op) { @@ -105,15 +106,6 @@ public: return op->d_->cont || asio_handler_is_continuation( std::addressof(op->d_.handler())); } - - template - friend - void asio_handler_invoke(Function&& f, close_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } }; template @@ -155,7 +147,8 @@ operator()( // Resume BOOST_ASIO_CORO_YIELD - d.ws.get_io_service().post(std::move(*this)); + boost::asio::post( + d.ws.get_executor(), std::move(*this)); BOOST_ASSERT(d.ws.wr_block_ == d.tok); // Make sure the stream is open @@ -205,7 +198,8 @@ operator()( // Resume BOOST_ASIO_CORO_YIELD - d.ws.get_io_service().post(std::move(*this)); + boost::asio::post( + d.ws.get_executor(), std::move(*this)); BOOST_ASSERT(d.ws.rd_block_ == d.tok); // Make sure the stream is open @@ -322,7 +316,8 @@ operator()( if(! d.cont) { auto& ws = d.ws; - return ws.stream_.get_io_service().post( + return boost::asio::post( + ws.stream_.get_executor(), bind_handler(d_.release_handler(), ec)); } d_.invoke(ec); @@ -440,17 +435,17 @@ close(close_reason const& cr, error_code& ec) template template -async_return_type< - CloseHandler, void(error_code)> +BOOST_ASIO_INITFN_RESULT_TYPE( + CloseHandler, void(error_code)) stream:: async_close(close_reason const& cr, CloseHandler&& handler) { static_assert(is_async_stream::value, "AsyncStream requirements not met"); - async_completion init{handler}; - close_op>{ + close_op{ init.completion_handler, *this, cr}( {}, 0, false); return init.result.get(); diff --git a/include/boost/beast/websocket/impl/handshake.ipp b/include/boost/beast/websocket/impl/handshake.ipp index 2e708f21..dc22bfb3 100644 --- a/include/boost/beast/websocket/impl/handshake.ipp +++ b/include/boost/beast/websocket/impl/handshake.ipp @@ -17,10 +17,10 @@ #include #include #include +#include +#include #include -#include #include -#include #include #include #include @@ -75,29 +75,29 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(d_.handler()); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(d_->ws.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + d_.handler(), d_->ws.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_used = 0); - friend - void* asio_handler_allocate( - std::size_t size, handshake_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, handshake_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - friend bool asio_handler_is_continuation(handshake_op* op) { @@ -105,15 +105,6 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } - - template - friend - void asio_handler_invoke(Function&& f, handshake_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } }; template @@ -156,8 +147,8 @@ operator()(error_code ec, std::size_t) template template -async_return_type< - HandshakeHandler, void(error_code)> +BOOST_ASIO_INITFN_RESULT_TYPE( + HandshakeHandler, void(error_code)) stream:: async_handshake(string_view host, string_view target, @@ -165,10 +156,10 @@ async_handshake(string_view host, { static_assert(is_async_stream::value, "AsyncStream requirements not met"); - async_completion init{handler}; - handshake_op>{ + handshake_op{ init.completion_handler, *this, nullptr, host, target, &default_decorate_req}(); return init.result.get(); @@ -176,8 +167,8 @@ async_handshake(string_view host, template template -async_return_type< - HandshakeHandler, void(error_code)> +BOOST_ASIO_INITFN_RESULT_TYPE( + HandshakeHandler, void(error_code)) stream:: async_handshake(response_type& res, string_view host, @@ -186,10 +177,10 @@ async_handshake(response_type& res, { static_assert(is_async_stream::value, "AsyncStream requirements not met"); - async_completion init{handler}; - handshake_op>{ + handshake_op{ init.completion_handler, *this, &res, host, target, &default_decorate_req}(); return init.result.get(); @@ -197,8 +188,8 @@ async_handshake(response_type& res, template template -async_return_type< - HandshakeHandler, void(error_code)> +BOOST_ASIO_INITFN_RESULT_TYPE( + HandshakeHandler, void(error_code)) stream:: async_handshake_ex(string_view host, string_view target, @@ -210,10 +201,10 @@ async_handshake_ex(string_view host, static_assert(detail::is_RequestDecorator< RequestDecorator>::value, "RequestDecorator requirements not met"); - async_completion init{handler}; - handshake_op>{ + handshake_op{ init.completion_handler, *this, nullptr, host, target, decorator}(); return init.result.get(); @@ -221,8 +212,8 @@ async_handshake_ex(string_view host, template template -async_return_type< - HandshakeHandler, void(error_code)> +BOOST_ASIO_INITFN_RESULT_TYPE( + HandshakeHandler, void(error_code)) stream:: async_handshake_ex(response_type& res, string_view host, @@ -235,10 +226,10 @@ async_handshake_ex(response_type& res, static_assert(detail::is_RequestDecorator< RequestDecorator>::value, "RequestDecorator requirements not met"); - async_completion init{handler}; - handshake_op>{ + handshake_op{ init.completion_handler, *this, &res, host, target, decorator}(); return init.result.get(); diff --git a/include/boost/beast/websocket/impl/ping.ipp b/include/boost/beast/websocket/impl/ping.ipp index 8ff65280..77d85dde 100644 --- a/include/boost/beast/websocket/impl/ping.ipp +++ b/include/boost/beast/websocket/impl/ping.ipp @@ -15,10 +15,11 @@ #include #include #include +#include +#include #include -#include #include -#include +#include #include #include @@ -74,28 +75,28 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(d_.handler()); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(d_->ws.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + d_.handler(), d_->ws.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate( - std::size_t size, ping_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, ping_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - friend bool asio_handler_is_continuation(ping_op* op) { @@ -103,15 +104,6 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } - - template - friend - void asio_handler_invoke(Function&& f, ping_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } }; template @@ -134,7 +126,8 @@ operator()(error_code ec, std::size_t) if(! d.ws.check_open(ec)) { BOOST_ASIO_CORO_YIELD - d.ws.get_io_service().post( + boost::asio::post( + d.ws.get_executor(), bind_handler(std::move(*this), ec)); goto upcall; } @@ -152,7 +145,8 @@ operator()(error_code ec, std::size_t) // Resume BOOST_ASIO_CORO_YIELD - d.ws.get_io_service().post(std::move(*this)); + boost::asio::post( + d.ws.get_executor(), std::move(*this)); BOOST_ASSERT(d.ws.wr_block_ == d.tok); // Make sure the stream is open @@ -235,17 +229,17 @@ pong(ping_data const& payload, error_code& ec) template template -async_return_type< - WriteHandler, void(error_code)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code)) stream:: async_ping(ping_data const& payload, WriteHandler&& handler) { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - async_completion init{handler}; - ping_op>{ + ping_op{ init.completion_handler, *this, detail::opcode::ping, payload}(); return init.result.get(); @@ -253,17 +247,17 @@ async_ping(ping_data const& payload, WriteHandler&& handler) template template -async_return_type< - WriteHandler, void(error_code)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code)) stream:: async_pong(ping_data const& payload, WriteHandler&& handler) { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - async_completion init{handler}; - ping_op>{ + ping_op{ init.completion_handler, *this, detail::opcode::pong, payload}(); return init.result.get(); diff --git a/include/boost/beast/websocket/impl/read.ipp b/include/boost/beast/websocket/impl/read.ipp index 6b13d037..9cd0a9c9 100644 --- a/include/boost/beast/websocket/impl/read.ipp +++ b/include/boost/beast/websocket/impl/read.ipp @@ -18,10 +18,11 @@ #include #include #include +#include +#include #include -#include #include -#include +#include #include #include #include @@ -74,6 +75,24 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(ws_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, ws_.get_executor()); + } + Handler& handler() { @@ -85,24 +104,6 @@ public: std::size_t bytes_transferred = 0, bool cont = true); - friend - void* asio_handler_allocate( - std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate(p, size, - std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(read_some_op* op) { @@ -110,15 +111,6 @@ public: return op->cont_ || asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, read_some_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } }; template @@ -133,7 +125,6 @@ operator()( { using beast::detail::clamp; using boost::asio::buffer; - using boost::asio::buffer_cast; using boost::asio::buffer_size; close_code code{}; cont_ = cont; @@ -168,7 +159,8 @@ operator()( // Resume BOOST_ASIO_CORO_YIELD - ws_.get_io_service().post(std::move(*this)); + boost::asio::post( + ws_.get_executor(), std::move(*this)); BOOST_ASSERT(ws_.rd_block_ == tok_); // The only way to get read blocked is if @@ -290,7 +282,8 @@ operator()( // Resume BOOST_ASIO_CORO_YIELD - ws_.get_io_service().post(std::move(*this)); + boost::asio::post( + ws_.get_executor(), std::move(*this)); BOOST_ASSERT(ws_.wr_block_ == tok_); // Make sure the stream is open @@ -489,8 +482,8 @@ operator()( zlib::z_params zs; { auto const out = buffers_front(cb_); - zs.next_out = buffer_cast(out); - zs.avail_out = buffer_size(out); + zs.next_out = out.data(); + zs.avail_out = out.size(); BOOST_ASSERT(zs.avail_out > 0); } if(ws_.rd_remain_ > 0) @@ -501,8 +494,8 @@ operator()( auto const in = buffers_prefix( clamp(ws_.rd_remain_), buffers_front( ws_.rd_buf_.data())); - zs.avail_in = buffer_size(in); - zs.next_in = buffer_cast(in); + zs.avail_in = in.size(); + zs.next_in = in.data(); } else { @@ -594,7 +587,8 @@ operator()( // Resume BOOST_ASIO_CORO_YIELD - ws_.get_io_service().post(std::move(*this)); + boost::asio::post( + ws_.get_executor(), std::move(*this)); BOOST_ASSERT(ws_.wr_block_ == tok_); // Make sure the stream is open @@ -659,7 +653,8 @@ operator()( ws_.paused_wr_.maybe_invoke(); } if(! cont_) - return ws_.stream_.get_io_service().post( + return boost::asio::post( + ws_.stream_.get_executor(), bind_handler(std::move(h_), ec, bytes_written_)); h_(ec, bytes_written_); @@ -683,6 +678,9 @@ class stream::read_op bool some_; public: + using allocator_type = + boost::asio::associated_allocator_t; + read_op(read_op&&) = default; read_op(read_op const&) = default; @@ -702,28 +700,25 @@ public: { } + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(ws_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, ws_.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate( - std::size_t size, read_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(read_op* op) { @@ -731,15 +726,6 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, read_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } }; template @@ -771,7 +757,8 @@ operator()( if(ec) { BOOST_ASIO_CORO_YIELD - ws_.get_io_service().post( + boost::asio::post( + ws_.get_executor(), bind_handler(std::move(*this), error::buffer_overflow, 0)); break; @@ -800,7 +787,8 @@ read(DynamicBuffer& buffer) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); error_code ec; auto const bytes_written = read(buffer, ec); @@ -817,7 +805,8 @@ read(DynamicBuffer& buffer, error_code& ec) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); std::size_t bytes_written = 0; do @@ -832,24 +821,27 @@ read(DynamicBuffer& buffer, error_code& ec) template template -async_return_type +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) stream:: async_read(DynamicBuffer& buffer, ReadHandler&& handler) { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - static_assert(beast::is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); - async_completion< + boost::asio::async_completion< ReadHandler, void(error_code, std::size_t)> init{handler}; read_op< DynamicBuffer, - handler_type >{ - init.completion_handler, - *this, - buffer, - 0, - false}(); + BOOST_ASIO_HANDLER_TYPE( + ReadHandler, void(error_code, std::size_t))>{ + init.completion_handler, + *this, + buffer, + 0, + false}(); return init.result.get(); } @@ -865,7 +857,8 @@ read_some( { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); error_code ec; auto const bytes_written = @@ -886,7 +879,8 @@ read_some( { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); using beast::detail::clamp; if(! limit) @@ -912,8 +906,8 @@ read_some( template template -async_return_type +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) stream:: async_read_some( DynamicBuffer& buffer, @@ -922,19 +916,20 @@ async_read_some( { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); - async_completion init{handler}; read_op< DynamicBuffer, - handler_type>{ - init.completion_handler, - *this, - buffer, - limit, - true}({}, 0); + BOOST_ASIO_HANDLER_TYPE( + ReadHandler, void(error_code, std::size_t))>{ + init.completion_handler, + *this, + buffer, + limit, + true}({}, 0); return init.result.get(); } @@ -949,7 +944,7 @@ read_some( { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_mutable_buffer_sequence< + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); error_code ec; @@ -969,12 +964,11 @@ read_some( { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(is_mutable_buffer_sequence< + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); using beast::detail::clamp; using boost::asio::buffer; - using boost::asio::buffer_cast; using boost::asio::buffer_size; close_code code{}; std::size_t bytes_written = 0; @@ -1191,8 +1185,8 @@ loop: zlib::z_params zs; { auto const out = buffers_front(cb); - zs.next_out = buffer_cast(out); - zs.avail_out = buffer_size(out); + zs.next_out = out.data(); + zs.avail_out = out.size(); BOOST_ASSERT(zs.avail_out > 0); } if(rd_remain_ > 0) @@ -1203,8 +1197,8 @@ loop: auto const in = buffers_prefix( clamp(rd_remain_), buffers_front( rd_buf_.data())); - zs.avail_in = buffer_size(in); - zs.next_in = buffer_cast(in); + zs.avail_in = in.size(); + zs.next_in = in.data(); } else if(! did_read) { @@ -1225,8 +1219,8 @@ loop: auto const in = buffers_prefix( clamp(rd_remain_), buffers_front( rd_buf_.data())); - zs.avail_in = buffer_size(in); - zs.next_in = buffer_cast(in); + zs.avail_in = in.size(); + zs.next_in = in.data(); did_read = true; } else @@ -1299,7 +1293,8 @@ loop: template template -async_return_type +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) stream:: async_read_some( MutableBufferSequence const& buffers, @@ -1307,13 +1302,13 @@ async_read_some( { static_assert(is_async_stream::value, "AsyncStream requirements requirements not met"); - static_assert(is_mutable_buffer_sequence< + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); - async_completion init{handler}; - read_some_op>{ + read_some_op{ init.completion_handler,*this, buffers}( {}, 0, false); return init.result.get(); diff --git a/include/boost/beast/websocket/impl/stream.ipp b/include/boost/beast/websocket/impl/stream.ipp index 65a1831c..f8e4a5fc 100644 --- a/include/boost/beast/websocket/impl/stream.ipp +++ b/include/boost/beast/websocket/impl/stream.ipp @@ -91,7 +91,8 @@ std::size_t stream:: read_size_hint(DynamicBuffer& buffer) const { - static_assert(is_dynamic_buffer::value, + static_assert( + boost::asio::is_dynamic_buffer::value, "DynamicBuffer requirements not met"); auto const initial_size = (std::min)( +tcp_frame_size, @@ -503,7 +504,7 @@ write_ping(DynamicBuffer& db, detail::prepare_key(key, fh.key); auto mb = db.prepare(data.size()); boost::asio::buffer_copy(mb, - boost::asio::const_buffers_1( + boost::asio::const_buffer( data.data(), data.size())); if(fh.mask) detail::mask_inplace(mb, key); diff --git a/include/boost/beast/websocket/impl/teardown.ipp b/include/boost/beast/websocket/impl/teardown.ipp index 71622256..bf7f418e 100644 --- a/include/boost/beast/websocket/impl/teardown.ipp +++ b/include/boost/beast/websocket/impl/teardown.ipp @@ -12,9 +12,10 @@ #include #include -#include +#include +#include #include -#include +#include #include namespace boost { @@ -49,29 +50,29 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(s_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, s_.get_executor()); + } + void operator()( error_code ec = {}, std::size_t bytes_transferred = 0); - friend - void* asio_handler_allocate(std::size_t size, - teardown_tcp_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate(void* p, - std::size_t size, teardown_tcp_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(teardown_tcp_op* op) { @@ -79,16 +80,6 @@ public: return op->step_ >= 3 || asio_handler_is_continuation(std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, - teardown_tcp_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } }; template @@ -105,7 +96,8 @@ operator()(error_code ec, std::size_t) if(ec) { step_ = 1; - return s_.get_io_service().post( + return boost::asio::post( + s_.get_executor(), bind_handler(std::move(*this), ec, 0)); } step_ = 2; diff --git a/include/boost/beast/websocket/impl/write.ipp b/include/boost/beast/websocket/impl/write.ipp index cc314c54..0a29c052 100644 --- a/include/boost/beast/websocket/impl/write.ipp +++ b/include/boost/beast/websocket/impl/write.ipp @@ -20,10 +20,10 @@ #include #include #include +#include +#include #include -#include #include -#include #include #include #include @@ -71,6 +71,24 @@ public: { } + using allocator_type = + boost::asio::associated_allocator_t; + + allocator_type + get_allocator() const noexcept + { + return boost::asio::get_associated_allocator(h_); + } + + using executor_type = boost::asio::associated_executor_t< + Handler, decltype(ws_.get_executor())>; + + executor_type get_executor() const noexcept + { + return boost::asio::get_associated_executor( + h_, ws_.get_executor()); + } + Handler& handler() { @@ -82,24 +100,6 @@ public: std::size_t bytes_transferred = 0, bool cont = true); - friend - void* asio_handler_allocate( - std::size_t size, write_some_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_some_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - friend bool asio_handler_is_continuation(write_some_op* op) { @@ -107,15 +107,6 @@ public: return op->cont_ || asio_handler_is_continuation( std::addressof(op->h_)); } - - template - friend - void asio_handler_invoke(Function&& f, write_some_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } }; template @@ -132,7 +123,7 @@ operator()( using boost::asio::buffer; using boost::asio::buffer_copy; using boost::asio::buffer_size; - using boost::asio::mutable_buffers_1; + using boost::asio::mutable_buffer; enum { do_nomask_nofrag, @@ -225,7 +216,8 @@ operator()( // Resume BOOST_ASIO_CORO_YIELD - ws_.get_io_service().post(std::move(*this)); + boost::asio::post( + ws_.get_executor(), std::move(*this)); BOOST_ASSERT(ws_.wr_block_ == tok_); // Make sure the stream is open @@ -435,8 +427,8 @@ operator()( // Send frame BOOST_ASIO_CORO_YIELD boost::asio::async_write(ws_.stream_, - buffers_cat(ws_.wr_fb_.data(), - mutable_buffers_1{b}), std::move(*this)); + buffers_cat(ws_.wr_fb_.data(), b), + std::move(*this)); if(! ws_.check_ok(ec)) goto upcall; bytes_transferred_ += in_; @@ -478,7 +470,8 @@ operator()( ws_.paused_rd_.maybe_invoke() || ws_.paused_ping_.maybe_invoke(); if(! cont_) - return ws_.stream_.get_io_service().post( + return boost::asio::post( + ws_.stream_.get_executor(), bind_handler(h_, ec, bytes_transferred_)); h_(ec, bytes_transferred_); } @@ -494,7 +487,7 @@ write_some(bool fin, ConstBufferSequence const& buffers) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); error_code ec; @@ -514,7 +507,7 @@ write_some(bool fin, { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); using beast::detail::clamp; @@ -720,21 +713,21 @@ write_some(bool fin, template template -async_return_type< - WriteHandler, void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) stream:: async_write_some(bool fin, ConstBufferSequence const& bs, WriteHandler&& handler) { static_assert(is_async_stream::value, "AsyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); - async_completion init{handler}; - write_some_op>{ + write_some_op{ init.completion_handler, *this, fin, bs}( {}, 0, false); return init.result.get(); @@ -750,7 +743,7 @@ write(ConstBufferSequence const& buffers) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); error_code ec; @@ -768,7 +761,7 @@ write(ConstBufferSequence const& buffers, error_code& ec) { static_assert(is_sync_stream::value, "SyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); return write_some(true, buffers, ec); @@ -776,21 +769,21 @@ write(ConstBufferSequence const& buffers, error_code& ec) template template -async_return_type< - WriteHandler, void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) stream:: async_write( ConstBufferSequence const& bs, WriteHandler&& handler) { static_assert(is_async_stream::value, "AsyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); - async_completion init{handler}; - write_some_op>{ + write_some_op{ init.completion_handler, *this, true, bs}( {}, 0, false); return init.result.get(); diff --git a/include/boost/beast/websocket/ssl.hpp b/include/boost/beast/websocket/ssl.hpp index 6c116a7b..44d5dc80 100644 --- a/include/boost/beast/websocket/ssl.hpp +++ b/include/boost/beast/websocket/ssl.hpp @@ -64,7 +64,7 @@ teardown( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using boost::asio::io_service::post(). + manner equivalent to using boost::asio::io_context::post(). */ template diff --git a/include/boost/beast/websocket/stream.hpp b/include/boost/beast/websocket/stream.hpp index f8fb8f9e..8f75d339 100644 --- a/include/boost/beast/websocket/stream.hpp +++ b/include/boost/beast/websocket/stream.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -31,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +38,8 @@ #include #include +#include // DEPRECATED + namespace boost { namespace beast { namespace websocket { @@ -91,11 +93,11 @@ enum class frame_type you would write: @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; @endcode Alternatively, you can write: @code - ip::tcp::socket sock{io_service}; + ip::tcp::socket sock{io_context}; websocket::stream ws{sock}; @endcode @@ -289,19 +291,29 @@ public: //-------------------------------------------------------------------------- - /** Return the `io_service` associated with the stream + /** Get the executor associated with the object. + + This function may be used to obtain the executor object that the stream + uses to dispatch handlers for asynchronous operations. - This function may be used to obtain the `io_service` object - that the stream uses to dispatch handlers for asynchronous - operations. + @return A copy of the executor that stream will use to dispatch handlers. - @return A reference to the io_service object that the stream - will use to dispatch handlers. + @note This function participates in overload resolution only if + `NextLayer` has a member function named `get_executor`. */ - boost::asio::io_service& - get_io_service() +#if BOOST_BEAST_DOXYGEN + implementation_defined +#else + template< + class T = next_layer_type, + class = typename std::enable_if< + has_get_executor::value>::type> + auto +#endif + get_executor() noexcept -> + decltype(std::declval().get_executor()) { - return stream_.get_io_service(); + return stream_.get_executor(); } /** Get a reference to the next layer @@ -746,7 +758,7 @@ public: @par Example @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; ... try { @@ -793,7 +805,7 @@ public: @par Example @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; ... try { @@ -848,7 +860,7 @@ public: @par Example @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; ... try { @@ -910,7 +922,7 @@ public: @par Example @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; ... try { @@ -962,7 +974,7 @@ public: @par Example @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; ... error_code ec; ws.handshake(host, target, ec); @@ -1008,7 +1020,7 @@ public: @par Example @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; ... error_code ec; response_type res; @@ -1062,7 +1074,7 @@ public: @par Example @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; ... error_code ec; ws.handshake("localhost", "/", @@ -1124,7 +1136,7 @@ public: @par Example @code - websocket::stream ws{io_service}; + websocket::stream ws{io_context}; ... error_code ec; response_type res; @@ -1187,15 +1199,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - HandshakeHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + HandshakeHandler, void(error_code)) async_handshake( string_view host, string_view target, @@ -1243,15 +1251,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - HandshakeHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + HandshakeHandler, void(error_code)) async_handshake( response_type& res, string_view host, @@ -1305,15 +1309,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - HandshakeHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + HandshakeHandler, void(error_code)) async_handshake_ex( string_view host, string_view target, @@ -1371,15 +1371,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - HandshakeHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + HandshakeHandler, void(error_code)) async_handshake_ex( response_type& res, string_view host, @@ -1950,15 +1946,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code)) async_accept(AcceptHandler&& handler); /** Start reading and responding to a WebSocket HTTP Upgrade request. @@ -2015,17 +2007,13 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class ResponseDecorator, class AcceptHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code)) async_accept_ex( ResponseDecorator const& decorator, AcceptHandler&& handler); @@ -2082,7 +2070,7 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class ConstBufferSequence, @@ -2092,7 +2080,8 @@ public: #else typename std::enable_if< ! http::detail::is_header::value, - async_return_type>::type + BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code))>::type #endif async_accept( ConstBufferSequence const& buffers, @@ -2159,7 +2148,7 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class ConstBufferSequence, @@ -2170,7 +2159,8 @@ public: #else typename std::enable_if< ! http::detail::is_header::value, - async_return_type>::type + BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code))>::type #endif async_accept_ex( ConstBufferSequence const& buffers, @@ -2219,17 +2209,13 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class Body, class Allocator, class AcceptHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code)) async_accept( http::request> const& req, @@ -2286,18 +2272,14 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class Body, class Allocator, class ResponseDecorator, class AcceptHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + AcceptHandler, void(error_code)) async_accept_ex( http::request> const& req, @@ -2409,15 +2391,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - CloseHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + CloseHandler, void(error_code)) async_close(close_reason const& cr, CloseHandler&& handler); /** Send a WebSocket ping frame. @@ -2491,15 +2469,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - WriteHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code)) async_ping(ping_data const& payload, WriteHandler&& handler); /** Send a WebSocket pong frame. @@ -2588,15 +2562,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - WriteHandler, void(error_code)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code)) async_pong(ping_data const& payload, WriteHandler&& handler); //-------------------------------------------------------------------------- @@ -2751,16 +2721,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - ReadHandler, - void(error_code, std::size_t)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read( DynamicBuffer& buffer, ReadHandler&& handler); @@ -2936,15 +2901,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - ReadHandler, void(error_code, std::size_t)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read_some( DynamicBuffer& buffer, std::size_t limit, @@ -3113,14 +3074,11 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read_some( MutableBufferSequence const& buffers, ReadHandler&& handler); @@ -3257,18 +3215,13 @@ public: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. + manner equivalent to using `boost::asio::io_context::post`. */ template< class ConstBufferSequence, class WriteHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - WriteHandler, - void(error_code, std::size_t)> -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write( ConstBufferSequence const& buffers, WriteHandler&& handler); @@ -3389,12 +3342,8 @@ public: ); @endcode */ template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type -#endif + BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write_some(bool fin, ConstBufferSequence const& buffers, WriteHandler&& handler); diff --git a/include/boost/beast/websocket/teardown.hpp b/include/boost/beast/websocket/teardown.hpp index b1ceab81..289b57c8 100644 --- a/include/boost/beast/websocket/teardown.hpp +++ b/include/boost/beast/websocket/teardown.hpp @@ -79,7 +79,7 @@ teardown( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using boost::asio::io_service::post(). + manner equivalent to using boost::asio::io_context::post(). */ template< @@ -155,7 +155,7 @@ teardown( Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using boost::asio::io_service::post(). + manner equivalent to using boost::asio::io_context::post(). */ template diff --git a/test/beast/core/CMakeLists.txt b/test/beast/core/CMakeLists.txt index b90e9a36..58ca5e31 100644 --- a/test/beast/core/CMakeLists.txt +++ b/test/beast/core/CMakeLists.txt @@ -19,7 +19,6 @@ add_executable (tests-beast-core Jamfile buffer_test.hpp file_test.hpp - async_result.cpp bind_handler.cpp buffered_read_stream.cpp buffers_adapter.cpp @@ -34,7 +33,6 @@ add_executable (tests-beast-core file_win32.cpp flat_buffer.cpp flat_static_buffer.cpp - handler_alloc.cpp handler_ptr.cpp multi_buffer.cpp ostream.cpp diff --git a/test/beast/core/Jamfile b/test/beast/core/Jamfile index 661feec0..aa093ef8 100644 --- a/test/beast/core/Jamfile +++ b/test/beast/core/Jamfile @@ -8,7 +8,6 @@ # local SOURCES = - async_result.cpp bind_handler.cpp buffered_read_stream.cpp buffers_adapter.cpp @@ -23,7 +22,6 @@ local SOURCES = file_win32.cpp flat_buffer.cpp flat_static_buffer.cpp - handler_alloc.cpp handler_ptr.cpp multi_buffer.cpp ostream.cpp diff --git a/test/beast/core/async_result.cpp b/test/beast/core/async_result.cpp deleted file mode 100644 index 163d674b..00000000 --- a/test/beast/core/async_result.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// -// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail 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) -// -// Official repository: https://github.com/boostorg/beast -// - -// Test that header file is self-contained. -#include - -#include -#include -#include - -namespace boost { -namespace beast { -namespace { - -struct handler -{ - void operator()(beast::error_code, std::size_t) const; -}; - -static_assert(detail::is_invocable< - typename async_result::completion_handler_type, - void(error_code, std::size_t)>::value, ""); - -static_assert(std::is_same::return_type>::value, ""); - -static_assert(std::is_constructible< - async_result, - typename async_result::completion_handler_type&>::value, ""); - -} // (anon-ns) -} // beast -} // boost diff --git a/test/beast/core/buffer_test.hpp b/test/beast/core/buffer_test.hpp index 258271d2..d2d78bd5 100644 --- a/test/beast/core/buffer_test.hpp +++ b/test/beast/core/buffer_test.hpp @@ -25,17 +25,15 @@ namespace test { template typename std::enable_if< - is_const_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value, std::string>::type to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + for(auto b : beast::detail::buffers_range(bs)) + s.append(reinterpret_cast(b.data()), + b.size()); return s; } @@ -50,7 +48,7 @@ write_buffer(DynamicBuffer& b, string_view s) template typename std::enable_if< - is_const_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value, std::size_t>::type buffer_count(ConstBufferSequence const& buffers) { @@ -59,7 +57,7 @@ buffer_count(ConstBufferSequence const& buffers) template typename std::enable_if< - is_const_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value, std::size_t>::type size_pre(ConstBufferSequence const& buffers) { @@ -78,7 +76,7 @@ size_pre(ConstBufferSequence const& buffers) template typename std::enable_if< - is_const_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value, std::size_t>::type size_post(ConstBufferSequence const& buffers) { @@ -90,7 +88,7 @@ size_post(ConstBufferSequence const& buffers) template typename std::enable_if< - is_const_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value, std::size_t>::type size_rev_pre(ConstBufferSequence const& buffers) { @@ -102,7 +100,7 @@ size_rev_pre(ConstBufferSequence const& buffers) template typename std::enable_if< - is_const_buffer_sequence::value, + boost::asio::is_const_buffer_sequence::value, std::size_t>::type size_rev_post(ConstBufferSequence const& buffers) { diff --git a/test/beast/core/buffered_read_stream.cpp b/test/beast/core/buffered_read_stream.cpp index a450b0f2..010233ad 100644 --- a/test/beast/core/buffered_read_stream.cpp +++ b/test/beast/core/buffered_read_stream.cpp @@ -31,16 +31,17 @@ class buffered_read_stream_test public: void testSpecialMembers() { - boost::asio::io_service ios; + boost::asio::io_context ioc; { - buffered_read_stream srs(ios); + buffered_read_stream srs(ioc); buffered_read_stream srs2(std::move(srs)); srs = std::move(srs2); - BEAST_EXPECT(&srs.get_io_service() == &ios); - BEAST_EXPECT(&srs.get_io_service() == &srs2.get_io_service()); + BEAST_EXPECT(&srs.get_executor().context() == &ioc); + BEAST_EXPECT( + &srs.get_executor().context() == &srs2.get_executor().context()); } { - test::stream ts{ios}; + test::stream ts{ioc}; buffered_read_stream srs(ts); } } @@ -52,7 +53,7 @@ public: std::size_t n_ = 0; std::size_t cap_; unit_test::suite& suite_; - boost::asio::io_service& ios_; + boost::asio::io_context& ioc_; boost::optional ts_; boost::optional fc_; boost::optionalbuffer().commit(buffer_copy( brs_->buffer().prepare(5), buffer("Hello", 5))); @@ -115,8 +116,8 @@ public: void testAsyncLoop() { - std::make_shared(*this, ios_, 0)->run(); - std::make_shared(*this, ios_, 3)->run(); + std::make_shared(*this, ioc_, 0)->run(); + std::make_shared(*this, ioc_, 3)->run(); } void testRead(yield_context do_yield) @@ -131,7 +132,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc{n}; - test::stream ts(ios_, fc, ", world!"); + test::stream ts(ioc_, fc, ", world!"); buffered_read_stream< test::stream&, multi_buffer> srs(ts); srs.buffer().commit(buffer_copy( @@ -149,7 +150,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc{n}; - test::stream ts(ios_, fc, ", world!"); + test::stream ts(ioc_, fc, ", world!"); buffered_read_stream< test::stream&, multi_buffer> srs(ts); srs.capacity(3); @@ -168,7 +169,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc{n}; - test::stream ts(ios_, fc, ", world!"); + test::stream ts(ioc_, fc, ", world!"); buffered_read_stream< test::stream&, multi_buffer> srs(ts); srs.buffer().commit(buffer_copy( @@ -187,7 +188,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc{n}; - test::stream ts(ios_, fc, ", world!"); + test::stream ts(ioc_, fc, ", world!"); buffered_read_stream< test::stream&, multi_buffer> srs(ts); srs.capacity(3); diff --git a/test/beast/core/buffers_adapter.cpp b/test/beast/core/buffers_adapter.cpp index 326a2111..b22316ed 100644 --- a/test/beast/core/buffers_adapter.cpp +++ b/test/beast/core/buffers_adapter.cpp @@ -29,20 +29,17 @@ public: std::string to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; - s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + s.reserve(boost::asio::buffer_size(bs)); + for(auto b : beast::detail::buffers_range(bs)) + s.append(reinterpret_cast< + char const*>(b.data()), b.size()); return s; } void testBuffersAdapter() { using boost::asio::buffer; - using boost::asio::buffer_cast; using boost::asio::buffer_size; using boost::asio::const_buffer; using boost::asio::mutable_buffer; diff --git a/test/beast/core/buffers_cat.cpp b/test/beast/core/buffers_cat.cpp index 7d1c1fef..30f92d49 100644 --- a/test/beast/core/buffers_cat.cpp +++ b/test/beast/core/buffers_cat.cpp @@ -218,26 +218,23 @@ public: void run() override { using boost::asio::const_buffer; - using boost::asio::const_buffers_1; + using boost::asio::const_buffer; using boost::asio::mutable_buffer; - using boost::asio::mutable_buffers_1; struct user_defined : mutable_buffer { }; // Check is_all_const_buffer_sequence BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); + detail::is_all_const_buffer_sequence::value); BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); + detail::is_all_const_buffer_sequence::value); BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); + detail::is_all_const_buffer_sequence::value); BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); + detail::is_all_const_buffer_sequence::value); BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); - BOOST_STATIC_ASSERT( - ! detail::is_all_const_buffer_sequence::value); + ! detail::is_all_const_buffer_sequence::value); // Ensure that concatenating mutable buffer // sequences results in a mutable buffer sequence diff --git a/test/beast/core/buffers_prefix.cpp b/test/beast/core/buffers_prefix.cpp index 82cdbf83..e4c030c2 100644 --- a/test/beast/core/buffers_prefix.cpp +++ b/test/beast/core/buffers_prefix.cpp @@ -25,18 +25,14 @@ BOOST_STATIC_ASSERT( std::declval()))>::value); BOOST_STATIC_ASSERT( - is_const_buffer_sequence()))>::value); + std::declval()))>::value); BOOST_STATIC_ASSERT( std::is_same()))>::value); -BOOST_STATIC_ASSERT( - is_mutable_buffer_sequence()))>::value); class buffers_prefix_test : public beast::unit_test::suite { @@ -97,13 +93,11 @@ public: std::string to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + for(auto b : beast::detail::buffers_range(bs)) + s.append(reinterpret_cast(b.data()), + b.size()); return s; } diff --git a/test/beast/core/buffers_suffix.cpp b/test/beast/core/buffers_suffix.cpp index fdd1225b..3d3c87df 100644 --- a/test/beast/core/buffers_suffix.cpp +++ b/test/beast/core/buffers_suffix.cpp @@ -58,10 +58,10 @@ public: { char buf[12]; buffers_suffix< - boost::asio::const_buffers_1> cb1{ + boost::asio::const_buffer> cb1{ boost::in_place_init, buf, sizeof(buf)}; buffers_suffix< - boost::asio::const_buffers_1> cb2{ + boost::asio::const_buffer> cb2{ boost::in_place_init, nullptr, 0}; cb2 = cb1; cb1 = std::move(cb2); @@ -116,11 +116,11 @@ public: testDefaultCtor() { using namespace test; - class test_buffer : public boost::asio::const_buffers_1 + class test_buffer : public boost::asio::const_buffer { public: test_buffer() - : boost::asio::const_buffers_1("\r\n", 2) + : boost::asio::const_buffer("\r\n", 2) { } }; @@ -134,11 +134,11 @@ public: { using namespace test; buffers_suffix> cb( + boost::asio::const_buffer, + boost::asio::const_buffer>> cb( boost::in_place_init, - boost::asio::const_buffers_1("\r", 1), - boost::asio::const_buffers_1("\n", 1)); + boost::asio::const_buffer("\r", 1), + boost::asio::const_buffer("\n", 1)); BEAST_EXPECT(to_string(cb) == "\r\n"); } diff --git a/test/beast/core/flat_buffer.cpp b/test/beast/core/flat_buffer.cpp index 23a9b820..87ff033b 100644 --- a/test/beast/core/flat_buffer.cpp +++ b/test/beast/core/flat_buffer.cpp @@ -22,8 +22,8 @@ namespace boost { namespace beast { -static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); +BOOST_STATIC_ASSERT( + boost::asio::is_dynamic_buffer::value); class flat_buffer_test : public beast::unit_test::suite { diff --git a/test/beast/core/flat_static_buffer.cpp b/test/beast/core/flat_static_buffer.cpp index 66f5a907..d68a1906 100644 --- a/test/beast/core/flat_static_buffer.cpp +++ b/test/beast/core/flat_static_buffer.cpp @@ -20,9 +20,8 @@ namespace boost { namespace beast { -static_assert( - is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); +BOOST_STATIC_ASSERT( + boost::asio::is_dynamic_buffer::value); class flat_static_buffer_test : public beast::unit_test::suite { @@ -32,7 +31,6 @@ public: { using namespace test; using boost::asio::buffer; - using boost::asio::buffer_cast; using boost::asio::buffer_size; char buf[12]; std::string const s = "Hello, world"; diff --git a/test/beast/core/handler_alloc.cpp b/test/beast/core/handler_alloc.cpp deleted file mode 100644 index 32defc73..00000000 --- a/test/beast/core/handler_alloc.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// -// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail 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) -// -// Official repository: https://github.com/boostorg/beast -// - -// Test that header file is self-contained. -#include - -#include -#include -#include - -namespace boost { -namespace beast { - -class handler_alloc_test : public beast::unit_test::suite -{ -public: - struct handler - { - void - operator()() const - { - } - }; - - // https://github.com/boostorg/beast/issues/432 - void - testRegression432() - { - handler h; - handler_alloc a{h}; - std::list> v{a}; - v.push_back(1); - v.push_back(2); - v.push_back(3); - } - - void - run() override - { - testRegression432(); - - handler h; - handler h2; - handler_alloc a1{h}; - handler_alloc a2{h2}; - BEAST_EXPECT(a2 == a1); - auto a3 = a1; - BEAST_EXPECT(a3 == a1); - { - std::vector> v(a1); - v.reserve(32); - v.resize(10); - } - } -}; - -BEAST_DEFINE_TESTSUITE(beast,core,handler_alloc); - -} // beast -} // boost diff --git a/test/beast/core/multi_buffer.cpp b/test/beast/core/multi_buffer.cpp index 80ab4af7..982cbef8 100644 --- a/test/beast/core/multi_buffer.cpp +++ b/test/beast/core/multi_buffer.cpp @@ -26,7 +26,8 @@ namespace boost { namespace beast { -BOOST_STATIC_ASSERT(is_dynamic_buffer::value); +BOOST_STATIC_ASSERT( + boost::asio::is_dynamic_buffer::value); class multi_buffer_test : public beast::unit_test::suite { diff --git a/test/beast/core/ostream.cpp b/test/beast/core/ostream.cpp index 65c639c6..0c069a47 100644 --- a/test/beast/core/ostream.cpp +++ b/test/beast/core/ostream.cpp @@ -25,13 +25,11 @@ public: std::string to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + for(auto b : beast::detail::buffers_range(bs)) + s.append(reinterpret_cast< + char const*>(b.data()), b.size()); return s; } diff --git a/test/beast/core/static_buffer.cpp b/test/beast/core/static_buffer.cpp index cb6d44db..485ab26c 100644 --- a/test/beast/core/static_buffer.cpp +++ b/test/beast/core/static_buffer.cpp @@ -20,9 +20,8 @@ namespace boost { namespace beast { -static_assert( - is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); +BOOST_STATIC_ASSERT( + boost::asio::is_dynamic_buffer::value); class static_buffer_test : public beast::unit_test::suite { @@ -32,7 +31,6 @@ public: { using namespace test; using boost::asio::buffer; - using boost::asio::buffer_cast; using boost::asio::buffer_size; char buf[12]; std::string const s = "Hello, world"; diff --git a/test/beast/core/type_traits.cpp b/test/beast/core/type_traits.cpp index e3be630a..9411b90e 100644 --- a/test/beast/core/type_traits.cpp +++ b/test/beast/core/type_traits.cpp @@ -121,24 +121,6 @@ BOOST_STATIC_ASSERT(min_all(1u, 2u, static_cast(3)) == 1); } // detail -// -// buffer concepts -// - -namespace { - -struct T {}; - -BOOST_STATIC_ASSERT(is_const_buffer_sequence::value); -BOOST_STATIC_ASSERT(! is_const_buffer_sequence::value); - -BOOST_STATIC_ASSERT(is_mutable_buffer_sequence::value); -BOOST_STATIC_ASSERT(! is_mutable_buffer_sequence::value); - -BOOST_STATIC_ASSERT(is_dynamic_buffer::value); - -} // (anonymous) - // // handler concepts // @@ -169,7 +151,7 @@ struct not_a_stream get_io_service(); }; -BOOST_STATIC_ASSERT(has_get_io_service::value); +BOOST_STATIC_ASSERT(has_get_executor::value); BOOST_STATIC_ASSERT(is_async_read_stream::value); BOOST_STATIC_ASSERT(is_async_write_stream::value); BOOST_STATIC_ASSERT(is_async_stream::value); @@ -177,7 +159,7 @@ BOOST_STATIC_ASSERT(is_sync_read_stream::value); BOOST_STATIC_ASSERT(is_sync_write_stream::value); BOOST_STATIC_ASSERT(is_sync_stream::value); -BOOST_STATIC_ASSERT(! has_get_io_service::value); +BOOST_STATIC_ASSERT(! has_get_executor::value); BOOST_STATIC_ASSERT(! is_async_read_stream::value); BOOST_STATIC_ASSERT(! is_async_write_stream::value); BOOST_STATIC_ASSERT(! is_sync_read_stream::value); diff --git a/test/beast/http/basic_parser.cpp b/test/beast/http/basic_parser.cpp index 349a95c7..a6462379 100644 --- a/test/beast/http/basic_parser.cpp +++ b/test/beast/http/basic_parser.cpp @@ -152,7 +152,7 @@ public: template typename std::enable_if< - is_const_buffer_sequence::value>::type + boost::asio::is_const_buffer_sequence::value>::type parsegrind(ConstBufferSequence const& buffers, Test const& test, bool skip = false) { @@ -213,13 +213,13 @@ public: void parsegrind(string_view msg, Test const& test, bool skip = false) { - parsegrind(boost::asio::const_buffers_1{ + parsegrind(boost::asio::const_buffer{ msg.data(), msg.size()}, test, skip); } template typename std::enable_if< - is_const_buffer_sequence::value>::type + boost::asio::is_const_buffer_sequence::value>::type parsegrind(ConstBufferSequence const& buffers) { parsegrind(buffers, [](Parser const&){}); @@ -241,7 +241,7 @@ public: Parser p; p.eager(true); error_code ec; - buffers_suffix cb{ + buffers_suffix cb{ boost::in_place_init, msg.data(), msg.size()}; auto n = p.put(buffers_prefix(i, cb), ec); if(ec == result) @@ -266,8 +266,8 @@ public: p.eager(true); error_code ec; p.put(buffers_cat( - boost::asio::const_buffers_1{msg.data(), i}, - boost::asio::const_buffers_1{ + boost::asio::const_buffer{msg.data(), i}, + boost::asio::const_buffer{ msg.data() + i, msg.size() - i}), ec); if(! ec) p.put_eof(ec); @@ -887,7 +887,7 @@ public: //-------------------------------------------------------------------------- static - boost::asio::const_buffers_1 + boost::asio::const_buffer buf(string_view s) { return {s.data(), s.size()}; @@ -1140,7 +1140,7 @@ public: error_code ec; test_parser p; p.eager(true); - p.put(boost::asio::const_buffers_1{ + p.put(boost::asio::const_buffer{ s.data(), s.size()}, ec); }); }; @@ -1156,7 +1156,7 @@ public: error_code ec; test_parser p; p.eager(true); - p.put(boost::asio::const_buffers_1{ + p.put(boost::asio::const_buffer{ msg.data(), msg.size()}, ec); BEAST_EXPECTS(! ec, ec.message()); grind(msg); @@ -1173,7 +1173,7 @@ public: error_code ec; test_parser p; p.eager(true); - p.put(boost::asio::const_buffers_1{ + p.put(boost::asio::const_buffer{ msg.data(), msg.size()}, ec); BEAST_EXPECT(ec); grind(msg); diff --git a/test/beast/http/chunk_encode.cpp b/test/beast/http/chunk_encode.cpp index 638ff5a4..ed6ebe8c 100644 --- a/test/beast/http/chunk_encode.cpp +++ b/test/beast/http/chunk_encode.cpp @@ -42,10 +42,10 @@ public: { std::string s; s.reserve(boost::asio::buffer_size(buffers)); - for(boost::asio::const_buffer buffer : buffers) + for(boost::asio::const_buffer b : beast::detail::buffers_range(buffers)) s.append( - boost::asio::buffer_cast(buffer), - boost::asio::buffer_size(buffer)); + reinterpret_cast(b.data()), + b.size()); return s; } @@ -73,7 +73,7 @@ public: BEAST_EXPECT(to_string(t3) == match); } - using cb_t = boost::asio::const_buffers_1; + using cb_t = boost::asio::const_buffer; static cb_t diff --git a/test/beast/http/dynamic_body.cpp b/test/beast/http/dynamic_body.cpp index a81f88b0..14bf3191 100644 --- a/test/beast/http/dynamic_body.cpp +++ b/test/beast/http/dynamic_body.cpp @@ -24,7 +24,7 @@ namespace http { class dynamic_body_test : public beast::unit_test::suite { - boost::asio::io_service ios_; + boost::asio::io_context ioc_; public: template @@ -42,13 +42,11 @@ public: std::string to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; - s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + s.reserve(boost::asio::buffer_size(bs)); + for(auto b : beast::detail::buffers_range(bs)) + s.append(reinterpret_cast(b.data()), + b.size()); return s; } @@ -61,7 +59,7 @@ public: "Content-Length: 3\r\n" "\r\n" "xyz"; - test::stream ts(ios_, s); + test::stream ts(ioc_, s); response_parser p; multi_buffer b; read(ts, b, p); diff --git a/test/beast/http/file_body.cpp b/test/beast/http/file_body.cpp index b63a5ce7..c950fa22 100644 --- a/test/beast/http/file_body.cpp +++ b/test/beast/http/file_body.cpp @@ -10,6 +10,7 @@ // Test that header file is self-contained. #include +#include #include #include #include @@ -86,10 +87,10 @@ public: serializer, fields> sr{res}; sr.next(ec, visit); BEAST_EXPECTS(! ec, ec.message()); - auto const cb = *visit.buffer.data().begin(); + auto const b = buffers_front(visit.buffer.data()); string_view const s1{ - boost::asio::buffer_cast(cb), - boost::asio::buffer_size(cb)}; + reinterpret_cast(b.data()), + b.size()}; BEAST_EXPECTS(s1 == s, s1); } } diff --git a/test/beast/http/message_fuzz.hpp b/test/beast/http/message_fuzz.hpp index bbb31d67..cbd1b084 100644 --- a/test/beast/http/message_fuzz.hpp +++ b/test/beast/http/message_fuzz.hpp @@ -503,10 +503,14 @@ public: auto const len = rand(500); ostream(db) << "Content-Length: " << len << "\r\n\r\n"; - for(boost::asio::mutable_buffer b : db.prepare(len)) + auto mb = db.prepare(len); + for(auto it = boost::asio::buffer_sequence_begin(mb); + it != boost::asio::buffer_sequence_end(mb); + ++it) { - auto p = boost::asio::buffer_cast(b); - auto n = boost::asio::buffer_size(b); + boost::asio::mutable_buffer b = *it; + auto p = reinterpret_cast(b.data()); + auto n = b.size(); while(n--) *p++ = static_cast(32 + rand(26+26+10+6)); } @@ -523,10 +527,14 @@ public: len -= n; ostream(db) << to_hex(n) << "\r\n"; - for(boost::asio::mutable_buffer b : db.prepare(n)) + auto mb = db.prepare(n); + for(auto it = boost::asio::buffer_sequence_begin(mb); + it != boost::asio::buffer_sequence_end(mb); + ++it) { - auto p = boost::asio::buffer_cast(b); - auto m = boost::asio::buffer_size(b); + boost::asio::mutable_buffer b = *it; + auto p = reinterpret_cast(b.data()); + auto m = b.size(); while(m--) *p++ = static_cast(32 + rand(26+26+10+6)); } diff --git a/test/beast/http/parser.cpp b/test/beast/http/parser.cpp index 1bef3b27..fb133574 100644 --- a/test/beast/http/parser.cpp +++ b/test/beast/http/parser.cpp @@ -37,7 +37,7 @@ public: parser; static - boost::asio::const_buffers_1 + boost::asio::const_buffer buf(string_view s) { return {s.data(), s.size()}; diff --git a/test/beast/http/read.cpp b/test/beast/http/read.cpp index c58df607..55837762 100644 --- a/test/beast/http/read.cpp +++ b/test/beast/http/read.cpp @@ -48,7 +48,7 @@ public: b.commit(buffer_copy( b.prepare(len), buffer(s, len))); test::fail_counter fc(n); - test::stream ts{ios_, fc}; + test::stream ts{ioc_, fc}; test_parser p(fc); error_code ec = test::error::fail_error; ts.close_remote(); @@ -64,7 +64,7 @@ public: b.commit(buffer_copy( b.prepare(pre), buffer(s, pre))); test::fail_counter fc(n); - test::stream ts{ios_, fc, + test::stream ts{ioc_, fc, std::string(s + pre, len - pre)}; test_parser p(fc); error_code ec = test::error::fail_error; @@ -80,7 +80,7 @@ public: b.commit(buffer_copy( b.prepare(len), buffer(s, len))); test::fail_counter fc(n); - test::stream ts{ios_, fc}; + test::stream ts{ioc_, fc}; test_parser p(fc); error_code ec = test::error::fail_error; ts.close_remote(); @@ -95,7 +95,7 @@ public: b.commit(buffer_copy( b.prepare(len), buffer(s, len))); test::fail_counter fc(n); - test::stream ts{ios_, fc}; + test::stream ts{ioc_, fc}; test_parser p(fc); error_code ec = test::error::fail_error; ts.close_remote(); @@ -111,7 +111,7 @@ public: b.commit(buffer_copy( b.prepare(pre), buffer(s, pre))); test::fail_counter fc(n); - test::stream ts(ios_, fc, + test::stream ts(ioc_, fc, std::string{s + pre, len - pre}); test_parser p(fc); error_code ec = test::error::fail_error; @@ -128,7 +128,7 @@ public: try { multi_buffer b; - test::stream c{ios_, "GET / X"}; + test::stream c{ioc_, "GET / X"}; c.close_remote(); request_parser p; read(c, b, p); @@ -144,7 +144,7 @@ public: testBufferOverflow() { { - test::stream c{ios_}; + test::stream c{ioc_}; ostream(c.buffer()) << "GET / HTTP/1.1\r\n" "Host: localhost\r\n" @@ -167,7 +167,7 @@ public: } } { - test::stream c{ios_}; + test::stream c{ioc_}; ostream(c.buffer()) << "GET / HTTP/1.1\r\n" "Host: localhost\r\n" @@ -254,7 +254,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc{n}; - test::stream c{ios_, fc, + test::stream c{ioc_, fc, "GET / HTTP/1.1\r\n" "Host: localhost\r\n" "User-Agent: test\r\n" @@ -277,7 +277,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc{n}; - test::stream ts{ios_, fc, + test::stream ts{ioc_, fc, "GET / HTTP/1.1\r\n" "Host: localhost\r\n" "User-Agent: test\r\n" @@ -296,7 +296,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc{n}; - test::stream c{ios_, fc, + test::stream c{ioc_, fc, "GET / HTTP/1.1\r\n" "Host: localhost\r\n" "User-Agent: test\r\n" @@ -318,7 +318,7 @@ public: { { multi_buffer b; - test::stream ts{ios_}; + test::stream ts{ioc_}; request_parser p; error_code ec; ts.close_remote(); @@ -327,7 +327,7 @@ public: } { multi_buffer b; - test::stream ts{ios_}; + test::stream ts{ioc_}; request_parser p; error_code ec; ts.close_remote(); @@ -352,28 +352,28 @@ public: { { // Make sure handlers are not destroyed - // after calling io_service::stop - boost::asio::io_service ios; - test::stream ts{ios, + // after calling io_context::stop + boost::asio::io_context ioc; + test::stream ts{ioc, "GET / HTTP/1.1\r\n\r\n"}; BEAST_EXPECT(handler::count() == 0); multi_buffer b; request m; async_read(ts, b, m, handler{}); BEAST_EXPECT(handler::count() > 0); - ios.stop(); + ioc.stop(); BEAST_EXPECT(handler::count() > 0); - ios.reset(); + ioc.restart(); BEAST_EXPECT(handler::count() > 0); - ios.run_one(); + ioc.run_one(); BEAST_EXPECT(handler::count() == 0); } { // Make sure uninvoked handlers are - // destroyed when calling ~io_service + // destroyed when calling ~io_context { - boost::asio::io_service ios; - test::stream ts{ios, + boost::asio::io_context ioc; + test::stream ts{ioc, "GET / HTTP/1.1\r\n\r\n"}; BEAST_EXPECT(handler::count() == 0); multi_buffer b; @@ -389,7 +389,7 @@ public: void testRegression430() { - test::stream ts{ios_}; + test::stream ts{ioc_}; ts.read_size(1); ostream(ts.buffer()) << "HTTP/1.1 200 OK\r\n" @@ -417,7 +417,7 @@ public: Parser p; error_code ec = test::error::fail_error; flat_buffer b; - test::stream ts{ios_}; + test::stream ts{ioc_}; ostream(ts.buffer()) << s; ts.read_size(n); read(ts, b, p, ec); diff --git a/test/beast/http/serializer.cpp b/test/beast/http/serializer.cpp index 3d364730..7e35f253 100644 --- a/test/beast/http/serializer.cpp +++ b/test/beast/http/serializer.cpp @@ -27,7 +27,7 @@ public: struct reader { using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template reader(message const&); @@ -47,7 +47,7 @@ public: struct reader { using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template reader(message&); diff --git a/test/beast/http/span_body.cpp b/test/beast/http/span_body.cpp index 2dbf2c0f..55d5149e 100644 --- a/test/beast/http/span_body.cpp +++ b/test/beast/http/span_body.cpp @@ -54,13 +54,13 @@ struct span_body_test error_code ec; w.init(boost::none, ec); BEAST_EXPECTS(! ec, ec.message()); - w.put(boost::asio::const_buffers_1{ + w.put(boost::asio::const_buffer{ "123", 3}, ec); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(buf[0] == '1'); BEAST_EXPECT(buf[1] == '2'); BEAST_EXPECT(buf[2] == '3'); - w.put(boost::asio::const_buffers_1{ + w.put(boost::asio::const_buffer{ "456", 3}, ec); BEAST_EXPECTS(ec == error::buffer_overflow, ec.message()); } diff --git a/test/beast/http/test_parser.hpp b/test/beast/http/test_parser.hpp index 3d65c9c5..76174819 100644 --- a/test/beast/http/test_parser.hpp +++ b/test/beast/http/test_parser.hpp @@ -27,7 +27,7 @@ class test_parser public: using mutable_buffers_type = - boost::asio::mutable_buffers_1; + boost::asio::mutable_buffer; int status = 0; int version = 0; diff --git a/test/beast/http/write.cpp b/test/beast/http/write.cpp index d0e8ebaa..bcd91952 100644 --- a/test/beast/http/write.cpp +++ b/test/beast/http/write.cpp @@ -44,7 +44,7 @@ public: public: using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template explicit @@ -89,7 +89,7 @@ public: public: using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template explicit @@ -226,7 +226,7 @@ public: public: using const_buffers_type = - boost::asio::const_buffers_1; + boost::asio::const_buffer; template explicit @@ -270,13 +270,11 @@ public: std::string to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + for(auto b : beast::detail::buffers_range(bs)) + s.append(reinterpret_cast(b), + b.size()); return s; } @@ -284,7 +282,7 @@ public: bool equal_body(string_view sv, string_view body) { - test::stream ts{ios_, sv}, tr{ios_}; + test::stream ts{ioc_, sv}, tr{ioc_}; ts.connect(tr); message m; multi_buffer b; @@ -305,7 +303,7 @@ public: std::string str(message const& m) { - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); error_code ec; write(ts, m, ec); @@ -325,7 +323,7 @@ public: m.set(field::content_length, "5"); m.body() = "*****"; error_code ec; - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); async_write(ts, m, do_yield[ec]); BEAST_EXPECT(! m.keep_alive()); @@ -345,7 +343,7 @@ public: m.set(field::transfer_encoding, "chunked"); m.body() = "*****"; error_code ec; - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); async_write(ts, m, do_yield[ec]); if(BEAST_EXPECTS(! ec, ec.message())) @@ -369,7 +367,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc(n); - test::stream ts{ios_, fc}, tr{ios_}; + test::stream ts{ioc_, fc}, tr{ioc_}; ts.connect(tr); request m(verb::get, "/", 10, fc); m.set(field::user_agent, "test"); @@ -399,7 +397,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc(n); - test::stream ts{ios_, fc}, tr{ios_}; + test::stream ts{ioc_, fc}, tr{ioc_}; ts.connect(tr); request m{verb::get, "/", 10, fc}; m.set(field::user_agent, "test"); @@ -430,7 +428,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc(n); - test::stream ts{ios_, fc}, tr{ios_}; + test::stream ts{ioc_, fc}, tr{ioc_}; ts.connect(tr); request m{verb::get, "/", 10, fc}; m.set(field::user_agent, "test"); @@ -461,7 +459,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc(n); - test::stream ts{ios_, fc}, tr{ios_}; + test::stream ts{ioc_, fc}, tr{ioc_}; ts.connect(tr); request m{verb::get, "/", 10, fc}; m.set(field::user_agent, "test"); @@ -488,7 +486,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc(n); - test::stream ts{ios_, fc}, tr{ios_}; + test::stream ts{ioc_, fc}, tr{ioc_}; ts.connect(tr); request m{verb::get, "/", 10, fc}; m.set(field::user_agent, "test"); @@ -542,7 +540,7 @@ public: m.set(field::user_agent, "test"); m.body() = "*"; m.prepare_payload(); - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); error_code ec; write(ts, m, ec); @@ -581,7 +579,7 @@ public: m.set(field::user_agent, "test"); m.body() = "*"; m.prepare_payload(); - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); error_code ec; write(ts, m, ec); @@ -648,9 +646,9 @@ public: { { // Make sure handlers are not destroyed - // after calling io_service::stop - boost::asio::io_service ios; - test::stream ts{ios}; + // after calling io_context::stop + boost::asio::io_context ioc; + test::stream ts{ioc}; BEAST_EXPECT(handler::count() == 0); request m; m.method(verb::get); @@ -660,19 +658,19 @@ public: m.body() = "*****"; async_write(ts, m, handler{}); BEAST_EXPECT(handler::count() > 0); - ios.stop(); + ioc.stop(); BEAST_EXPECT(handler::count() > 0); - ios.reset(); + ioc.restart(); BEAST_EXPECT(handler::count() > 0); - ios.run_one(); + ioc.run_one(); BEAST_EXPECT(handler::count() == 0); } { // Make sure uninvoked handlers are - // destroyed when calling ~io_service + // destroyed when calling ~io_context { - boost::asio::io_service ios; - test::stream ts{ios}, tr{ios}; + boost::asio::io_context ioc; + test::stream ts{ioc}, tr{ioc}; ts.connect(tr); BEAST_EXPECT(handler::count() == 0); request m; @@ -733,7 +731,7 @@ public: void testWriteStream(boost::asio::yield_context yield) { - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); ts.write_size(3); @@ -849,8 +847,8 @@ public: void testIssue655() { - boost::asio::io_service ios; - test::stream ts{ios}, tr{ios}; + boost::asio::io_context ioc; + test::stream ts{ioc}, tr{ioc}; ts.connect(tr); response res; res.chunked(true); @@ -859,7 +857,7 @@ public: [&](error_code const&, std::size_t) { }); - ios.run(); + ioc.run(); } void diff --git a/test/beast/websocket/accept.cpp b/test/beast/websocket/accept.cpp index b98640a4..71ae0768 100644 --- a/test/beast/websocket/accept.cpp +++ b/test/beast/websocket/accept.cpp @@ -70,7 +70,7 @@ public: // request in stream, oversized { - stream ws{ios_, + stream ws{ioc_, "GET / HTTP/1.1\r\n" "Host: localhost\r\n" "Upgrade: websocket\r\n" @@ -115,7 +115,7 @@ public: // request in stream, decorator, oversized { - stream ws{ios_, + stream ws{ioc_, "GET / HTTP/1.1\r\n" "Host: localhost\r\n" "Upgrade: websocket\r\n" @@ -158,7 +158,7 @@ public: // request in buffers, oversize { - stream ws{ios_}; + stream ws{ioc_}; auto tr = connect(ws.next_layer()); try { @@ -202,7 +202,7 @@ public: // request in buffers, decorator, oversized { - stream ws{ios_}; + stream ws{ioc_}; auto tr = connect(ws.next_layer()); try { @@ -248,7 +248,7 @@ public: // request in buffers and stream, oversized { - stream ws{ios_, + stream ws{ioc_, "Connection: upgrade\r\n" "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" "Sec-WebSocket-Version: 13\r\n" @@ -294,7 +294,7 @@ public: // request in buffers and stream, decorator, oversize { - stream ws{ios_, + stream ws{ioc_, "Connection: upgrade\r\n" "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" "Sec-WebSocket-Version: 13\r\n" @@ -415,7 +415,7 @@ public: // Closed by client { - stream ws{ios_}; + stream ws{ioc_}; auto tr = connect(ws.next_layer()); tr.close(); try @@ -466,7 +466,7 @@ public: n = s.size() - 1; break; } - stream ws{ios_}; + stream ws{ioc_}; auto tr = connect(ws.next_layer()); ws.next_layer().append( s.substr(n, s.size() - n)); diff --git a/test/beast/websocket/close.cpp b/test/beast/websocket/close.cpp index 494ca42e..2c215206 100644 --- a/test/beast/websocket/close.cpp +++ b/test/beast/websocket/close.cpp @@ -50,7 +50,7 @@ public: // already closed { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); w.handshake(ws, "localhost", "/"); w.close(ws, {}); @@ -96,7 +96,7 @@ public: // drain invalid message frame after close { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); w.handshake(ws, "localhost", "/"); ws.next_layer().append("\x81\x81\xff\xff\xff\xff*"); @@ -116,7 +116,7 @@ public: // drain invalid close frame after close { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); w.handshake(ws, "localhost", "/"); ws.next_layer().append("\x88\x01*"); @@ -136,7 +136,7 @@ public: // drain masked close frame { echo_server es{log, kind::async_client}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); ws.set_option(pmd); es.async_handshake(); @@ -174,8 +174,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -198,7 +198,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -206,8 +206,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -231,7 +231,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -239,8 +239,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add a ping and message to the input @@ -258,8 +258,8 @@ public: }); while(! ws.wr_block_) { - ios.run_one(); - if(! BEAST_EXPECT(! ios.stopped())) + ioc.run_one(); + if(! BEAST_EXPECT(! ioc.stopped())) break; } BEAST_EXPECT(count == 0); @@ -272,7 +272,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -280,8 +280,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add an invalid frame to the input @@ -299,8 +299,8 @@ public: }); while(! ws.wr_block_) { - ios.run_one(); - if(! BEAST_EXPECT(! ios.stopped())) + ioc.run_one(); + if(! BEAST_EXPECT(! ioc.stopped())) break; } BEAST_EXPECT(count == 0); @@ -313,7 +313,7 @@ public: BEAST_EXPECT(++count == 2); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -321,8 +321,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add a close frame to the input @@ -340,8 +340,8 @@ public: }); while(! ws.wr_block_) { - ios.run_one(); - if(! BEAST_EXPECT(! ios.stopped())) + ioc.run_one(); + if(! BEAST_EXPECT(! ioc.stopped())) break; } BEAST_EXPECT(count == 0); @@ -354,7 +354,7 @@ public: BEAST_EXPECT(++count == 2); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -362,8 +362,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add a close frame to the input @@ -398,7 +398,7 @@ public: BEAST_EXPECT(++count == 2); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 3); }); @@ -406,8 +406,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add a ping frame to the input @@ -445,7 +445,7 @@ public: BEAST_EXPECT(ws.is_open()); BEAST_EXPECT(ws.wr_block_); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 3); }); @@ -453,8 +453,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -493,7 +493,7 @@ public: ++count; }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 4); }); @@ -501,8 +501,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -554,7 +554,7 @@ public: BEAST_EXPECT(count == 2 || count == 3); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 4); }); @@ -562,8 +562,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -602,7 +602,7 @@ public: BEAST_EXPECT(++count == 2); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 4); }); } @@ -615,7 +615,7 @@ public: void operator()(error_code) {} }; - stream ws{ios_}; + stream ws{ioc_}; stream::close_op op{ handler{}, ws, {}}; using boost::asio::asio_handler_is_continuation; diff --git a/test/beast/websocket/handshake.cpp b/test/beast/websocket/handshake.cpp index a585436b..acf27f91 100644 --- a/test/beast/websocket/handshake.cpp +++ b/test/beast/websocket/handshake.cpp @@ -139,7 +139,7 @@ public: auto const check = [&](std::string const& s) { - stream ws{ios_}; + stream ws{ioc_}; auto tr = connect(ws.next_layer()); ws.next_layer().append(s); tr.close(); diff --git a/test/beast/websocket/ping.cpp b/test/beast/websocket/ping.cpp index 855a5996..4c467816 100644 --- a/test/beast/websocket/ping.cpp +++ b/test/beast/websocket/ping.cpp @@ -42,7 +42,7 @@ public: // ping, already closed { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.close({}); @@ -62,7 +62,7 @@ public: // pong, already closed { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.close({}); @@ -98,8 +98,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -123,7 +123,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -131,8 +131,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -155,7 +155,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -163,8 +163,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add a ping and message to the input @@ -182,8 +182,8 @@ public: }); while(! ws.wr_block_) { - ios.run_one(); - if(! BEAST_EXPECT(! ios.stopped())) + ioc.run_one(); + if(! BEAST_EXPECT(! ioc.stopped())) break; } BEAST_EXPECT(count == 0); @@ -196,7 +196,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -204,8 +204,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add an invalid frame to the input @@ -224,8 +224,8 @@ public: }); while(! ws.wr_block_) { - ios.run_one(); - if(! BEAST_EXPECT(! ios.stopped())) + ioc.run_one(); + if(! BEAST_EXPECT(! ioc.stopped())) break; } BEAST_EXPECT(count == 0); @@ -238,7 +238,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -246,8 +246,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add a close frame to the input @@ -265,8 +265,8 @@ public: }); while(! ws.wr_block_) { - ios.run_one(); - if(! BEAST_EXPECT(! ios.stopped())) + ioc.run_one(); + if(! BEAST_EXPECT(! ioc.stopped())) break; } BEAST_EXPECT(count == 0); @@ -279,7 +279,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -287,8 +287,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log, kind::async}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // Cause close to be received @@ -305,8 +305,8 @@ public: }); while(! ws.wr_block_) { - ios.run_one(); - if(! BEAST_EXPECT(! ios.stopped())) + ioc.run_one(); + if(! BEAST_EXPECT(! ioc.stopped())) break; } BEAST_EXPECT(count == 0); @@ -319,7 +319,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -328,8 +328,8 @@ public: { echo_server es{log}; error_code ec; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -359,14 +359,14 @@ public: BOOST_THROW_EXCEPTION( system_error{ec}); }); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 3); }); { echo_server es{log, kind::async}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); @@ -394,7 +394,7 @@ public: ec.message()); }); }); - if(! BEAST_EXPECT(run_until(ios, 100, + if(! BEAST_EXPECT(run_until(ioc, 100, [&]{ return ws.wr_close_; }))) return; // Try to ping @@ -422,10 +422,10 @@ public: { if(count >= 4) break; - ios.run_one(); + ioc.run_one(); } BEAST_EXPECT(n < limit); - ios.run(); + ioc.run(); } } @@ -437,7 +437,7 @@ public: void operator()(error_code) {} }; - stream ws{ios_}; + stream ws{ioc_}; stream::ping_op op{ handler{}, ws, detail::opcode::ping, {}}; using boost::asio::asio_handler_is_continuation; diff --git a/test/beast/websocket/read.cpp b/test/beast/websocket/read.cpp index 33077a33..577fb554 100644 --- a/test/beast/websocket/read.cpp +++ b/test/beast/websocket/read.cpp @@ -76,7 +76,7 @@ public: // already closed { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.close({}); @@ -236,8 +236,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log, kind::async}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // Cause close to be received @@ -252,7 +252,7 @@ public: BOOST_THROW_EXCEPTION( system_error{ec}); }); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 1); }); @@ -375,7 +375,7 @@ public: [&](error_code ev, string_view s) { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); w.handshake(ws, "localhost", "/"); ws.next_layer().append(s); @@ -619,7 +619,7 @@ public: [&](error_code ev, string_view s) { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.next_layer().append(s); @@ -657,8 +657,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -671,7 +671,7 @@ public: BEAST_EXPECT(++count == 1); }); while(! ws.rd_block_) - ios.run_one(); + ioc.run_one(); multi_buffer b; ws.async_read(b, [&](error_code ec, std::size_t) @@ -681,7 +681,7 @@ public: system_error{ec}); BEAST_EXPECT(++count == 2); }); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); #endif @@ -691,8 +691,8 @@ public: { //log << "fc.count()==" << fc.count() << std::endl; echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -714,7 +714,7 @@ public: system_error{ec}); BEAST_EXPECT(++count == 1); }); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -723,8 +723,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // insert a ping @@ -753,7 +753,7 @@ public: ++count; }); BEAST_EXPECT(ws.wr_block_); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -761,8 +761,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -801,7 +801,7 @@ public: BEAST_EXPECT(++count == 2); }); BEAST_EXPECT(ws.wr_block_); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 3); }); @@ -809,8 +809,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -839,7 +839,7 @@ public: BEAST_EXPECT(++count == 1); }); BEAST_EXPECT(ws.wr_block_); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); #endif @@ -852,8 +852,8 @@ public: [&](string_view s) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.next_layer().append(s); @@ -866,8 +866,8 @@ public: // chopped frame header { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.next_layer().append( @@ -883,10 +883,10 @@ public: BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(to_string(b.data()) == s); }); - ios.run_one(); + ioc.run_one(); es.stream().write_some( boost::asio::buffer("\x01" + s)); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 1); } @@ -923,8 +923,8 @@ public: // unmasked frame from client { echo_server es{log, kind::async_client}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); es.async_handshake(); ws.accept(); @@ -942,8 +942,8 @@ public: // chopped control frame payload { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.next_layer().append( @@ -958,11 +958,11 @@ public: BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(to_string(b.data()) == "**"); }); - ios.run_one(); + ioc.run_one(); es.stream().write_some( boost::asio::buffer( "*" "\x81\x02**")); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 1); } @@ -981,11 +981,11 @@ public: }; char buf[32]; - stream ws{ios_}; + stream ws{ioc_}; stream::read_some_op< - boost::asio::mutable_buffers_1, + boost::asio::mutable_buffer, handler> op{handler{}, ws, - boost::asio::mutable_buffers_1{ + boost::asio::mutable_buffer{ buf, sizeof(buf)}}; using boost::asio::asio_handler_is_continuation; asio_handler_is_continuation(&op); @@ -998,7 +998,7 @@ public: }; multi_buffer b; - stream ws{ios_}; + stream ws{ioc_}; stream::read_op< multi_buffer, handler> op{ handler{}, ws, b, 32, true}; @@ -1014,8 +1014,8 @@ public: for(std::size_t i = 0; i < 100; ++i) { echo_server es{log, kind::async}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // too-big message frame indicates payload of 2^64-1 @@ -1033,14 +1033,14 @@ public: testIssue807() { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.write(sbuf("Hello, world!")); char buf[4]; - boost::asio::mutable_buffers_1 cb{buf, 0}; - auto const n = ws.read_some(cb); + boost::asio::mutable_buffer b{buf, 0}; + auto const n = ws.read_some(b); BEAST_EXPECT(n == 0); } diff --git a/test/beast/websocket/stream.cpp b/test/beast/websocket/stream.cpp index 17132b64..1367b567 100644 --- a/test/beast/websocket/stream.cpp +++ b/test/beast/websocket/stream.cpp @@ -22,7 +22,7 @@ public: void testOptions() { - stream ws{ios_}; + stream ws{ioc_}; ws.auto_fragment(true); ws.write_buffer_size(2048); ws.binary(false); @@ -40,7 +40,7 @@ public: auto const bad = [&](permessage_deflate const& pmd) { - stream ws{ios_}; + stream ws{ioc_}; try { ws.set_option(pmd); @@ -105,7 +105,7 @@ public: run() override { BOOST_STATIC_ASSERT(std::is_constructible< - stream, boost::asio::io_service&>::value); + stream, boost::asio::io_context&>::value); BOOST_STATIC_ASSERT(std::is_move_constructible< stream>::value); diff --git a/test/beast/websocket/test.hpp b/test/beast/websocket/test.hpp index fb9f0794..739657eb 100644 --- a/test/beast/websocket/test.hpp +++ b/test/beast/websocket/test.hpp @@ -10,12 +10,14 @@ #ifndef BEAST_TEST_WEBSOCKET_TEST_HPP #define BEAST_TEST_WEBSOCKET_TEST_HPP +#include #include #include #include #include #include #include +#include #include #include #include @@ -51,9 +53,10 @@ public: }; std::ostream& log_; - boost::asio::io_service ios_; + boost::asio::io_context ioc_; boost::optional< - boost::asio::io_service::work> work_; + boost::asio::executor_work_guard< + boost::asio::io_context::executor_type>> work_; static_buffer buffer_; test::stream ts_; std::thread t_; @@ -66,8 +69,8 @@ public: std::ostream& log, kind k = kind::sync) : log_(log) - , work_(ios_) - , ts_(ios_) + , work_(ioc_.get_executor()) + , ts_(ioc_) , ws_(ts_) { permessage_deflate pmd; @@ -83,12 +86,12 @@ public: break; case kind::async: - t_ = std::thread{[&]{ ios_.run(); }}; + t_ = std::thread{[&]{ ioc_.run(); }}; do_accept(); break; case kind::async_client: - t_ = std::thread{[&]{ ios_.run(); }}; + t_ = std::thread{[&]{ ioc_.run(); }}; break; } } @@ -118,7 +121,7 @@ public: void async_close() { - ios_.post( + boost::asio::post(ioc_, [&] { if(ws_.is_open()) @@ -293,7 +296,7 @@ public: doFailLoop( [&](test::fail_counter& fc) { - test::stream ts{ios_, fc}; + test::stream ts{ioc_, fc}; f(ts); ts.close(); } @@ -316,7 +319,7 @@ public: for(n = 0; n < limit; ++n) { test::fail_counter fc{n}; - test::stream ts{ios_, fc}; + test::stream ts{ioc_, fc}; ws_type ws{ts}; ws.set_option(pmd); @@ -363,13 +366,12 @@ public: std::string to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + for(auto b : beast::detail::buffers_range(bs)) + s.append( + reinterpret_cast(b.data()), + b.size()); return s; } @@ -413,10 +415,10 @@ public: template static - boost::asio::const_buffers_1 + boost::asio::const_buffer sbuf(const char (&s)[N]) { - return boost::asio::const_buffers_1(&s[0], N-1); + return boost::asio::const_buffer(&s[0], N-1); } template< @@ -436,14 +438,14 @@ public: template bool - run_until(boost::asio::io_service& ios, + run_until(boost::asio::io_context& ioc, std::size_t limit, Pred&& pred) { for(std::size_t i = 0; i < limit; ++i) { if(pred()) return true; - ios.run_one(); + ioc.run_one(); } return false; } @@ -451,9 +453,9 @@ public: template bool run_until( - boost::asio::io_service& ios, Pred&& pred) + boost::asio::io_context& ioc, Pred&& pred) { - return run_until(ios, 100, pred); + return run_until(ioc, 100, pred); } inline diff --git a/test/beast/websocket/utf8_checker.cpp b/test/beast/websocket/utf8_checker.cpp index 3e94f4ce..45394e57 100644 --- a/test/beast/websocket/utf8_checker.cpp +++ b/test/beast/websocket/utf8_checker.cpp @@ -230,7 +230,7 @@ public: void testFourByteSequence() { - using boost::asio::const_buffers_1; + using boost::asio::const_buffer; utf8_checker utf8; std::uint8_t buf[4]; for(auto i = 240; i <= 244; ++i) @@ -364,7 +364,6 @@ public: void testWithStreamBuffer() { - using namespace boost::asio; { // Valid UTF8 encoded text std::vector> const data{{ @@ -395,13 +394,14 @@ public: static std::size_t constexpr size = 3; std::size_t n = s.size(); buffers_suffix< - boost::asio::const_buffers_1> cb{ - boost::asio::const_buffers_1(s.data(), n)}; + boost::asio::const_buffer> cb{ + boost::asio::const_buffer(s.data(), n)}; multi_buffer b; while(n) { auto const amount = (std::min)(n, size); - b.commit(buffer_copy(b.prepare(amount), cb)); + b.commit(boost::asio::buffer_copy( + b.prepare(amount), cb)); cb.consume(amount); n -= amount; } diff --git a/test/beast/websocket/write.cpp b/test/beast/websocket/write.cpp index d45f9f84..afa52700 100644 --- a/test/beast/websocket/write.cpp +++ b/test/beast/websocket/write.cpp @@ -32,7 +32,7 @@ public: // already closed { echo_server es{log}; - stream ws{ios_}; + stream ws{ioc_}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); ws.close({}); @@ -255,8 +255,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -280,7 +280,7 @@ public: BEAST_EXPECT(n == 1); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -288,8 +288,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -312,7 +312,7 @@ public: system_error{ec}); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -320,8 +320,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); // add a ping and message to the input @@ -339,8 +339,8 @@ public: }); while(! ws.wr_block_) { - ios.run_one(); - if(! BEAST_EXPECT(! ios.stopped())) + ioc.run_one(); + if(! BEAST_EXPECT(! ioc.stopped())) break; } BEAST_EXPECT(count == 0); @@ -354,7 +354,7 @@ public: BEAST_EXPECT(n == 1); }); BEAST_EXPECT(count == 0); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -362,8 +362,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log, kind::async_client}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); es.async_handshake(); ws.accept(); @@ -388,7 +388,7 @@ public: BOOST_THROW_EXCEPTION( system_error{ec}); }); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -396,8 +396,8 @@ public: doFailLoop([&](test::fail_counter& fc) { echo_server es{log, kind::async_client}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); es.async_handshake(); ws.accept(); @@ -422,7 +422,7 @@ public: BOOST_THROW_EXCEPTION( system_error{ec}); }); - ios.run(); + ioc.run(); BEAST_EXPECT(count == 2); }); @@ -431,8 +431,8 @@ public: { echo_server es{log}; error_code ec; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -456,7 +456,7 @@ public: BOOST_THROW_EXCEPTION( system_error{ec}); }); - ios.run(); + ioc.run(); }); // suspend on ping: mask, frag @@ -464,8 +464,8 @@ public: { echo_server es{log}; error_code ec; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; ws.next_layer().connect(es.stream()); ws.handshake("localhost", "/"); std::size_t count = 0; @@ -489,15 +489,15 @@ public: BOOST_THROW_EXCEPTION( system_error{ec}); }); - ios.run(); + ioc.run(); }); // suspend on ping: deflate doFailLoop([&](test::fail_counter& fc) { echo_server es{log, kind::async}; - boost::asio::io_service ios; - stream ws{ios, fc}; + boost::asio::io_context ioc; + stream ws{ioc, fc}; { permessage_deflate pmd; pmd.client_enable = true; @@ -527,7 +527,7 @@ public: BOOST_THROW_EXCEPTION( system_error{ec}); }); - ios.run(); + ioc.run(); }); } @@ -540,8 +540,8 @@ public: { echo_server es{log, i==1 ? kind::async : kind::sync}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); error_code ec; @@ -557,7 +557,7 @@ public: if(! BEAST_EXPECTS(! ec, ec.message())) break; // - // Destruction of the io_service will cause destruction + // Destruction of the io_context will cause destruction // of the write_some_op without invoking the final handler. // break; @@ -577,8 +577,8 @@ public: { echo_server es{log, i==1 ? kind::async : kind::sync}; - boost::asio::io_service ios; - stream ws{ios}; + boost::asio::io_context ioc; + stream ws{ioc}; ws.next_layer().connect(es.stream()); error_code ec; @@ -602,11 +602,11 @@ public: }; char buf[32]; - stream ws{ios_}; + stream ws{ioc_}; stream::write_some_op< - boost::asio::const_buffers_1, + boost::asio::const_buffer, handler> op{handler{}, ws, true, - boost::asio::const_buffers_1{ + boost::asio::const_buffer{ buf, sizeof(buf)}}; using boost::asio::asio_handler_is_continuation; asio_handler_is_continuation(&op); diff --git a/test/bench/buffers/bench_buffers.cpp b/test/bench/buffers/bench_buffers.cpp index d656f1ce..c6abd05a 100644 --- a/test/bench/buffers/bench_buffers.cpp +++ b/test/bench/buffers/bench_buffers.cpp @@ -67,15 +67,13 @@ public: fill(MutableBufferSequence const& buffers) { std::size_t n = 0; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - for(boost::asio::mutable_buffer buffer : buffers) + for(auto b : beast::detail::buffers_range(buffers)) { std::fill( - buffer_cast(buffer), - buffer_cast(buffer) + - buffer_size(buffer), '\0'); - n += buffer_size(buffer); + reinterpret_cast(b.data()), + reinterpret_cast(b.data()) + + b.size(), '\0'); + n += b.size(); } return n; } diff --git a/test/bench/parser/bench_parser.cpp b/test/bench/parser/bench_parser.cpp index 659fe3f1..3b4a8327 100644 --- a/test/bench/parser/bench_parser.cpp +++ b/test/bench/parser/bench_parser.cpp @@ -42,13 +42,11 @@ public: std::string to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + for(auto b : beast::detail::buffers_range(bs)) + s.append(reinterpret_cast(b.data()), + b.size()); return s; } @@ -172,7 +170,7 @@ public: isRequest, bench_parser> { using mutable_buffers_type = - boost::asio::mutable_buffers_1; + boost::asio::mutable_buffer; void on_request_impl(verb, string_view, diff --git a/test/bench/parser/nodejs_parser.hpp b/test/bench/parser/nodejs_parser.hpp index 2d5a7e73..ada007f0 100644 --- a/test/bench/parser/nodejs_parser.hpp +++ b/test/bench/parser/nodejs_parser.hpp @@ -264,17 +264,15 @@ std::size_t nodejs_basic_parser::write( ConstBufferSequence const& buffers, error_code& ec) { - static_assert(beast::is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::size_t bytes_used = 0; - for(boost::asio::const_buffer buffer : buffers) + for(auto buffer : beast::detail::buffers_range(buffers)) { auto const n = write( - buffer_cast(buffer), - buffer_size(buffer), ec); + reinterpret_cast(buffer.data()), + buffer.size(), ec); if(ec) return 0; bytes_used += n; diff --git a/test/bench/wsload/wsload.cpp b/test/bench/wsload/wsload.cpp index 58f7deaf..34c475ba 100644 --- a/test/bench/wsload/wsload.cpp +++ b/test/bench/wsload/wsload.cpp @@ -39,19 +39,37 @@ namespace ws = boost::beast::websocket; namespace ph = std::placeholders; using error_code = boost::beast::error_code; -class test_buffer : public asio::const_buffers_1 +class test_buffer { char data_[4096]; + boost::asio::const_buffer b_; public: + using const_iterator = + boost::asio::const_buffer const*; + + using value_type = boost::asio::const_buffer; + test_buffer() - : asio::const_buffers_1(data_, sizeof(data_)) + : b_(data_, sizeof(data_)) { std::mt19937_64 rng; std::uniform_int_distribution dist; for(auto& c : data_) c = static_cast(dist(rng)); } + + const_iterator + begin() const + { + return &b_; + } + + const_iterator + end() const + { + return begin() + 1; + } }; class report @@ -96,7 +114,8 @@ class connection std::size_t messages_; report& rep_; test_buffer const& tb_; - asio::io_service::strand strand_; + asio::strand< + asio::io_context::executor_type> strand_; boost::beast::multi_buffer buffer_; std::mt19937_64 rng_; std::size_t count_ = 0; @@ -105,18 +124,18 @@ class connection public: connection( - asio::io_service& ios, + asio::io_context& ioc, tcp::endpoint const& ep, std::size_t messages, bool deflate, report& rep, test_buffer const& tb) - : ws_(ios) + : ws_(ioc) , ep_(ep) , messages_(messages) , rep_(rep) , tb_(tb) - , strand_(ios) + , strand_(ioc.get_executor()) { ws::permessage_deflate pmd; pmd.client_enable = deflate; @@ -274,7 +293,7 @@ main(int argc, char** argv) return EXIT_FAILURE; } - auto const address = ip::address::from_string(argv[1]); + auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); auto const trials = static_cast(std::atoi(argv[3])); auto const messages= static_cast(std::atoi(argv[4])); @@ -286,12 +305,12 @@ main(int argc, char** argv) for(auto i = trials; i != 0; --i) { report rep; - boost::asio::io_service ios{1}; + boost::asio::io_context ioc{1}; for(auto j = workers; j; --j) { auto sp = std::make_shared( - ios, + ioc, tcp::endpoint{address, port}, work, deflate, @@ -304,9 +323,9 @@ main(int argc, char** argv) if(threads > 1) { tv.reserve(threads); - tv.emplace_back([&ios]{ ios.run(); }); + tv.emplace_back([&ioc]{ ioc.run(); }); } - ios.run(); + ioc.run(); for(auto& t : tv) t.join(); auto const elapsed = clock.elapsed(); diff --git a/test/doc/core_examples.cpp b/test/doc/core_examples.cpp index af3fae91..65a985cc 100644 --- a/test/doc/core_examples.cpp +++ b/test/doc/core_examples.cpp @@ -50,7 +50,7 @@ public: testRead() { { - test::stream ts{ios_, "\x16***"}; + test::stream ts{ioc_, "\x16***"}; error_code ec; flat_buffer b; auto const result = detect_ssl(ts, b, ec); @@ -60,7 +60,7 @@ public: yield_to( [&](yield_context yield) { - test::stream ts{ios_, "\x16***"}; + test::stream ts{ioc_, "\x16***"}; error_code ec; flat_buffer b; auto const result = diff --git a/test/doc/core_snippets.cpp b/test/doc/core_snippets.cpp index 728971a8..cf8bb1ef 100644 --- a/test/doc/core_snippets.cpp +++ b/test/doc/core_snippets.cpp @@ -27,12 +27,12 @@ void fxx() // using namespace boost::beast; -boost::asio::io_service ios; -boost::asio::io_service::work work{ios}; -std::thread t{[&](){ ios.run(); }}; +boost::asio::io_context ioc; +auto work = boost::asio::make_work_guard(ioc); +std::thread t{[&](){ ioc.run(); }}; error_code ec; -boost::asio::ip::tcp::socket sock{ios}; +boost::asio::ip::tcp::socket sock{ioc}; //] @@ -40,9 +40,10 @@ boost::asio::ip::tcp::socket sock{ios}; //[snippet_core_2 char const* const host = "www.example.com"; -boost::asio::ip::tcp::resolver r{ios}; -boost::asio::ip::tcp::socket stream{ios}; -boost::asio::connect(stream, r.resolve({host, "http"})); +boost::asio::ip::tcp::resolver r{ioc}; +boost::asio::ip::tcp::socket stream{ioc}; +auto const results = r.resolve(host, "http"); +boost::asio::connect(stream, results.begin(), results.end()); // At this point `stream` is a connected to a remote // host and may be used to perform stream operations. @@ -59,7 +60,7 @@ void write_string(SyncWriteStream& stream, string_view s) { static_assert(is_sync_write_stream::value, "SyncWriteStream requirements not met"); - boost::asio::write(stream, boost::asio::const_buffers_1(s.data(), s.size())); + boost::asio::write(stream, boost::asio::const_buffer(s.data(), s.size())); } //] diff --git a/test/doc/exemplars.cpp b/test/doc/exemplars.cpp index 98d90ad8..e97d6852 100644 --- a/test/doc/exemplars.cpp +++ b/test/doc/exemplars.cpp @@ -53,7 +53,7 @@ struct BodyReader { public: /// The type of buffer returned by `get`. - using const_buffers_type = boost::asio::const_buffers_1; + using const_buffers_type = boost::asio::const_buffer; /** Construct the reader. diff --git a/test/doc/http_examples.cpp b/test/doc/http_examples.cpp index afee4b08..4aac72ad 100644 --- a/test/doc/http_examples.cpp +++ b/test/doc/http_examples.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -57,13 +58,11 @@ public: std::string to_string(ConstBufferSequence const& bs) { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; std::string s; s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); + for(auto b : beast::detail::buffers_range(bs)) + s.append(reinterpret_cast< + char const*>(b.data()), b.size()); return s; } @@ -71,7 +70,7 @@ public: bool equal_body(string_view sv, string_view body) { - test::stream ts{ios_, sv}; + test::stream ts{ioc_, sv}; message m; multi_buffer b; ts.close_remote(); @@ -90,7 +89,7 @@ public: void doExpect100Continue() { - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); yield_to( [&](yield_context) @@ -123,10 +122,10 @@ public: doCgiResponse() { std::string const s = "Hello, world!"; - test::stream t0{ios_, s}; + test::stream t0{ioc_, s}; t0.read_size(3); t0.close_remote(); - test::stream t1{ios_}, t1r{ios_}; + test::stream t1{ioc_}, t1r{ioc_}; t1.connect(t1r); error_code ec; send_cgi_response(t0, t1, ec); @@ -145,10 +144,10 @@ public: req.body() = "Hello, world!"; req.prepare_payload(); - test::stream ds{ios_}, dsr{ios_}; + test::stream ds{ioc_}, dsr{ioc_}; ds.connect(dsr); dsr.read_size(3); - test::stream us{ios_}, usr{ios_}; + test::stream us{ioc_}, usr{ioc_}; us.connect(usr); us.write_size(3); @@ -241,7 +240,7 @@ public: void doHEAD() { - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); yield_to( [&](yield_context) @@ -280,7 +279,7 @@ public: void doDeferredBody() { - test::stream ts(ios_, + test::stream ts(ioc_, "POST / HTTP/1.1\r\n" "User-Agent: test\r\n" "Content-Type: multipart/form-data\r\n" @@ -299,7 +298,7 @@ public: void doIncrementalRead() { - test::stream ts{ios_}; + test::stream ts{ioc_}; std::string s(2048, '*'); ostream(ts.buffer()) << "HTTP/1.1 200 OK\r\n" @@ -323,10 +322,10 @@ public: auto const buf = [](string_view s) { - return boost::asio::const_buffers_1{ + return boost::asio::const_buffer{ s.data(), s.size()}; }; - test::stream ts{ios_}, tr{ios_}; + test::stream ts{ioc_}, tr{ioc_}; ts.connect(tr); response res{status::ok, 11}; @@ -394,7 +393,7 @@ public: void doExplicitChunkParse() { - test::stream ts(ios_, + test::stream ts(ioc_, "HTTP/1.1 200 OK\r\n" "Server: test\r\n" "Trailer: Expires, Content-MD5\r\n" diff --git a/test/doc/http_snippets.cpp b/test/doc/http_snippets.cpp index d2ec807f..ad930c4a 100644 --- a/test/doc/http_snippets.cpp +++ b/test/doc/http_snippets.cpp @@ -26,20 +26,20 @@ namespace doc_http_snippets { //[http_snippet_17 // This function returns the buffer containing the next chunk body -boost::asio::const_buffers_1 get_next_chunk_body(); +boost::asio::const_buffer get_next_chunk_body(); //] -boost::asio::const_buffers_1 get_next_chunk_body() +boost::asio::const_buffer get_next_chunk_body() { return {nullptr, 0}; } void fxx() { - boost::asio::io_service ios; - boost::asio::io_service::work work{ios}; - std::thread t{[&](){ ios.run(); }}; - boost::asio::ip::tcp::socket sock{ios}; + boost::asio::io_context ioc; + auto work = boost::asio::make_work_guard(ioc); + std::thread t{[&](){ ioc.run(); }}; + boost::asio::ip::tcp::socket sock{ioc}; { //[http_snippet_2 @@ -270,7 +270,7 @@ void fxx() { "Content-MD5: f4a5c16584f03d90\r\n" "Expires: never\r\n" "\r\n"; - boost::asio::write(sock, make_chunk_last(boost::asio::const_buffers_1{ext.data(), ext.size()})); + boost::asio::write(sock, make_chunk_last(boost::asio::const_buffer{ext.data(), ext.size()})); //] } diff --git a/test/doc/websocket_snippets.cpp b/test/doc/websocket_snippets.cpp index 92d6a787..4b1cc1e4 100644 --- a/test/doc/websocket_snippets.cpp +++ b/test/doc/websocket_snippets.cpp @@ -27,15 +27,15 @@ namespace doc_ws_snippets { void fxx() { -boost::asio::io_service ios; -boost::asio::io_service::work work{ios}; -std::thread t{[&](){ ios.run(); }}; +boost::asio::io_context ioc; +auto work = boost::asio::make_work_guard(ioc); +std::thread t{[&](){ ioc.run(); }}; error_code ec; -boost::asio::ip::tcp::socket sock{ios}; +boost::asio::ip::tcp::socket sock{ioc}; { //[ws_snippet_2 - stream ws{ios}; + stream ws{ioc}; //] } @@ -58,22 +58,23 @@ boost::asio::ip::tcp::socket sock{ios}; { //[ws_snippet_6 std::string const host = "mywebapp.com"; - boost::asio::ip::tcp::resolver r{ios}; - stream ws{ios}; - boost::asio::connect(ws.next_layer(), r.resolve({host, "ws"})); + boost::asio::ip::tcp::resolver r{ioc}; + stream ws{ioc}; + auto const results = r.resolve(host, "ws"); + boost::asio::connect(ws.next_layer(), results.begin(), results.end()); //] } { //[ws_snippet_7 - boost::asio::ip::tcp::acceptor acceptor{ios}; - stream ws{acceptor.get_io_service()}; + boost::asio::ip::tcp::acceptor acceptor{ioc}; + stream ws{acceptor.get_executor().context()}; acceptor.accept(ws.next_layer()); //] } { - stream ws{ios}; + stream ws{ioc}; //[ws_snippet_8 ws.handshake("localhost", "/"); //] @@ -137,7 +138,7 @@ boost::asio::ip::tcp::socket sock{ios}; } { - stream ws{ios}; + stream ws{ioc}; //[ws_snippet_14 // Read into our buffer until we reach the end of the HTTP request. // No parsing takes place here, we are just accumulating data. @@ -149,7 +150,7 @@ boost::asio::ip::tcp::socket sock{ios}; //] } { - stream ws{ios}; + stream ws{ioc}; //[ws_snippet_15 multi_buffer buffer; ws.read(buffer); @@ -161,7 +162,7 @@ boost::asio::ip::tcp::socket sock{ios}; } { - stream ws{ios}; + stream ws{ioc}; //[ws_snippet_16 multi_buffer buffer; for(;;) @@ -187,7 +188,7 @@ boost::asio::ip::tcp::socket sock{ios}; } { - stream ws{ios}; + stream ws{ioc}; //[ws_snippet_17 auto cb = [](frame_type kind, string_view payload) @@ -325,16 +326,16 @@ namespace doc_wss_snippets { void fxx() { -boost::asio::io_service ios; -boost::asio::io_service::work work{ios}; -std::thread t{[&](){ ios.run(); }}; +boost::asio::io_context ioc; +auto work = boost::asio::make_work_guard(ioc); +std::thread t{[&](){ ioc.run(); }}; error_code ec; -boost::asio::ip::tcp::socket sock{ios}; +boost::asio::ip::tcp::socket sock{ioc}; { //[wss_snippet_2 boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23}; - stream> wss{ios, ctx}; + stream> wss{ioc, ctx}; //] } @@ -342,7 +343,7 @@ boost::asio::ip::tcp::socket sock{ios}; //[wss_snippet_3 boost::asio::ip::tcp::endpoint ep; boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23}; - stream> ws{ios, ctx}; + stream> ws{ioc, ctx}; // connect the underlying TCP/IP socket ws.next_layer().next_layer().connect(ep); diff --git a/test/example/common/CMakeLists.txt b/test/example/common/CMakeLists.txt index a581c306..dff2123e 100644 --- a/test/example/common/CMakeLists.txt +++ b/test/example/common/CMakeLists.txt @@ -22,6 +22,5 @@ add_executable (tests-example-common server_certificate.cpp session_alloc.cpp ssl_stream.cpp - write_msg.cpp main.cpp ) diff --git a/test/example/common/Jamfile b/test/example/common/Jamfile index d5e58c98..719deba0 100644 --- a/test/example/common/Jamfile +++ b/test/example/common/Jamfile @@ -13,7 +13,6 @@ local SOURCES = server_certificate.cpp session_alloc.cpp ssl_stream.cpp - write_msg.cpp ; local RUN_TESTS ; diff --git a/test/example/common/write_msg.cpp b/test/example/common/write_msg.cpp deleted file mode 100644 index e7b1bf30..00000000 --- a/test/example/common/write_msg.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// -// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail 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) -// -// Official repository: https://github.com/boostorg/beast -// - -// Test that header file is self-contained. -#include "example/common/write_msg.hpp" - diff --git a/test/extras/include/boost/beast/test/sig_wait.hpp b/test/extras/include/boost/beast/test/sig_wait.hpp index cb2ded45..847dc95b 100644 --- a/test/extras/include/boost/beast/test/sig_wait.hpp +++ b/test/extras/include/boost/beast/test/sig_wait.hpp @@ -21,14 +21,14 @@ inline void sig_wait() { - boost::asio::io_service ios; + boost::asio::io_context ioc; boost::asio::signal_set signals( - ios, SIGINT, SIGTERM); + ioc, SIGINT, SIGTERM); signals.async_wait( [&](boost::system::error_code const&, int) { }); - ios.run(); + ioc.run(); } } // test diff --git a/test/extras/include/boost/beast/test/stream.hpp b/test/extras/include/boost/beast/test/stream.hpp index c1228228..3352b988 100644 --- a/test/extras/include/boost/beast/test/stream.hpp +++ b/test/extras/include/boost/beast/test/stream.hpp @@ -10,15 +10,17 @@ #ifndef BOOST_BEAST_TEST_STREAM_HPP #define BOOST_BEAST_TEST_STREAM_HPP -#include #include +#include #include #include #include #include #include +#include #include -#include +#include +#include #include #include #include @@ -68,7 +70,7 @@ class stream flat_buffer b; std::condition_variable cv; std::unique_ptr op; - boost::asio::io_service& ios; + boost::asio::io_context& ioc; status code = status::ok; fail_counter* fc = nullptr; std::size_t nread = 0; @@ -85,9 +87,9 @@ class stream explicit state( - boost::asio::io_service& ios_, + boost::asio::io_context& ioc_, fail_counter* fc_) - : ios(ios_) + : ioc(ioc_) , fc(fc_) { } @@ -139,7 +141,7 @@ public: stream(stream&& other) { auto in = std::make_shared( - other.in_->ios, other.in_->fc); + other.in_->ioc, other.in_->fc); in_ = std::move(other.in_); out_ = std::move(other.out_); other.in_ = in; @@ -150,7 +152,7 @@ public: operator=(stream&& other) { auto in = std::make_shared( - other.in_->ios, other.in_->fc); + other.in_->ioc, other.in_->fc); in_ = std::move(other.in_); out_ = std::move(other.out_); other.in_ = in; @@ -159,24 +161,24 @@ public: /// Constructor explicit - stream(boost::asio::io_service& ios) - : in_(std::make_shared(ios, nullptr)) + stream(boost::asio::io_context& ioc) + : in_(std::make_shared(ioc, nullptr)) { } /// Constructor stream( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, fail_counter& fc) - : in_(std::make_shared(ios, &fc)) + : in_(std::make_shared(ioc, &fc)) { } /// Constructor stream( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, string_view s) - : in_(std::make_shared(ios, nullptr)) + : in_(std::make_shared(ioc, nullptr)) { using boost::asio::buffer; using boost::asio::buffer_copy; @@ -187,10 +189,10 @@ public: /// Constructor stream( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, fail_counter& fc, string_view s) - : in_(std::make_shared(ios, &fc)) + : in_(std::make_shared(ioc, &fc)) { using boost::asio::buffer; using boost::asio::buffer_copy; @@ -209,12 +211,16 @@ public: remote.out_ = in_; } - /// Return the `io_service` associated with the stream - boost::asio::io_service& - get_io_service() + /// The type of the executor associated with the object. + using executor_type = + boost::asio::io_context::executor_type; + + /// Return the executor associated with the object. + boost::asio::io_context::executor_type + get_executor() noexcept { - return in_->ios; - } + return in_->ioc.get_executor(); + }; /** Get a reference to the lowest layer @@ -269,11 +275,11 @@ public: string_view str() const { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return { - buffer_cast(*in_->b.data().begin()), - buffer_size(*in_->b.data().begin())}; + auto const bs = in_->b.data(); + if(boost::asio::buffer_size(bs) == 0) + return {}; + auto const b = buffers_front(bs); + return {reinterpret_cast(b.data()), b.size()}; } /// Appends a string to the pending input data @@ -336,8 +342,8 @@ public: error_code& ec); template - async_return_type< - ReadHandler, void(error_code, std::size_t)> + BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) async_read_some(MutableBufferSequence const& buffers, ReadHandler&& handler); @@ -351,8 +357,8 @@ public: ConstBufferSequence const& buffers, error_code&); template - async_return_type< - WriteHandler, void(error_code, std::size_t)> + BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) async_write_some(ConstBufferSequence const& buffers, WriteHandler&& handler); @@ -405,7 +411,7 @@ std::size_t stream:: read_some(MutableBufferSequence const& buffers) { - static_assert(is_mutable_buffer_sequence< + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); error_code ec; @@ -421,7 +427,7 @@ stream:: read_some(MutableBufferSequence const& buffers, error_code& ec) { - static_assert(is_mutable_buffer_sequence< + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); using boost::asio::buffer_copy; @@ -460,27 +466,31 @@ read_some(MutableBufferSequence const& buffers, } template -async_return_type< - ReadHandler, void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + ReadHandler, void(error_code, std::size_t)) stream:: async_read_some( MutableBufferSequence const& buffers, ReadHandler&& handler) { - static_assert(is_mutable_buffer_sequence< + static_assert(boost::asio::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); using boost::asio::buffer_copy; using boost::asio::buffer_size; BOOST_ASSERT(buffer_size(buffers) > 0); - async_completion init{handler}; if(in_->fc) { error_code ec; if(in_->fc->fail(ec)) - return in_->ios.post(bind_handler( - init.completion_handler, ec, 0)); + return boost::asio::post( + in_->ioc.get_executor(), + bind_handler( + init.completion_handler, + ec, + 0)); } { std::unique_lock lock{in_->m}; @@ -493,8 +503,12 @@ async_read_some( in_->b.consume(bytes_transferred); lock.unlock(); ++in_->nread; - in_->ios.post(bind_handler(init.completion_handler, - error_code{}, bytes_transferred)); + boost::asio::post( + in_->ioc.get_executor(), + bind_handler( + init.completion_handler, + error_code{}, + bytes_transferred)); } else if(in_->code != status::ok) { @@ -505,15 +519,19 @@ async_read_some( ec = boost::asio::error::eof; else if(in_->code == status::reset) ec = boost::asio::error::connection_reset; - in_->ios.post(bind_handler( - init.completion_handler, ec, 0)); + boost::asio::post( + in_->ioc.get_executor(), + bind_handler( + init.completion_handler, + ec, + 0)); } else { - in_->op.reset(new read_op_impl, - MutableBufferSequence>{*in_, buffers, - init.completion_handler}); + in_->op.reset(new read_op_impl{*in_, buffers, + init.completion_handler}); } } return init.result.get(); @@ -524,7 +542,7 @@ std::size_t stream:: write_some(ConstBufferSequence const& buffers) { - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); error_code ec; @@ -541,7 +559,7 @@ stream:: write_some( ConstBufferSequence const& buffers, error_code& ec) { - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); using boost::asio::buffer_copy; @@ -569,31 +587,38 @@ write_some( } template -async_return_type< - WriteHandler, void(error_code, std::size_t)> +BOOST_ASIO_INITFN_RESULT_TYPE( + WriteHandler, void(error_code, std::size_t)) stream:: async_write_some(ConstBufferSequence const& buffers, WriteHandler&& handler) { - static_assert(is_const_buffer_sequence< + static_assert(boost::asio::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); using boost::asio::buffer_copy; using boost::asio::buffer_size; - async_completion init{handler}; auto out = out_.lock(); if(! out) - return in_->ios.post( - bind_handler(init.completion_handler, - boost::asio::error::connection_reset, 0)); + return boost::asio::post( + in_->ioc.get_executor(), + bind_handler( + init.completion_handler, + boost::asio::error::connection_reset, + 0)); BOOST_ASSERT(out->code == status::ok); if(in_->fc) { error_code ec; if(in_->fc->fail(ec)) - return in_->ios.post(bind_handler( - init.completion_handler, ec, 0)); + return boost::asio::post( + in_->ioc.get_executor(), + bind_handler( + init.completion_handler, + ec, + 0)); } auto const n = (std::min)(buffer_size(buffers), in_->write_max); @@ -604,8 +629,12 @@ async_write_some(ConstBufferSequence const& buffers, out->on_write(); lock.unlock(); ++in_->nwrite; - in_->ios.post(bind_handler(init.completion_handler, - error_code{}, bytes_transferred)); + boost::asio::post( + in_->ioc.get_executor(), + bind_handler( + init.completion_handler, + error_code{}, + bytes_transferred)); return init.result.get(); } @@ -640,7 +669,8 @@ async_teardown( error_code ec; if( s.in_->fc && s.in_->fc->fail(ec)) - return s.get_io_service().post( + return boost::asio::post( + s.get_executor(), bind_handler(std::move(handler), ec)); s.close(); if( s.in_->fc && @@ -649,7 +679,8 @@ async_teardown( else ec.assign(0, ec.category()); - s.get_io_service().post( + boost::asio::post( + s.get_executor(), bind_handler(std::move(handler), ec)); } @@ -664,7 +695,8 @@ class stream::read_op_impl : public stream::read_op Buffers b_; Handler h_; boost::optional< - boost::asio::io_service::work> work_; + boost::asio::executor_work_guard< + boost::asio::io_context::executor_type>> work_; public: lambda(lambda&&) = default; @@ -674,7 +706,7 @@ class stream::read_op_impl : public stream::read_op : s_(s) , b_(b) , h_(std::move(h)) - , work_(s_.ios) + , work_(s_.ioc.get_executor()) { } @@ -682,14 +714,16 @@ class stream::read_op_impl : public stream::read_op : s_(s) , b_(b) , h_(h) - , work_(s_.ios) + , work_(s_.ioc.get_executor()) { } void post() { - s_.ios.post(std::move(*this)); + boost::asio::post( + s_.ioc.get_executor(), + std::move(*this)); work_ = boost::none; } @@ -709,8 +743,12 @@ class stream::read_op_impl : public stream::read_op Handler h{std::move(h_)}; lock.unlock(); ++s.nread; - s.ios.post(bind_handler(std::move(h), - error_code{}, bytes_transferred)); + boost::asio::post( + s.ioc.get_executor(), + bind_handler( + std::move(h), + error_code{}, + bytes_transferred)); } else { @@ -724,7 +762,9 @@ class stream::read_op_impl : public stream::read_op ec = boost::asio::error::eof; else if(s.code == status::reset) ec = boost::asio::error::connection_reset; - s.ios.post(bind_handler(std::move(h), ec, 0)); + boost::asio::post( + s.ioc.get_executor(), + bind_handler(std::move(h), ec, 0)); } } }; @@ -754,7 +794,7 @@ inline stream connect(stream& to) { - stream from{to.get_io_service()}; + stream from{to.get_executor().context()}; from.connect(to); return from; } diff --git a/test/extras/include/boost/beast/test/yield_to.hpp b/test/extras/include/boost/beast/test/yield_to.hpp index b7fb87ce..1fb3738f 100644 --- a/test/extras/include/boost/beast/test/yield_to.hpp +++ b/test/extras/include/boost/beast/test/yield_to.hpp @@ -10,7 +10,7 @@ #ifndef BOOST_BEAST_TEST_YIELD_TO_HPP #define BOOST_BEAST_TEST_YIELD_TO_HPP -#include +#include #include #include #include @@ -32,10 +32,12 @@ namespace test { class enable_yield_to { protected: - boost::asio::io_service ios_; + boost::asio::io_context ioc_; private: - boost::optional work_; + boost::optional< + boost::asio::executor_work_guard< + boost::asio::io_context::executor_type>> work_; std::vector threads_; std::mutex m_; std::condition_variable cv_; @@ -48,12 +50,12 @@ public: explicit enable_yield_to(std::size_t concurrency = 1) - : work_(ios_) + : work_(ioc_.get_executor()) { threads_.reserve(concurrency); while(concurrency--) threads_.emplace_back( - [&]{ ios_.run(); }); + [&]{ ioc_.run(); }); } ~enable_yield_to() @@ -63,11 +65,11 @@ public: t.join(); } - /// Return the `io_service` associated with the object - boost::asio::io_service& + /// Return the `io_context` associated with the object + boost::asio::io_context& get_io_service() { - return ios_; + return ioc_; } /** Run one or more functions, each in a coroutine. @@ -119,7 +121,7 @@ void enable_yield_to:: spawn(F0&& f, FN&&... fn) { - boost::asio::spawn(ios_, + boost::asio::spawn(ioc_, [&](yield_context yield) { f(yield);