This commit is contained in:
Timur A. Fatkhullin 2024-11-15 12:49:11 +03:00
parent 285f8de1f7
commit 221f595bcb
6 changed files with 23 additions and 16 deletions

View File

@ -53,6 +53,7 @@ set(ADC_NETWORK_HEADERS
# net/adc_netservice.h
net/adc_endpoint.h
net/adc_netserver.h
net/adc_netclient.h
net/adc_net_concepts.h
net/adc_device_netmsg.h
net/adc_device_netserver.h
@ -199,8 +200,12 @@ if (BUILD_TESTS)
# add_test(VALUE_HOLDER ${VALUEHOLDER_TEST_APP})
add_test(VALUE_HOLDER ${DEVATTR_TEST_APP})
add_test(NETMSG_TEST ${NETMSG_TEST_APP})
add_test(ASIO_NETSRV_TEST ${ASIO_NETSERVER_TEST_APP})
if (SPDLOG_LIBRARY)
target_link_libraries(${ASIO_NETSERVER_TEST_APP} PRIVATE fmt::fmt)
endif()
enable_testing()
endif(BUILD_TESTS)

View File

@ -16,7 +16,7 @@ namespace adc
/* SPDLOG-library based advanced single/multithreaded logger */
class AdcSPDLOGLogger
class AdcSpdlogLogger
{
public:
// [year-month-day time.millisecs][log-level]: log-message
@ -25,7 +25,7 @@ public:
typedef spdlog::level::level_enum loglevel_t;
template <traits::adc_input_char_range R = decltype(LOGGER_DEFAULT_FORMAT)>
AdcSPDLOGLogger(std::shared_ptr<spdlog::logger> logger, const R& pattern = LOGGER_DEFAULT_FORMAT)
AdcSpdlogLogger(std::shared_ptr<spdlog::logger> logger, const R& pattern = LOGGER_DEFAULT_FORMAT)
: _loggerSPtr(logger), _currentLogPattern()
{
std::ranges::copy(pattern, std::back_inserter(_currentLogPattern));
@ -33,7 +33,7 @@ public:
}
virtual ~AdcSPDLOGLogger() = default;
virtual ~AdcSpdlogLogger() = default;
void setLogLevel(loglevel_t log_level)
@ -144,6 +144,7 @@ protected:
};
/*
template <typename BaseT>
class AdcSpdlogGenericDecorator : public BaseT
@ -285,7 +286,6 @@ protected:
}
};
template <typename BaseT>
class AdcSpdlogGenericMarkDecorator : public AdcSpdlogGenericDecorator<BaseT>
{
@ -317,7 +317,7 @@ public:
}
};
*/
} // namespace adc
#endif

View File

@ -10,7 +10,6 @@ ABSTRACT DEVICE COMPONENTS LIBRARY
#include <functional>
#include <list>
#include <set>
#include <thread>
#include <unordered_map>
#if __has_include(<unistd.h>) // POSIX
@ -52,8 +51,6 @@ public:
tmp_path = std::filesystem::current_path().root_path();
}
// _ioContext.notify_fork(asio::execution_context::fork_prepare);
if (pid_t pid = fork()) {
if (pid > 0) {
exit(0);
@ -82,7 +79,6 @@ public:
close(1);
close(2);
// _ioContext.notify_fork(asio::io_context::fork_child);
#endif
daemonizeFinalize();
}

View File

@ -106,7 +106,7 @@ public:
std::vector<std::string> vsg;
std::ranges::transform(sig_range, std::back_inserter(vsg),
[](auto s) { return std::format("'{}'", sigdescr_np(s)); });
[](auto s) { return std::format("'{}' (No = {})", sigdescr_np(s), s); });
utils::AdcJoinRange(vsg, std::string_view(", "), sgs);
#else
@ -184,7 +184,8 @@ protected:
virtual void signalReceived(std::error_code ec, int signo)
{
#ifdef _GNU_SOURCE
this->logInfo("The server received the signal: '{}' (ec = {})", sigdescr_np(signo), ec.message());
this->logInfo("The server received the signal: '{}' (No = {}, ec = {})", sigdescr_np(signo), signo,
ec.message());
#else
this->logInfo("The server received the signal: {} (ec = {})", signo, ec.message());
#endif

View File

@ -259,6 +259,8 @@ public:
timer->cancel();
}
srv->_socket.set_option(asio::socket_base::keep_alive(true));
self.complete(ec, std::move(*srv));
srv.reset();
@ -574,7 +576,7 @@ public:
if (!ec) {
if (do_read) {
do_read = false;
// do_read = false;
if (_receiveQueue.size()) { // return message from queue
timer->cancel();
auto imsg = _receiveQueue.front();
@ -593,6 +595,8 @@ public:
}
auto buff = _streamBuffer.prepare(n_avail ? n_avail : 1);
do_read = false;
if constexpr (isTLS) {
return asio::async_read(_sessSocket, std::move(buff), asio::transfer_at_least(1),
std::move(self));
@ -638,8 +642,9 @@ public:
auto net_pack = this->search(std::span(start_ptr, _streamBuffer.size()));
if (net_pack.empty()) {
do_read = true;
asio::post(std::move(self)); // initiate consequence socket's read operation
return;
return _socket.async_wait(asio::ip::tcp::socket::wait_read, std::move(self));
// asio::post(std::move(self)); // initiate consequence socket's read operation
// return;
}
timer->cancel(); // there were no errors in the asynchronous read-operation, so stop timer

View File

@ -137,7 +137,7 @@ int main(int argc, char* argv[])
asio::signal_set signals(io_ctx, SIGINT, SIGTERM);
signals.async_wait([&](std::error_code, int) { io_ctx.stop(); });
using server_t = adc::impl::AdcDeviceNetServerASIO<std::string, adc::AdcSPDLOGLogger>;
using server_t = adc::impl::AdcDeviceNetServerASIO<std::string, adc::AdcSpdlogLogger>;
std::shared_ptr<spdlog::logger> logger = spdlog::stdout_color_mt("console");
logger->set_level(spdlog::level::debug);
// server_t server("TEST SRV", io_ctx, logger, "[%Y-%m-%d %T.%e][%l]: %v");