| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/cppalliance/beast2 | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_BEAST2_SERVER_ROUTE_HANDLER_ASIO_HPP | ||
| 11 | #define BOOST_BEAST2_SERVER_ROUTE_HANDLER_ASIO_HPP | ||
| 12 | |||
| 13 | #include <boost/beast2/detail/config.hpp> | ||
| 14 | #include <boost/http_proto/server/route_handler.hpp> | ||
| 15 | #include <boost/asio/post.hpp> | ||
| 16 | #include <type_traits> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace beast2 { | ||
| 20 | |||
| 21 | /** Route parameters object for Asio HTTP route handlers | ||
| 22 | */ | ||
| 23 | template<class AsyncStream> | ||
| 24 | class asio_route_params | ||
| 25 | : public http_proto::route_params | ||
| 26 | { | ||
| 27 | public: | ||
| 28 | using stream_type = typename std::decay<AsyncStream>::type; | ||
| 29 | |||
| 30 | AsyncStream stream; | ||
| 31 | |||
| 32 | template<class... Args> | ||
| 33 | explicit | ||
| 34 | 1 | asio_route_params( | |
| 35 | Args&&... args) | ||
| 36 | 1 | : stream(std::forward<Args>(args)...) | |
| 37 | { | ||
| 38 | 1 | } | |
| 39 | |||
| 40 | private: | ||
| 41 | void do_post() override; | ||
| 42 | }; | ||
| 43 | |||
| 44 | //----------------------------------------------- | ||
| 45 | |||
| 46 | template<class AsyncStream> | ||
| 47 | void | ||
| 48 | ✗ | asio_route_params<AsyncStream>:: | |
| 49 | do_post() | ||
| 50 | { | ||
| 51 | ✗ | asio::post( | |
| 52 | ✗ | stream.get_executor(), | |
| 53 | ✗ | [&] | |
| 54 | { | ||
| 55 | ✗ | if(task_->invoke()) | |
| 56 | ✗ | return; | |
| 57 | ✗ | do_post(); | |
| 58 | }); | ||
| 59 | ✗ | } | |
| 60 | |||
| 61 | } // beast2 | ||
| 62 | } // boost | ||
| 63 | |||
| 64 | #endif | ||
| 65 |