James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Vernon Mauery | 076d14a | 2018-10-02 15:10:20 -0700 | [diff] [blame] | 18 | #ifndef BOOST_COROUTINES_NO_DEPRECATION_WARNING |
| 19 | // users should define this if they directly include boost/asio/spawn.hpp, |
| 20 | // but by defining it here, warnings won't cause problems with a compile |
| 21 | #define BOOST_COROUTINES_NO_DEPRECATION_WARNING |
| 22 | #endif |
| 23 | |
Ed Tanous | 38ab5ec | 2020-08-17 17:08:20 -0700 | [diff] [blame] | 24 | #include <boost/asio/async_result.hpp> |
| 25 | #include <boost/asio/io_context.hpp> |
| 26 | #include <boost/asio/posix/stream_descriptor.hpp> |
| 27 | #include <boost/asio/post.hpp> |
Ed Tanous | 1778b12 | 2021-09-13 16:37:40 -0700 | [diff] [blame] | 28 | #ifndef SDBUSPLUS_DISABLE_BOOST_COROUTINES |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 29 | #include <boost/asio/spawn.hpp> |
Ed Tanous | 1778b12 | 2021-09-13 16:37:40 -0700 | [diff] [blame] | 30 | #endif |
Patrick Venture | 95269db | 2018-08-31 09:19:17 -0700 | [diff] [blame] | 31 | #include <boost/callable_traits.hpp> |
Patrick Venture | 95269db | 2018-08-31 09:19:17 -0700 | [diff] [blame] | 32 | #include <sdbusplus/asio/detail/async_send_handler.hpp> |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 33 | #include <sdbusplus/message.hpp> |
| 34 | #include <sdbusplus/utility/read_into_tuple.hpp> |
| 35 | #include <sdbusplus/utility/type_traits.hpp> |
Patrick Williams | 127b8ab | 2020-05-21 15:24:19 -0500 | [diff] [blame] | 36 | |
| 37 | #include <chrono> |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 38 | #include <string> |
James Feist | c14699f | 2019-06-04 14:11:48 -0700 | [diff] [blame] | 39 | #include <tuple> |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 40 | |
| 41 | namespace sdbusplus |
| 42 | { |
| 43 | |
| 44 | namespace asio |
| 45 | { |
| 46 | |
| 47 | /// Root D-Bus IO object |
| 48 | /** |
| 49 | * A connection to a bus, through which messages may be sent or received. |
| 50 | */ |
Patrick Williams | 0f282c4 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 51 | class connection : public sdbusplus::bus_t |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 52 | { |
| 53 | public: |
| 54 | // default to system bus |
Ed Tanous | c7d104d | 2019-01-02 14:15:50 -0800 | [diff] [blame] | 55 | connection(boost::asio::io_context& io) : |
Patrick Williams | fdfd3af | 2023-05-11 14:44:03 -0500 | [diff] [blame] | 56 | sdbusplus::bus_t(sdbusplus::bus::new_default()), io_(io), |
| 57 | socket(io_.get_executor(), get_fd()) |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 58 | { |
Rahul Kapoor | 894d6ca | 2023-11-21 20:05:27 +0000 | [diff] [blame^] | 59 | read_immediate(); |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 60 | } |
Ed Tanous | c7d104d | 2019-01-02 14:15:50 -0800 | [diff] [blame] | 61 | connection(boost::asio::io_context& io, sd_bus* bus) : |
Patrick Williams | fdfd3af | 2023-05-11 14:44:03 -0500 | [diff] [blame] | 62 | sdbusplus::bus_t(bus), io_(io), socket(io_.get_executor(), get_fd()) |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 63 | { |
Rahul Kapoor | 894d6ca | 2023-11-21 20:05:27 +0000 | [diff] [blame^] | 64 | read_immediate(); |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 65 | } |
| 66 | ~connection() |
| 67 | { |
| 68 | // The FD will be closed by the socket object, so assign null to the |
| 69 | // sd_bus object to avoid a double close() Ignore return codes here, |
| 70 | // because there's nothing we can do about errors |
| 71 | socket.release(); |
| 72 | } |
| 73 | |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 74 | /** @brief Perform an asynchronous send of a message, executing the handler |
| 75 | * upon return and return |
| 76 | * |
| 77 | * @param[in] m - A message ready to send |
Ed Tanous | ddc57bd | 2023-01-05 10:47:32 -0800 | [diff] [blame] | 78 | * @param[in] token - The completion token to execute upon completion; |
| 79 | * @param[in] timeout - The timeout in microseconds |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 80 | * |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 81 | */ |
Ed Tanous | 6c97486 | 2022-08-31 13:21:32 -0700 | [diff] [blame] | 82 | template <typename CompletionToken> |
| 83 | inline auto async_send(message_t& m, CompletionToken&& token, |
| 84 | uint64_t timeout = 0) |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 85 | { |
Ed Tanous | 3cc9c30 | 2023-05-30 12:57:31 -0700 | [diff] [blame] | 86 | #ifdef SDBUSPLUS_DISABLE_BOOST_COROUTINES |
| 87 | constexpr bool is_yield = false; |
| 88 | #else |
Ed Tanous | 6c97486 | 2022-08-31 13:21:32 -0700 | [diff] [blame] | 89 | constexpr bool is_yield = |
| 90 | std::is_same_v<CompletionToken, boost::asio::yield_context>; |
Ed Tanous | 3cc9c30 | 2023-05-30 12:57:31 -0700 | [diff] [blame] | 91 | #endif |
Ed Tanous | 6c97486 | 2022-08-31 13:21:32 -0700 | [diff] [blame] | 92 | using return_t = std::conditional_t<is_yield, message_t, message_t&>; |
| 93 | using callback_t = void(boost::system::error_code, return_t); |
| 94 | return boost::asio::async_initiate<CompletionToken, callback_t>( |
| 95 | detail::async_send_handler(get(), m, timeout), token); |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 98 | /** @brief Perform an asynchronous method call, with input parameter packing |
Konrad Sztyber | da0b3f1 | 2020-03-27 16:48:26 +0100 | [diff] [blame] | 99 | * and return value unpacking. |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 100 | * |
| 101 | * @param[in] handler - A function object that is to be called as a |
| 102 | * continuation for the async dbus method call. The |
| 103 | * arguments to parse on the return are deduced from |
| 104 | * the handler's signature and then passed in along |
Patrick Williams | 10d7aa1 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 105 | * with an error code and optional message_t |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 106 | * @param[in] service - The service to call. |
| 107 | * @param[in] objpath - The object's path for the call. |
| 108 | * @param[in] interf - The object's interface to call. |
| 109 | * @param[in] method - The object's method to call. |
Konrad Sztyber | da0b3f1 | 2020-03-27 16:48:26 +0100 | [diff] [blame] | 110 | * @param[in] timeout - The timeout for the method call in usec (0 results |
| 111 | * in using the default value). |
Ed Tanous | ddc57bd | 2023-01-05 10:47:32 -0800 | [diff] [blame] | 112 | * @param[in] a - Optional parameters for the method call. |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 113 | * |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 114 | */ |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 115 | template <typename MessageHandler, typename... InputArgs> |
Konrad Sztyber | da0b3f1 | 2020-03-27 16:48:26 +0100 | [diff] [blame] | 116 | void async_method_call_timed(MessageHandler&& handler, |
| 117 | const std::string& service, |
| 118 | const std::string& objpath, |
| 119 | const std::string& interf, |
| 120 | const std::string& method, uint64_t timeout, |
| 121 | const InputArgs&... a) |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 122 | { |
Vernon Mauery | c079db4 | 2020-02-06 09:22:01 -0800 | [diff] [blame] | 123 | using FunctionTuple = boost::callable_traits::args_t<MessageHandler>; |
Patrick Williams | b16ea98 | 2021-07-14 10:01:52 -0500 | [diff] [blame] | 124 | using FunctionTupleType = utility::decay_tuple_t<FunctionTuple>; |
Vernon Mauery | c079db4 | 2020-02-06 09:22:01 -0800 | [diff] [blame] | 125 | constexpr bool returnWithMsg = []() { |
Patrick Williams | 4b64623 | 2021-02-22 13:50:48 -0600 | [diff] [blame] | 126 | if constexpr ((std::tuple_size_v<FunctionTupleType>) > 1) |
Vernon Mauery | c079db4 | 2020-02-06 09:22:01 -0800 | [diff] [blame] | 127 | { |
| 128 | return std::is_same_v< |
| 129 | std::tuple_element_t<1, FunctionTupleType>, |
Patrick Williams | 10d7aa1 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 130 | sdbusplus::message_t>; |
Vernon Mauery | c079db4 | 2020-02-06 09:22:01 -0800 | [diff] [blame] | 131 | } |
| 132 | return false; |
| 133 | }(); |
Patrick Williams | b16ea98 | 2021-07-14 10:01:52 -0500 | [diff] [blame] | 134 | using UnpackType = utility::strip_first_n_args_t<returnWithMsg ? 2 : 1, |
| 135 | FunctionTupleType>; |
Patrick Williams | 6db8838 | 2023-10-20 11:18:17 -0500 | [diff] [blame] | 136 | auto applyHandler = [handler = std::forward<MessageHandler>(handler)]( |
| 137 | boost::system::error_code ec, |
| 138 | message_t& r) mutable { |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 139 | UnpackType responseData; |
| 140 | if (!ec) |
| 141 | { |
Vernon Mauery | c077190 | 2019-05-07 16:53:50 -0700 | [diff] [blame] | 142 | try |
| 143 | { |
| 144 | utility::read_into_tuple(responseData, r); |
| 145 | } |
Brad Bishop | 5a6c790 | 2022-09-29 11:05:47 -0400 | [diff] [blame] | 146 | catch (const std::exception&) |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 147 | { |
| 148 | // Set error code if not already set |
| 149 | ec = boost::system::errc::make_error_code( |
| 150 | boost::system::errc::invalid_argument); |
| 151 | } |
| 152 | } |
| 153 | // Note. Callback is called whether or not the unpack was |
Gunnar Mills | 31a4b13 | 2018-08-14 11:59:13 -0500 | [diff] [blame] | 154 | // successful to allow the user to implement their own handling |
Richard Marian Thomaiyar | 4212292 | 2019-07-01 21:31:04 +0530 | [diff] [blame] | 155 | if constexpr (returnWithMsg) |
| 156 | { |
| 157 | auto response = std::tuple_cat(std::make_tuple(ec), |
| 158 | std::forward_as_tuple(r), |
| 159 | std::move(responseData)); |
| 160 | std::apply(handler, response); |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | auto response = std::tuple_cat(std::make_tuple(ec), |
| 165 | std::move(responseData)); |
| 166 | std::apply(handler, response); |
| 167 | } |
Vernon Mauery | c079db4 | 2020-02-06 09:22:01 -0800 | [diff] [blame] | 168 | }; |
Patrick Williams | 10d7aa1 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 169 | message_t m; |
Vernon Mauery | c079db4 | 2020-02-06 09:22:01 -0800 | [diff] [blame] | 170 | boost::system::error_code ec; |
| 171 | try |
| 172 | { |
| 173 | m = new_method_call(service.c_str(), objpath.c_str(), |
| 174 | interf.c_str(), method.c_str()); |
| 175 | m.append(a...); |
| 176 | } |
| 177 | catch (const exception::SdBusError& e) |
| 178 | { |
| 179 | ec = boost::system::errc::make_error_code( |
| 180 | static_cast<boost::system::errc::errc_t>(e.get_errno())); |
| 181 | applyHandler(ec, m); |
| 182 | return; |
| 183 | } |
Konrad Sztyber | da0b3f1 | 2020-03-27 16:48:26 +0100 | [diff] [blame] | 184 | async_send(m, std::forward<decltype(applyHandler)>(applyHandler), |
| 185 | timeout); |
| 186 | } |
| 187 | |
| 188 | /** @brief Perform an asynchronous method call, with input parameter packing |
| 189 | * and return value unpacking. Uses the default timeout value. |
| 190 | * |
| 191 | * @param[in] handler - A function object that is to be called as a |
| 192 | * continuation for the async dbus method call. The |
| 193 | * arguments to parse on the return are deduced from |
| 194 | * the handler's signature and then passed in along |
Patrick Williams | 10d7aa1 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 195 | * with an error code and optional message_t |
Konrad Sztyber | da0b3f1 | 2020-03-27 16:48:26 +0100 | [diff] [blame] | 196 | * @param[in] service - The service to call. |
| 197 | * @param[in] objpath - The object's path for the call. |
| 198 | * @param[in] interf - The object's interface to call. |
| 199 | * @param[in] method - The object's method to call. |
Ed Tanous | ddc57bd | 2023-01-05 10:47:32 -0800 | [diff] [blame] | 200 | * @param[in] a - Optional parameters for the method call. |
Konrad Sztyber | da0b3f1 | 2020-03-27 16:48:26 +0100 | [diff] [blame] | 201 | * |
Konrad Sztyber | da0b3f1 | 2020-03-27 16:48:26 +0100 | [diff] [blame] | 202 | */ |
| 203 | template <typename MessageHandler, typename... InputArgs> |
| 204 | void async_method_call(MessageHandler&& handler, const std::string& service, |
| 205 | const std::string& objpath, |
| 206 | const std::string& interf, const std::string& method, |
| 207 | const InputArgs&... a) |
| 208 | { |
| 209 | async_method_call_timed(std::forward<MessageHandler>(handler), service, |
| 210 | objpath, interf, method, 0, a...); |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Ed Tanous | 1778b12 | 2021-09-13 16:37:40 -0700 | [diff] [blame] | 213 | #ifndef SDBUSPLUS_DISABLE_BOOST_COROUTINES |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 214 | /** @brief Perform a yielding asynchronous method call, with input |
| 215 | * parameter packing and return value unpacking |
| 216 | * |
Vernon Mauery | 37a5e61 | 2019-05-07 16:53:50 -0700 | [diff] [blame] | 217 | * @param[in] yield - A yield context to async block upon. |
| 218 | * @param[in] ec - an error code that will be set for any errors |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 219 | * @param[in] service - The service to call. |
| 220 | * @param[in] objpath - The object's path for the call. |
| 221 | * @param[in] interf - The object's interface to call. |
| 222 | * @param[in] method - The object's method to call. |
Ed Tanous | ddc57bd | 2023-01-05 10:47:32 -0800 | [diff] [blame] | 223 | * @param[in] a - Optional parameters for the method call. |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 224 | * |
| 225 | * @return Unpacked value of RetType |
| 226 | */ |
| 227 | template <typename... RetTypes, typename... InputArgs> |
| 228 | auto yield_method_call(boost::asio::yield_context yield, |
Vernon Mauery | 37a5e61 | 2019-05-07 16:53:50 -0700 | [diff] [blame] | 229 | boost::system::error_code& ec, |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 230 | const std::string& service, |
| 231 | const std::string& objpath, |
| 232 | const std::string& interf, const std::string& method, |
| 233 | const InputArgs&... a) |
| 234 | { |
Patrick Williams | 10d7aa1 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 235 | message_t m; |
Vernon Mauery | c079db4 | 2020-02-06 09:22:01 -0800 | [diff] [blame] | 236 | try |
| 237 | { |
| 238 | m = new_method_call(service.c_str(), objpath.c_str(), |
| 239 | interf.c_str(), method.c_str()); |
| 240 | m.append(a...); |
| 241 | } |
| 242 | catch (const exception::SdBusError& e) |
| 243 | { |
| 244 | ec = boost::system::errc::make_error_code( |
| 245 | static_cast<boost::system::errc::errc_t>(e.get_errno())); |
| 246 | } |
Patrick Williams | 10d7aa1 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 247 | message_t r; |
Vernon Mauery | c079db4 | 2020-02-06 09:22:01 -0800 | [diff] [blame] | 248 | if (!ec) |
| 249 | { |
| 250 | r = async_send(m, yield[ec]); |
| 251 | } |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 252 | if constexpr (sizeof...(RetTypes) == 0) |
| 253 | { |
| 254 | // void return |
| 255 | return; |
| 256 | } |
| 257 | else if constexpr (sizeof...(RetTypes) == 1) |
| 258 | { |
Patrick Williams | 64f0122 | 2021-07-14 10:14:51 -0500 | [diff] [blame] | 259 | if constexpr (std::is_same_v<utility::first_type_t<RetTypes...>, |
| 260 | void>) |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 261 | { |
| 262 | return; |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | // single item return |
Patrick Williams | b16ea98 | 2021-07-14 10:01:52 -0500 | [diff] [blame] | 267 | utility::first_type_t<RetTypes...> responseData{}; |
Vernon Mauery | 37a5e61 | 2019-05-07 16:53:50 -0700 | [diff] [blame] | 268 | // before attempting to read, check ec and bail on error |
| 269 | if (ec) |
| 270 | { |
| 271 | return responseData; |
| 272 | } |
| 273 | try |
| 274 | { |
| 275 | r.read(responseData); |
| 276 | } |
Brad Bishop | 5a6c790 | 2022-09-29 11:05:47 -0400 | [diff] [blame] | 277 | catch (const std::exception&) |
Vernon Mauery | 37a5e61 | 2019-05-07 16:53:50 -0700 | [diff] [blame] | 278 | { |
| 279 | ec = boost::system::errc::make_error_code( |
| 280 | boost::system::errc::invalid_argument); |
| 281 | // responseData will be default-constructed... |
| 282 | } |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 283 | return responseData; |
| 284 | } |
| 285 | } |
| 286 | else |
| 287 | { |
| 288 | // tuple of things to return |
Patrick Williams | 5d4e4b2 | 2020-05-20 21:39:22 -0500 | [diff] [blame] | 289 | std::tuple<RetTypes...> responseData{}; |
Vernon Mauery | 37a5e61 | 2019-05-07 16:53:50 -0700 | [diff] [blame] | 290 | // before attempting to read, check ec and bail on error |
| 291 | if (ec) |
| 292 | { |
| 293 | return responseData; |
| 294 | } |
| 295 | try |
| 296 | { |
| 297 | r.read(responseData); |
| 298 | } |
Brad Bishop | 5a6c790 | 2022-09-29 11:05:47 -0400 | [diff] [blame] | 299 | catch (const std::exception&) |
Vernon Mauery | 37a5e61 | 2019-05-07 16:53:50 -0700 | [diff] [blame] | 300 | { |
| 301 | ec = boost::system::errc::make_error_code( |
| 302 | boost::system::errc::invalid_argument); |
| 303 | // responseData will be default-constructed... |
| 304 | } |
Vernon Mauery | 261e72b | 2018-09-25 12:34:25 -0700 | [diff] [blame] | 305 | return responseData; |
| 306 | } |
| 307 | } |
Ed Tanous | 1778b12 | 2021-09-13 16:37:40 -0700 | [diff] [blame] | 308 | #endif |
Ed Tanous | c7d104d | 2019-01-02 14:15:50 -0800 | [diff] [blame] | 309 | boost::asio::io_context& get_io_context() |
Vernon Mauery | 076d14a | 2018-10-02 15:10:20 -0700 | [diff] [blame] | 310 | { |
| 311 | return io_; |
| 312 | } |
| 313 | |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 314 | private: |
Ed Tanous | c7d104d | 2019-01-02 14:15:50 -0800 | [diff] [blame] | 315 | boost::asio::io_context& io_; |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 316 | boost::asio::posix::stream_descriptor socket; |
| 317 | |
James Feist | b575518 | 2018-07-16 10:30:08 -0700 | [diff] [blame] | 318 | void read_wait() |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 319 | { |
| 320 | socket.async_read_some( |
| 321 | boost::asio::null_buffers(), |
Vernon Mauery | 0c76546 | 2020-12-15 14:36:34 -0800 | [diff] [blame] | 322 | [&](const boost::system::error_code& ec, std::size_t) { |
Patrick Williams | d214904 | 2023-05-10 07:50:13 -0500 | [diff] [blame] | 323 | if (ec) |
| 324 | { |
| 325 | return; |
| 326 | } |
| 327 | if (process_discard()) |
| 328 | { |
| 329 | read_immediate(); |
| 330 | } |
| 331 | else |
| 332 | { |
| 333 | read_wait(); |
| 334 | } |
Patrick Williams | 6db8838 | 2023-10-20 11:18:17 -0500 | [diff] [blame] | 335 | }); |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 336 | } |
James Feist | b575518 | 2018-07-16 10:30:08 -0700 | [diff] [blame] | 337 | void read_immediate() |
| 338 | { |
Ed Tanous | c7d104d | 2019-01-02 14:15:50 -0800 | [diff] [blame] | 339 | boost::asio::post(io_, [&] { |
James Feist | b575518 | 2018-07-16 10:30:08 -0700 | [diff] [blame] | 340 | if (process_discard()) |
| 341 | { |
| 342 | read_immediate(); |
| 343 | } |
| 344 | else |
| 345 | { |
| 346 | read_wait(); |
| 347 | } |
| 348 | }); |
| 349 | } |
James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | } // namespace asio |
| 353 | |
| 354 | } // namespace sdbusplus |