23#include <flow/log/log.hpp>
30template<
bool NO_HNDLS,
typename Batch,
typename Async_rcv_impl_func>
33 const Async_rcv_impl_func& async_rcv_impl_func,
34 const Error_code init_err_code,
size_t init_sz)
36 using flow::async::Task_asio_err_sz;
44 *sync_err_code = init_err_code;
49 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_TRANSPORT);
55 const auto init_n_used = batch->n_used();
56 batch->emulate_result(init_sz);
58 if constexpr(NO_HNDLS)
61 FLOW_LOG_TRACE(
"Msg_batch [" << *batch <<
"]: Emulating async-receive (no-hndls? = yes); "
62 "just recorded init-result into the last slot: n_rcvd [" << init_sz <<
"].");
66 FLOW_LOG_TRACE(
"Msg_batch [" << *batch <<
"]: Emulating async-receive (no-hndls? = no); "
67 "just recorded init-result into the last slot: "
68 "n_rcvd [" << init_sz <<
"]; hndl [" << batch->result_payload_hndl(batch->n_used() - 1) <<
"].");
71 sync_err_code->clear();
74 while ((!err_code) && (!batch->full()))
79 if constexpr(NO_HNDLS)
81 async_rcv_impl_func(
false, batch->next_target_blob(), &err_code, &sz,
86 async_rcv_impl_func(batch->next_target_hndl(),
false, batch->next_target_blob(), &err_code, &sz,
91 && (err_code != boost::asio::error::eof)
108 if constexpr(!NO_HNDLS)
110 for (
auto idx = init_n_used; idx != batch->n_used(); ++idx)
117 batch->result_payload_hndl(idx).close();
121 batch->clear_used(init_n_used);
122 *sync_err_code = err_code;
124 FLOW_LOG_TRACE(
"Msg_batch [" << *batch <<
"]: Due to non-would-block, non-graceful-close "
125 "error [" << err_code <<
"] [" << err_code.message() <<
"] emitting overall batch-receive "
126 "error having rewound the Msg_batch to its pre-op state.");
132 batch->emulate_result(sz);
134 if constexpr(NO_HNDLS)
136 FLOW_LOG_TRACE(
"Msg_batch [" << *batch <<
"]: Emulating async-receive (no-hndls? = yes); "
137 "just recorded tacked-on-result into the last slot: n_rcvd [" << sz <<
"].");
141 FLOW_LOG_TRACE(
"Msg_batch [" << *batch <<
"]: Emulating async-receive (no-hndls? = no); "
142 "just recorded tacked-on-result into the last slot: "
143 "n_rcvd [" << sz <<
"]; hndl [" << batch->result_payload_hndl(batch->n_used() - 1) <<
"].");
@ S_SYNC_IO_WOULD_BLOCK
A sync_io operation could not immediately complete; it will complete contingent on active async-wait ...
@ S_RECEIVES_FINISHED_CANNOT_RECEIVE
Will not receive message: opposing user sent graceful-close via API.
sync_io-pattern counterparts to async-I/O-pattern object types in parent namespace ipc::transport.
void async_receive_batch_emulation_on_init_msg(flow::log::Logger *logger_ptr, Batch *batch, Error_code *sync_err_code, const Async_rcv_impl_func &async_rcv_impl_func, const Error_code init_err_code, size_t init_sz)
Helper for async_receive_batch_emulation() that executes on that call's initial single-message async-...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.