This commit is contained in:
Timur A. Fatkhullin 2024-11-09 23:51:40 +03:00
parent afd1a917b4
commit afa8d09ade
5 changed files with 22 additions and 14 deletions

View File

@ -246,8 +246,9 @@ public:
_netService.asyncReceive(
[self, this](netservice_t::async_callback_err_t ec, message_t msg) {
if (ec) {
_serverPtr->errorMessage(std::string("asyncReceive operation completed with") +
netservice_t::formatError(ec));
std::string str("asyncReceive operation completed with error: ");
netservice_t::formatError(ec, str);
_serverPtr->errorMessage(str);
stop();
} else {
auto msg_sptr = std::make_shared<message_t>(std::move(msg));
@ -260,8 +261,9 @@ public:
*msg_sptr,
[self, msg_sptr, this](netservice_t::async_callback_err_t ec) {
if (ec) {
_serverPtr->errorMessage(std::string("asyncSend operation completed with") +
netservice_t::formatError(ec));
std::string str("asyncSend operation completed with error: ");
netservice_t::formatError(ec, str);
_serverPtr->errorMessage(str);
stop();
} else {
start();
@ -391,9 +393,6 @@ public:
auto id = std::forward<IdSerialT>(id_ser_func)(dev_ptr->ident());
_devices.try_emplace(dev_ptr, dev_ptr, id, std::forward<AttrIdDeserialT>(attr_id_deser_func),
std::forward<CmdIdDeserialT>(cmd_id_deser_func));
// _devices.try_emplace(dev_ptr, dev_ptr, std::forward<IdSerialT>(id_ser_func),
// std::forward<AttrIdDeserialT>(attr_id_deser_func),
// std::forward<CmdIdDeserialT>(cmd_id_deser_func));
return *this;
}

View File

@ -159,6 +159,9 @@ concept adc_netservice_c = requires(SRVT srv, const SRVT srv_const) {
{ srv.receive(std::declval<const typename SRVT::timeout_t&>()) } -> std::same_as<typename SRVT::recv_msg_t>;
srv.close();
// static method
SRVT::formatError(std::declval<typename SRVT::async_callback_err_t>(), std::declval<std::string&>());
};

View File

@ -353,13 +353,16 @@ protected:
_isListening<SessionT>[this][id] = true;
doAccept<SessionT>(acceptor, std::move(id), std::move(sess_ctx));
} else {
errorMessage(SessionT::netservice_t::formatError(ec));
std::string str{"Cannot start accepting connection: "};
SessionT::netservice_t::formatError(ec, str);
errorMessage(str);
_isListening<SessionT>[this][id] = false;
}
});
}
virtual void errorMessage(const std::string&) = 0;
virtual void errorMessage(const std::string&) {};
};

View File

@ -30,6 +30,11 @@ protected:
std::string _serverID;
virtual void errorMessage(const std::string& err_msg)
{
logError(err_msg);
}
public:
using typename ServerT::server_ident_t;

View File

@ -758,12 +758,10 @@ public:
}
template <typename OutputItT, typename FormatT = std::string_view>
static void formatError(std::error_code err,
OutputItT out_iter,
FormatT fmt = "{} (Err category: {}) (Err msg: {})")
static void formatError(std::error_code err, std::string& result_str)
{
std::format_to(out_iter, fmt, err.value(), err.category().name(), err.message());
std::format_to(std::back_inserter(result_str), "{} (Err category: {}) (Err msg: {})", err.value(),
err.category().name(), err.message());
}
protected: